diff --git a/js/package.json b/js/package.json index ef0fa3c19..b64521be3 100644 --- a/js/package.json +++ b/js/package.json @@ -21,7 +21,7 @@ }, "dependencies": { "botbuilder": "^4.22.3", - "openai": "4.41.0" + "openai": "4.41.1" }, "devDependencies": { "@azure/logger": "^1.1.4", @@ -39,13 +39,13 @@ "browserify": "^17.0.0", "chai": "^4.5.0", "depcheck": "^1.4.7", + "eslint": "^8.57.0", "eslint-config-prettier": "^8.10.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-jsdoc": "^46.10.1", "eslint-plugin-mocha": "^10.5.0", "eslint-plugin-only-warn": "^1.1.0", "eslint-plugin-prettier": "^5.2.1", - "eslint": "^8.57.0", "exorcist": "^2.0.0", "express": "^4.19.2", "mocha-junit-reporter": "^2.0.0", diff --git a/js/packages/teams-ai/src/models/OpenAIModel.ts b/js/packages/teams-ai/src/models/OpenAIModel.ts index 03fb87e82..0177b7895 100644 --- a/js/packages/teams-ai/src/models/OpenAIModel.ts +++ b/js/packages/teams-ai/src/models/OpenAIModel.ts @@ -374,6 +374,7 @@ export class OpenAIModel implements PromptCompletionModel { const responseMessage = (completion as ChatCompletion).choices![0].message; const isToolsAugmentation = template.config.augmentation && template.config.augmentation?.augmentation_type == 'tools'; + // Log tool calls to be added to message of type Message as action_calls if (isToolsAugmentation && responseMessage?.tool_calls) { for (const toolCall of responseMessage.tool_calls) { @@ -388,10 +389,11 @@ export class OpenAIModel implements PromptCompletionModel { } } // Log the generated response - message = ((completion as ChatCompletion).choices[0]?.message as Message) ?? { - role: 'assistant', - content: '' + message = { + role: responseMessage.role, + content: responseMessage.content ?? '' }; + if (actionCalls.length > 0) { message.action_calls = actionCalls; } @@ -421,12 +423,13 @@ export class OpenAIModel implements PromptCompletionModel { private convertMessages(messages: Message[]): ChatCompletionMessageParam[] { const params: ChatCompletionMessageParam[] = []; // Iterate through the messages and check for action calls - let param: ChatCompletionMessageParam = { - role: 'user', - content: '' - }; for (const message of messages) { + let param: ChatCompletionMessageParam = { + role: 'user', + content: '' + }; + if (message.role === 'user') { param.content = message.content ?? ''; } else if (message.role === 'system') { @@ -470,6 +473,7 @@ export class OpenAIModel implements PromptCompletionModel { } params.push(param); } + return params; } diff --git a/js/yarn.lock b/js/yarn.lock index 5a2144307..c6e8f95d7 100644 --- a/js/yarn.lock +++ b/js/yarn.lock @@ -7482,10 +7482,10 @@ openai@4.28.4: node-fetch "^2.6.7" web-streams-polyfill "^3.2.1" -openai@4.41.0: - version "4.41.0" - resolved "https://registry.yarnpkg.com/openai/-/openai-4.41.0.tgz#85f9880fdca6a4d761d948f84df3f4f3558ff079" - integrity sha512-fiV+RvUGRW+PXxycqeDYuOwsL3TxNqT/LcM6vlqyLz9ACmfSUGg1qviQrHuuNKL7gFOvfzgEJRVVFdqmv/sjxg== +openai@4.41.1: + version "4.41.1" + resolved "https://registry.yarnpkg.com/openai/-/openai-4.41.1.tgz#61d22d3f9338841be9f1ab3242418193e4df620f" + integrity sha512-QY8pkCOTjwXWS1AsTxRLomkX6B9fBQvggqRu4uvFd7Xjg1NDcPChGyki+sFiYzstpUeoApim/DNGy7fBKwdokg== dependencies: "@types/node" "^18.11.18" "@types/node-fetch" "^2.6.4" @@ -9078,7 +9078,7 @@ string-argv@^0.3.1, string-argv@~0.3.1: resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6" integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -9104,15 +9104,6 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -9204,7 +9195,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -9232,13 +9223,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -10151,7 +10135,7 @@ workerpool@^6.5.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -10178,15 +10162,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"