Skip to content

Commit 852ac58

Browse files
authored
fix: assistant tool calling (#1508)
2 parents bcf75ed + 675a158 commit 852ac58

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

package-lock.json

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"ngx-ui-scroll": "^3.2.1",
6969
"node-cron": "^3.0.3",
7070
"node-fetch": "^2.6.7",
71-
"openai": "^4.48.1",
71+
"openai": "^4.82.0",
7272
"p-debounce": "^2.1.0",
7373
"p-limit": "^3.1.0",
7474
"p-throttle": "^7.0.0",

packages/util/server/src/ml/assistant.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,21 @@ export class Assistant {
8585

8686
const chatGPTContext = assistantMessageContext
8787
.reverse() // Oldest first
88-
.map(
89-
(assistantMessage) =>
90-
assistantMessage.json as unknown as ChatCompletionMessageParam,
91-
);
88+
.map((assistantMessage) => {
89+
const message =
90+
assistantMessage.json as unknown as ChatCompletionMessageParam;
91+
if (message.role === "assistant") {
92+
return {
93+
...message,
94+
// Fix for https://github.com/openai/openai-python/issues/2061
95+
tool_calls: message.tool_calls?.length
96+
? message.tool_calls
97+
: undefined,
98+
};
99+
}
100+
101+
return message;
102+
});
92103

93104
let expectedToolCalls = 0;
94105
let toolCallingError = false;

0 commit comments

Comments
 (0)