Skip to content

[JS] chore: remove @azure/openai-assistants dependency from AssistantsPlanner.ts #2156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/lodash": "^4.17.12",
"@types/mocha": "^10.0.9",
"@types/node": "^20.16.1",
"@types/sinon": "^10.0.19",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"applicationinsights": "^2.9.6",
Expand All @@ -47,8 +47,8 @@
"eslint-plugin-prettier": "^5.2.1",
"exorcist": "^2.0.0",
"express": "^4.21.1",
"mocha-junit-reporter": "^2.0.0",
"mocha": "^10.7.3",
"mocha-junit-reporter": "^2.0.0",
"ms-rest-azure": "^3.0.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
Expand All @@ -58,7 +58,7 @@
"replace-in-file": "^4.1.0",
"rimraf": "^5.0.10",
"shx": "^0.3.4",
"sinon": "^16.1.3",
"sinon": "^19.0.2",
"source-map-support": "^0.5.19",
"sponge": "^0.1.0",
"tinyify": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion js/packages/teams-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"openai": "^4.68.2"
},
"dependencies": {
"@azure/openai-assistants": "1.0.0-beta.6",
"@azure/msal-node": "^2.15.0",
"axios": "^1.7.5",
"botbuilder-dialogs": "^4.23.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,47 @@ describe('ToolsAugmentation', () => {
assert(plan.commands.length === 0);
});
});

it('should handle empty arguments gracefully', async () => {
await adapter.sendTextToBot('test', async (context) => {
const actionCalls: ActionCall[] = [
{
type: 'function',
id: '123',
function: {
name: 'LightsOn',
arguments: ''
}
},
{
type: 'function',
id: '124',
function: {
name: 'Pause',
arguments: '{ "time": 10 }'
}
}
];
const response: PromptResponse<string | ActionCall[]> = {
status: 'success',
input: {
role: 'user',
content: 'Perform actions'
},
message: { role: 'assistant', content: '', action_calls: actionCalls }
};
const state = await TestTurnState.create(context);
const plan = await toolsAugmentation.createPlanFromResponse(context, state, response);

assert(plan.type === 'plan');
assert(plan.commands.length === 2);
assert(plan.commands[0].type === 'DO');
assert((plan.commands[0] as PredictedDoCommand).action === 'LightsOn');
assert.deepEqual((plan.commands[0] as PredictedDoCommand).parameters, {});
assert(plan.commands[1].type === 'DO');
assert((plan.commands[1] as PredictedDoCommand).action === 'Pause');
assert.deepEqual((plan.commands[1] as PredictedDoCommand).parameters, { time: 10 });
});
});
});
});
20 changes: 12 additions & 8 deletions js/packages/teams-ai/src/augmentations/ToolsAugmentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ToolsAugmentation implements Augmentation<string> {
* Creates a plan given validated response value.
* @param {TurnContext} context Context for the current turn of conversation.
* @param {Memory} memory An interface for accessing state variables.
* @param {PromptResponse<string>} response The validated and transformed response for the prompt.
* @param {PromptResponse<string | ActionCall[]>} response The validated and transformed response for the prompt.
* @returns {Promise<Plan>} The created plan.
*/
public createPlanFromResponse(
Expand All @@ -74,14 +74,18 @@ export class ToolsAugmentation implements Augmentation<string> {
const actionToolCalls: ActionCall[] = response.message.action_calls;

for (const toolCall of actionToolCalls) {
let parameters;
let parameters = {};

try {
parameters = JSON.parse(toolCall.function.arguments) ?? {};
} catch (err) {
console.error('ToolsAugmentation parameters:', toolCall.function.arguments);
console.error('ToolsAugmentation createPlanFromResponse: Error parsing tool arguments: ', err);
parameters = {};
if (toolCall.function.arguments && toolCall.function.arguments.trim() !== '') {
try {
parameters = JSON.parse(toolCall.function.arguments);
} catch (err) {
console.warn(
`ToolsAugmentation: Error parsing tool arguments for ${toolCall.function.name}:`,
err
);
console.warn('Arguments:', toolCall.function.arguments);
}
}

const doCommand: PredictedDoCommand = {
Expand Down
Loading
Loading