microsoft / teams-ai

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

[Bug]: Teams Chef Bot Sample crashes when local debugging #1881

Closed tecton closed 1 month ago

tecton commented 1 month ago

Language

Javascript/Typescript

Version

latest

Description

Local debug cannot start and shows the following error: [nodemon] 3.0.3 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): src*\ [nodemon] watching extensions: ts,json [nodemon] starting node --inspect=9239 -r ts-node/register ./src/index.ts Debugger listening on ws://127.0.0.1:9239/xxxx For help, see: https://nodejs.org/en/docs/inspector TypeError: Cannot read properties of undefined (reading 'trim') at new OpenAIModel (node_modules\@microsoft\teams-ai\src\models\OpenAIModel.ts:192:55) at Object. (\src\index.ts:84:15) at Module._compile (node:internal/modules/cjs/loader:1369:14) at Module.m._compile (node_modules\ts-node\src\index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) at Object.require.extensions. [as .ts] (node_modules\ts-node\src\index.ts:1621:12) at Module.load (node:internal/modules/cjs/loader:1206:32) at Function.Module._load (node:internal/modules/cjs/loader:1022:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 [nodemon] app crashed - waiting for file changes before starting...

Reproduction Steps

1. Download sample in Teams Toolkit sample gallery.
2. Fill in OpenAI key.
3. Press 'F5' to start local debugging.
lilyydu commented 1 month ago

Hi @tecton,

Are you using a sample from Teams Toolkit? If so, please file the issue with them here instead

tecton commented 1 month ago

Hi @lilyydu,

The root cause of this bug is that azureApiKey is passed to the constructor of OpenAIModellink. While in teams-ai library, it checks 'azureApiKey' in options. In this case, azureApiKey is undefined but still executes the 'trim()' function. It should either check the azureApiKey is not empty string or avoid passing azureApiKey in constructor.

lilyydu commented 1 month ago

Hi @tecton,

The trim is only called if the azureApiKey or azureADTokenProvider exists. If you are using OAI instead, you will need to provide the appropriate keys, and comment this section out.

tecton commented 1 month ago

Hi @lilyydu,

Yes, I mean there's a bug that trim() is called even if azureApiKey doesn't exist. I'm using OpenAI instead of Azure Open AI service, but the sample shows the error: Cannot read properties of undefined (reading 'trim'). Could you please help to fix it?

lilyydu commented 1 month ago

Hi @tecton,

trim() is only called if azureApiKey or azureADTokenProvider are filled in- if you are using OAI, both of these need to be commented out. Can you confirm you have tried this?

tecton commented 1 month ago

@lilyydu Commenting out Azure related lines is working. I'll create a PR to update README.