Skip to content

added tools support for fireworks.ai #4560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/llm/llms/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class OpenAI extends BaseLLM {
return !!model && (model.startsWith("o1") || model.startsWith("o3"));
}

private isFireworksAiModel(model?: string): boolean {
return !!model && model.startsWith("accounts/fireworks/models");
}

protected supportsPrediction(model: string): boolean {
const SUPPORTED_MODELS = ["gpt-4o-mini", "gpt-4o", "mistral-large"];
return SUPPORTED_MODELS.some((m) => model.includes(m));
Expand Down Expand Up @@ -274,7 +278,13 @@ class OpenAI extends BaseLLM {
body.max_completion_tokens = undefined;
}

if (body.tools?.length && !body.model?.startsWith("o3")) {
if (body.tools?.length) {
if (this.isFireworksAiModel(body.model)) {
// fireworks.ai does not support parallel tool calls, but their api expects this to be true anyway otherwise they return an error.
// tooling works with them as a inference provider once this is set to true.
// https://docs.fireworks.ai/guides/function-calling#openai-compatibility
body.parallel_tool_calls = true;
}
// To ensure schema adherence: https://platform.openai.com/docs/guides/function-calling#parallel-function-calling-and-structured-outputs
// In practice, setting this to true and asking for multiple tool calls
// leads to "arguments" being something like '{"file": "test.ts"}{"file": "test.js"}'
Expand Down
13 changes: 13 additions & 0 deletions core/llm/toolSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ export const PROVIDER_TOOL_SUPPORT: Record<
) {
return true;
}
// firworks-ai https://docs.fireworks.ai/guides/function-calling
if (model.startsWith("accounts/fireworks/models/")) {
switch (model.substring(26)) {
case "llama-v3p1-405b-instruct":
case "llama-v3p1-70b-instruct":
case "qwen2p5-72b-instruct":
case "firefunction-v1":
case "firefunction-v2":
return true;
default:
return false;
}
}
},
gemini: (model) => {
// All gemini models support function calling
Expand Down
Loading