页面简介
Give open models on Fireworks live web search and page contents with Exa tool calling.
正文摘录
Fireworks serves open models such as Kimi, GLM, DeepSeek, and Qwen through an OpenAI-compatible API. Exa gives those models live web search and full page contents. Point the OpenAI SDK at Fireworks, pass it the Exa SDK’s ready-made tools, and any Fireworks model that supports function calling can search the web and read the pages it finds. Get started 1Install the SDKsPythonJavaScriptpip install openai exa_py # Or, if using uv: uv add openai exa_py 2Set up your API keysSet the EXA_API_KEY and FIREWORKS_API_KEY environment variables. Create a Fireworks key in the Fireworks dashboard and an Exa key in the Exa dashboard.Get your Exa API keyCreate a key in the dashboard. New accounts start with free credits.3Run the tool loopCreate an OpenAI client with the Fireworks base URL and pass the Exa tools in tools. handle_tool_calls runs every Exa tool call in the model’s message and returns the role: "tool" messages to append. Repeat until the model answers without tool calls.PythonJavaScriptimport os from exa_py import Exa from openai import OpenAI exa = Exa() # reads EXA_API_KEY from the environment fireworks = OpenAI( api_key=os.environ["FIREWORKS_API_KEY"], base_url="https://api.fireworks.ai/inference/v1", ) MODEL = "accounts/fireworks/models/kimi-k3" tools = [exa.openai.web_search(), exa.openai.get_contents()] messages = [ {"role": "user", "content": "What were the major AI announcements this week?"} ] while True: completion = fireworks.chat.completions.create( model=MODEL, messages=messages, tools=tools, ) message = completion.choices[0].message messages.append(message) if not message.tool_calls: break messages += exa.openai.handle_tool_calls(message) print(message.content) web_search finds pages the model has not seen. get_contents reads pages it already has URLs for, from an earlier search or from the user. Register either or both. Any Fireworks model with function calling works. Swap MODEL for another ID from the Fireworks model library, or for your own fine-tuned model or on-demand deployment. Configuring the tools Calling the factories with no arguments gives Exa’s recommended defaults. The search tool runs a type="auto" search with contents={"highlights": True}, which returns query-relevant excerpts from each result. The contents tool returns page text. Keyword arguments you pass to a factory override these defaults, and a custom name lets you run differently configured Exa tools side by side. See OpenAI tool calling for every option, mixing in your own tools, and writing the loop by hand. Search first, then generate When your code decides what to search, skip tool calling. Run one Exa search with contents and pass the results to a Fireworks model as numbered sources. This fits pipelines such as research briefs, monitoring digests, and dataset generation. Pythonresults = exa.search( "federated fine-tuning of LLMs with LoRA", type="auto", category="publication", num_results=10, contents={"highlights": True}, ) sources = "\n\n".join( f"[{i}] {r.title}\n{r.url}\n{' '.join(r.highlights)}" for i, r in enumerate(results.results, start=1) ) completion = fireworks.chat.completions.create( model=MODEL, messages=[ {"role": "system", "content": "Answer only from the numbered sources and cite them by number."}, {"role": "user", "content": f"Sources:\n\n{sources}\n\nSummarize the main approaches and their tradeoffs."}, ], ) print(completion.choices[0].message.content) Use contents={"text": True} instead of highlights when the model needs full page text. See search best practices for choosing a search type and filters. Pricing Exa calls bill to your Exa account at standard Exa pricing. Fireworks bills model tokens to your Fireworks account. Resources Fireworks tool callingTool definitions, supported models, and tool choice options on Fireworks.Open docsCookbookBuild a research assistant with Exa search and Fireworks models, with a runnable notebook.Open cookbook