mirror of
https://github.com/runebookai/tome.git
synced 2025-07-21 00:27:30 +03:00
Merge pull request #87 from runebookai/no-tools-if-no-tools
Don't pass tools array if it's empty
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { OpenAI as OpenAIClient } from 'openai';
|
||||
import type { ChatCompletionCreateParamsNonStreaming } from 'openai/resources/index.mjs';
|
||||
|
||||
import OpenAiMessage from '$lib/engines/openai/message';
|
||||
import type { Client, ClientProps, Options, Tool, ToolCall } from '$lib/engines/types';
|
||||
@@ -28,12 +29,16 @@ export default class OpenAI implements Client {
|
||||
_options: Options = {}
|
||||
): Promise<Message> {
|
||||
const messages = history.map(m => OpenAiMessage.from(m));
|
||||
const response = await this.client.chat.completions.create({
|
||||
const completion: ChatCompletionCreateParamsNonStreaming = {
|
||||
model: model.name,
|
||||
messages,
|
||||
tools,
|
||||
});
|
||||
};
|
||||
|
||||
if (tools.length > 0) {
|
||||
completion.tools = tools;
|
||||
}
|
||||
|
||||
const response = await this.client.chat.completions.create(completion);
|
||||
const { role, content, tool_calls } = response.choices[0].message;
|
||||
|
||||
let toolCalls: ToolCall[] = [];
|
||||
|
||||
Reference in New Issue
Block a user