Skip to content

Commit

Permalink
fix: Improve tool choice handling in Observability AI Assistant client
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoliduena committed Dec 12, 2024
1 parent 96573a4 commit 446fcb8
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,24 @@ export class ObservabilityAIAssistantClient {
tracer: LangTracer;
}
): Observable<ChatCompletionChunkEvent | TokenCountEvent | ChatCompletionMessageEvent> => {
const tools = functions?.reduce((acc, fn) => {
acc[fn.name] = {
description: fn.description,
schema: fn.parameters,
};
return acc;
}, {} as Record<string, { description: string; schema: any }>);
let tools: Record<string, { description: string; schema: any }> | undefined;
let toolChoice: ToolChoiceType | { function: string } | undefined;

if (functions && functions.length > 0) {
tools = functions?.reduce((acc, fn) => {
acc[fn.name] = {
description: fn.description,
schema: fn.parameters,
};
return acc;
}, {} as Record<string, { description: string; schema: any }>);

toolChoice = functionCall
? {
function: functionCall,
}
: ToolChoiceType.auto;
}

const chatComplete$ = defer(() =>
this.dependencies.inferenceClient.chatComplete({
Expand All @@ -497,11 +508,7 @@ export class ObservabilityAIAssistantClient {
messages.filter((message) => message.message.role !== MessageRole.System)
),
functionCalling: simulateFunctionCalling ? 'simulated' : 'native',
toolChoice: functionCall
? {
function: functionCall,
}
: ToolChoiceType.auto,
toolChoice,
tools,
})
).pipe(
Expand Down

0 comments on commit 446fcb8

Please sign in to comment.