Function Calling Deepseekv3
Captured source
source ↗Enabling Function Calling in DeepSeek v3: Bridging the Gap Between Text and Action
GLM 5.2 is live! Opus-level intelligence at open-source rates. Pay per token on serverless. Try it today.
Blog
Function Calling Deepseekv3 Enabling Function Calling in DeepSeek v3: Bridging the Gap Between Text and Action
PUBLISHED 2/14/2025
Table of Contents What is Function Calling? Technical Underpinnings Applications and Use Cases Function Calling Support for DeepSeek v3
Code Example
Non-streaming API
Streaming API
Limitations
Table of Contents
Large language models (LLMs) have revolutionized natural language processing by generating impressive text based on massive pretraining and strategic alignment with user preferences during post training. However, their inherent limitation is that—while they excel at generating human-like language—they lack the ability to access or update real-world information on demand. This is where function (or tool) calling comes into play. By enabling LLMs to invoke external functions or APIs, we can dynamically extend their capabilities, making them not only great conversationalists but also powerful, interactive agents. We are thrilled to announce that Fireworks AI API now supports function calling on top of the latest generation DeepSeek V3 model. What is Function Calling?
Function calling refers to the process by which an LLM detects that a user request requires external data or action and then produces a structured output (typically in JSON) that specifies which function to call along with the necessary arguments. For example, instead of simply generating text to answer “What is the weather in London?” an LLM equipped with function calling can output a JSON object that triggers a weather API call. Once the external tool returns the relevant data, the LLM integrates this information into its final response. This paradigm is sometimes also called tool calling , and it fundamentally transforms LLMs from static knowledge generators into dynamic, interactive agents capable of real‐world tasks. Technical Underpinnings
At its core, function calling involves the following key steps: Tool Specification and Prompting: Developers define a set of external functions—each with a name, description, and a JSON schema for its parameters. For example, a weather retrieval function might be specified with parameters such as location and temperature unit. The LLM is then prompted with both the user query and the tool definitions. By passing in the tool definitions as part of the prompt context, the model learns to generate structured calls when it identifies that a user query requires external data. Detecting and Generating Function Calls: When the LLM processes a user query, it decides whether to answer directly or issue a function call. If the latter is chosen, the model outputs a JSON string with the name of the function and the relevant arguments. This output does not execute the function—it merely indicates what external call should be made. The ability to output a function call in a structured format is critical; it lets developers safely and reliably integrate external APIs into the LLM’s workflow. Function Execution and Feedback Loop: An external system or middleware detects the structured function call, executes the specified function (e.g., calls a weather API), and retrieves the result. This result is then fed back into the conversation context for the LLM to generate a comprehensive answer. In many implementations, a second round of prompting uses both the original query and the function’s output to produce the final response. This two-step process—first generating the function call, then using the result to refine the final output—forms the backbone of interactive LLM systems.
Applications and Use Cases
The ability to call functions extends LLMs’ applicability into numerous domains: • Real-Time Data Retrieval: LLMs can fetch up-to-date information such as weather forecasts, stock prices, or news updates, overcoming the limitations of static pretraining data. • Task Automation and Workflow Integration: By invoking functions, LLMs can perform tasks like scheduling meetings, managing databases, or even controlling IoT devices, effectively operating as autonomous agents.
Function Calling Support for DeepSeek v3
We are excited to announce that the Fireworks AI API now offers function calling capabilities integrated with the latest DeepSeek v3 model. This enhancement enables developers to create applications where the model can interact with external functions or APIs, thereby extending its capabilities beyond static responses. Code Example
Non-streaming API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 import json import requests
Define available tools / functions that the model can use
In this case , we have a single weather function that can fetch weather data
tools = [ { "type" : "function" , "function" : { "name" : "get_current_weather" , "description" : "Fetch the current weather in a given location." , "parameters" : { "type" : "object" , "properties" : { "location" : { "type" : "string" , "description" : "City name, e.g., London" , } , "unit" : { "type" : "string" , "enum" : [ "celsius" , "fahrenheit" ] } , } , "required" : [ "location" ] , } , } , } ]
API configuration
API_URL = "https://api.fireworks.ai/inference/v1/chat/completions" FW_API_KEY = "get your key from https://fireworks.ai/" MODEL = "accounts/fireworks/models/deepseek-v3"
Set up request headers with API key authentication
headers = { "Content-Type" : "application/json" , "Authorization" : f "Bearer {FW_API_KEY}" , }
Define the conversation messages - in this case a simple weather query
messages = [ { "role" : "user" , "content" : "What is the weather like in London?" } ]
Prepare the request payload with the model , messages and available tools
payload = { "model" : MODEL , "messages" : messages , "tools" : tools , }
Send POST request to the API and parse the JSON response
response = requests . post ( API_URL , headers = headers , data = json . dumps ( payload ) ) parsed_response = response . json ( )
Print the first choice's message from the response with nice formatting
print ( json . dumps ( parsed_response [ "choices" ] [ 0 ] [ "message" ] , indent = 2 ) )
Output :
#
{
"role" :...
Excerpt shown — open the source for the full document.
Notability
notability 6.0/10Platform adds function calling support for DeepSeek V3.