Skip to content

Commit

Permalink
fix: assistant tool calling backport (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Feb 5, 2025
2 parents bacd1ce + 9b59de5 commit 485dab9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/util/server/src/ml/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,21 @@ export class Assistant {

const chatGPTContext = assistantMessageContext
.reverse() // Oldest first
.map(
(assistantMessage) =>
assistantMessage.json as unknown as ChatCompletionMessageParam,
);
.map((assistantMessage) => {
const message =
assistantMessage.json as unknown as ChatCompletionMessageParam;
if (message.role === "assistant") {
return {
...message,
// Fix for https://github.com/openai/openai-python/issues/2061
tool_calls: message.tool_calls?.length
? message.tool_calls
: undefined,
};
}

return message;
});

let expectedToolCalls = 0;
let toolCallingError = false;
Expand Down

0 comments on commit 485dab9

Please sign in to comment.