microsoft / teams-ai

SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
MIT License
406 stars 176 forks source link

[Bug]: Prompt Manager unable to find config.json file #1639

Closed yikwen closed 4 months ago

yikwen commented 4 months ago

Language

Python

Version

latest

Description

The bot.py script in the given samples (e.g. listBot, devOpsBot), initialise prompt manager with the line prompts = PromptManager(PromptManagerOptions(prompts_folder=f"{os.getcwd()}/src/prompts")). This will result in error PromptManager.get_prompt(): an error occurred while loading '/tmp/8dc7004c356e144/src/prompts/sequence/config.json'. The file is either invalid or missing. when the code is run.

the config.json file is located in a subfolder of the folder where bot.py is, so the path to use for initialising the prompt manager should be f{os.getcwd()}/prompts instead.

Reproduction Steps

1.Just try to run the code as-is. It will fail as PromptManager will fail to initialise.
lilyydu commented 4 months ago

Hi @yikwen, could you print os.getcwd() and let me know what your path is?

The existing line prompts = PromptManager(PromptManagerOptions(prompts_folder=f"{os.getcwd()}/src/prompts"))

is correct because os.cwd() is as follows: {path-where-you-cloned-the-library}\teams-ai\python\samples\04.ai.d.chainedActions.listBot

yikwen commented 4 months ago

Hi @lilyydu ,

bot.py is located at {path-where-you-cloned-the-library}\teams-ai\python\samples\04.ai.d.chainedActions.listBot\src

Hence, f"{os.getcwd()}/src/prompts") returns {path-where-you-cloned-the-library}\teams-ai\python\samples\04.ai.d.chainedActions.listBot\src\src\prompts. That's one extra src.

lilyydu commented 4 months ago

Hi @yikwen,

(1) Do you have the sample open as the target directory? os.cwd will use the path where its being executed (hence it looks like we have different entry points). The correct way is to directly open the sample folder {path-where-you-cloned-the-library}\teams-ai\python\samples\04.ai.d.chainedActions.listBot in your VSC and terminal.

Doing so, will correctly yield os.cwd()-> {path-where-you-cloned-the-library}\teams-ai\python\samples\04.ai.d.chainedActions.listBot

(2) Are you running the application via F5 as well?

yikwen commented 4 months ago

Hi @lilyydu, yes I have the sample open as the target directory. os.cwd() prints the current directory where that line of code is running from right? To make sure I wasn't dreaming, I tested with 2 python notebooks in different directories and os.cwd() just returns whichever directory they're located in.

I ran the code by deploying it to an Azure web app. The error message PromptManager.get_prompt(): an error occurred while loading '/tmp/8dc7004c356e144/src/prompts/sequence/config.json'. The file is either invalid or missing. was obtained from the web app, and was fixed after I modified that line of code in bot.py.

yikwen commented 4 months ago

Perhaps you could try also deploying the code to an Azure web app to reproduce the issue? I did not make any changes to the code prior to deploying, so it was just run as-is, and the error appears right after.

yikwen commented 4 months ago

And for comparison, the Javascript samples use:

const prompts = new PromptManager({
    promptsFolder: path.join(__dirname, '../src/prompts')
});

where .. navigates to one level above the current directory before coming back down to /src/prompts.

lilyydu commented 4 months ago

Got it, thank you for rigorously testing on your end @yikwen. Reason I asked (2) was because ow.cwd() is working as expected with the F5 TTK flow (local launch of the application) but because it references the current script's location, it is failing for the azure deployment.

However, updating to f{os.getcwd()}/prompts will not work for the F5 local deployment either.

Could you try updating to this line of code and let me know if it still throws the same error for the deployment?

prompts_folder=f"{os.path.dirname(os.path.abspath(__file__))}/prompts")

yikwen commented 4 months ago

Hi Lily, sorry have not found time to try this out yet. Will try next week.

yikwen commented 4 months ago

Hi @lilyydu , I've tested prompts_folder=f"{os.path.dirname(os.path.abspath(__file__))}/prompts"), and it works. At least it does when deployed to Azure. I haven't been able run via F5 so far because my organization blocks sideloading of Teams apps, and it was a bit of a hassle to get setup my own Dev environment so I've been developing and testing by deploying straight to Azure.

lilyydu commented 4 months ago

Hi @yikwen,

Sorry for the delay, our team was presenting at Build. Will be issuing a PR for this update soon- thanks so much for testing it :)