openai-tools-p1
This commit is contained in:
parent
8293beb986
commit
b35f00f3dc
4 changed files with 29 additions and 22 deletions
|
|
@ -309,14 +309,6 @@ class OpenAI extends BaseLLM {
|
|||
|
||||
const body = this._convertArgs(options, messages);
|
||||
|
||||
// Empty messages cause an error in LM Studio
|
||||
body.messages = body.messages.map((m: any) => ({
|
||||
...m,
|
||||
content: m.content === "" ? " " : m.content,
|
||||
// We call it toolCalls, they call it tool_calls
|
||||
tool_calls: m.toolCalls,
|
||||
tool_call_id: m.toolCallId,
|
||||
})) as any;
|
||||
const response = await this.fetch(this._getEndpoint("chat/completions"), {
|
||||
method: "POST",
|
||||
headers: this._getHeaders(),
|
||||
|
|
|
|||
|
|
@ -57,16 +57,6 @@ export function toChatBody(
|
|||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
): ChatCompletionCreateParams {
|
||||
const tools = options.tools?.map((tool) => ({
|
||||
type: tool.type,
|
||||
function: {
|
||||
name: tool.function.name,
|
||||
description: tool.function.description,
|
||||
parameters: tool.function.parameters,
|
||||
strict: tool.function.strict,
|
||||
},
|
||||
}));
|
||||
|
||||
const params: ChatCompletionCreateParams = {
|
||||
messages: messages.map(toChatMessage),
|
||||
model: options.model,
|
||||
|
|
@ -79,9 +69,19 @@ export function toChatBody(
|
|||
stop: options.stop,
|
||||
prediction: options.prediction,
|
||||
};
|
||||
if (tools?.length) {
|
||||
params.tools = tools;
|
||||
|
||||
if (options.tools?.length) {
|
||||
params.tools = options.tools.map((tool) => ({
|
||||
type: tool.type,
|
||||
function: {
|
||||
name: tool.function.name,
|
||||
description: tool.function.description,
|
||||
parameters: tool.function.parameters,
|
||||
strict: tool.function.strict,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@ export const PROVIDER_TOOL_SUPPORT: Record<
|
|||
return true;
|
||||
}
|
||||
},
|
||||
openai: (model) => {
|
||||
if (
|
||||
["gpt-4", "o1", "chatgpt-4o-latest"].some((part) =>
|
||||
model.toLowerCase().startsWith(part),
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// https://ollama.com/search?c=tools
|
||||
ollama: (model) => {
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -23,17 +23,23 @@ export const streamNormalInput = createAsyncThunk<
|
|||
const toolSettings = state.ui.toolSettings;
|
||||
const streamAborter = state.session.streamAborter;
|
||||
const useTools = state.ui.useTools;
|
||||
|
||||
if (!defaultModel) {
|
||||
throw new Error("Default model not defined");
|
||||
}
|
||||
|
||||
console.log("YOO", messages);
|
||||
const includeTools =
|
||||
useTools &&
|
||||
modelSupportsTools(defaultModel.title, defaultModel.provider) &&
|
||||
messages.length >= 2 &&
|
||||
messages[messages.length - 2].role === "user";
|
||||
|
||||
// Send request
|
||||
const gen = extra.ideMessenger.llmStreamChat(
|
||||
defaultModel.title,
|
||||
streamAborter.signal,
|
||||
messages,
|
||||
useTools && modelSupportsTools(defaultModel.title, defaultModel.provider)
|
||||
includeTools
|
||||
? {
|
||||
tools: state.config.config.tools.filter(
|
||||
(tool) => toolSettings[tool.function.name] !== "disabled",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue