Because the Fireworks API extends OpenAI's, the call option type is the same.
Runtime args can be passed as the second argument to any of the base runnable methods .invoke. .stream, .batch, etc.
They can also be passed via .withConfig, or the second arg in .bindTools, like shown in the examples below:
// When calling `.withConfig`, call options should be passed via the first argument constllmWithArgsBound = llm.withConfig({ stop: ["\n"], tools: [...], });
// When calling `.bindTools`, call options should be passed via the second argument constllmWithTools = llm.bindTools( [...], { stop: ["\n"], } );
constllm = newChatFireworks({ model:"command-r-plus", temperature:0, // other params... });
Invoking
constinput = `Translate "I love programming" into French.`;
// Models also accept a list of chat messages or a formatted prompt constresult = awaitllm.invoke(input); console.log(result);
AIMessage {
"id": "dbc233df-532e-4aaa-8995-9d6ea65fea15",
"content": "The translation of \"I love programming\" into French is:\n\n\"J'adore la programmation.\"\n\nHere's a breakdown of the translation:\n\n* \"I\" is translated to \"Je\" (but in informal writing, it's common to use \"J'\" instead of \"Je\" when it's followed by a vowel)\n* \"love\" is translated to \"adore\"\n* \"programming\" is translated to \"la programmation\"\n\nSo, the complete translation is \"J'adore la programmation.\"",
"additional_kwargs": {},
"response_metadata": {
"tokenUsage": {
"completionTokens": 105,
"promptTokens": 19,
"totalTokens": 124
},
"finish_reason": "stop"
},
"tool_calls": [],
"invalid_tool_calls": [],
"usage_metadata": {
"input_tokens": 19,
"output_tokens": 105,
"total_tokens": 124
}
}
AIMessageChunk {
"id": "9b80e5af-0f50-4fb7-b700-6d431a819556",
"content": "The translation of \"I love programming\" into French is:\n\n\"J'adore la programmation.\"\n\nHere's a breakdown of the translation:\n\n* \"I\" is translated to \"Je\" (but in informal writing, it's common to use \"J'\" instead of \"Je\" when it's followed by a vowel)\n* \"love\" is translated to \"adore\"\n* \"programming\" is translated to \"la programmation\"\n\nSo, the complete translation is \"J'adore la programmation.\"",
"additional_kwargs": {},
"response_metadata": {
"prompt": 0,
"completion": 0,
"finish_reason": "stop"
},
"tool_calls": [],
"tool_call_chunks": [],
"invalid_tool_calls": [],
"usage_metadata": {
"input_tokens": 19,
"output_tokens": 105,
"total_tokens": 124
}
}
Bind tools
import { z } from'zod';
constllmForToolCalling = newChatFireworks({ // Use a model with tool calling capability model:"accounts/fireworks/models/firefunction-v2", temperature:0, // other params... }); constGetWeather = { name:"GetWeather", description:"Get the current weather in a given location", schema:z.object({ location:z.string().describe("The city and state, e.g. San Francisco, CA") }), }
constGetPopulation = { name:"GetPopulation", description:"Get the current population in a given location", schema:z.object({ location:z.string().describe("The city and state, e.g. San Francisco, CA") }), }
constllmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]); constaiMsg = awaitllmWithTools.invoke( "Which city is hotter today and which is bigger: LA or NY?" ); console.log(aiMsg.tool_calls);
constJoke = z.object({ setup:z.string().describe("The setup of the joke"), punchline:z.string().describe("The punchline to the joke"), rating:z.number().optional().describe("How funny the joke is, from 1 to 10") }).describe('Joke to tell user.');
conststructuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name:"Joke" }); constjokeResult = awaitstructuredLlm.invoke("Tell me a joke about cats"); console.log(jokeResult);
{
setup: 'Why did the cat join a band?',
punchline: 'Because it wanted to be the purr-cussionist!',
rating: 8
}
Wrapper around Fireworks API for large language models fine-tuned for chat
Fireworks API is compatible to the OpenAI API with some limitations described in https://readme.fireworks.ai/docs/openai-compatibility.
To use, you should have the
FIREWORKS_API_KEY
environment variable set.Setup: Install
@langchain/community
and set a environment variable calledFIREWORKS_API_KEY
.Constructor args
Runtime args
Because the Fireworks API extends OpenAI's, the call option type is the same.
Runtime args can be passed as the second argument to any of the base runnable methods
.invoke
..stream
,.batch
, etc. They can also be passed via.withConfig
, or the second arg in.bindTools
, like shown in the examples below:Examples
Instantiate
Invoking
Streaming Chunks
Aggregate Streamed Chunks
Bind tools
Structured Output
Usage Metadata
Response Metadata