Skip to content

Commit

Permalink
fix: only us function calling for supported models
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 11, 2024
1 parent a344018 commit 9f97f2d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/helpers/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ const useOllama = (model?: string) => {
return model?.includes('llama') || model?.includes('phi');
};

const supportsFunctionCalling = (model?: string) => {
// gpt-4o, gpt-4o-2024-05-13, gpt-4-turbo, gpt-4-turbo-2024-04-09, gpt-4-turbo-preview, gpt-4-0125-preview, gpt-4-1106-preview, gpt-4, gpt-4-0613, gpt-3.5-turbo, gpt-3.5-turbo-0125, gpt-3.5-turbo-1106, and gpt-3.5-turbo-0613
return !!{
'gpt-4o': true,
'gpt-4o-2024-05-13': true,
'gpt-4-turbo': true,
'gpt-4-turbo-2024-04-09': true,
'gpt-4-turbo-preview': true,
'gpt-4-0125-preview': true,
'gpt-4-1106-preview': true,
'gpt-4': true,
'gpt-4-0613': true,
'gpt-3.5-turbo': true,
'gpt-3.5-turbo-0125': true,
'gpt-3.5-turbo-1106': true,
'gpt-3.5-turbo-0613': true,
}[model || ''];
};

export const getOpenAi = async function () {
const { OPENAI_KEY: openaiKey, OPENAI_API_ENDPOINT: endpoint } =
await getConfig();
Expand Down Expand Up @@ -59,7 +78,7 @@ export const getFileSuggestion = async function (
`,
};
const { MODEL: model } = await getConfig();
if (useOllama(model)) {
if (useOllama(model) || !supportsFunctionCalling(model)) {
return removeInitialSlash(
removeBackticks(
await getSimpleCompletion({
Expand Down Expand Up @@ -111,7 +130,6 @@ export const getFileSuggestion = async function (
},
message,
],
response_format: { type: 'json_object' },
});
const jsonStr =
completion.choices[0]?.message.tool_calls?.[0]?.function.arguments;
Expand Down

0 comments on commit 9f97f2d

Please sign in to comment.