Skip to content

Function calling #9

Open
Open
@sigren

Description

@sigren

When will R1 support function calling and structured outputs? Thanks

Activity

FORNDODAper

FORNDODAper commented on Jan 21, 2025

@FORNDODAper

x2
('x2' stands for 'yeah, i would like to know that too')

reatang

reatang commented on Jan 21, 2025

@reatang

x2 + 1

flyfish101

flyfish101 commented on Jan 21, 2025

@flyfish101

x2 + 2

liberty-rapid

liberty-rapid commented on Jan 21, 2025

@liberty-rapid

x2 + 3

lzl-mt

lzl-mt commented on Jan 21, 2025

@lzl-mt

x2 + 4

juanjopc

juanjopc commented on Jan 21, 2025

@juanjopc

x2 + 5

engalisabry

engalisabry commented on Jan 21, 2025

@engalisabry

Response to Issue #9: Function Calling and Structured Outputs

Thank you for your question and for the community’s interest in this feature! Below, I’ve addressed the current status and future plans for function calling and structured outputs in DeepSeek R1.


Current Status

  • As of now, DeepSeek R1 does not natively support function calling or structured outputs.
  • The model is primarily optimized for reasoning-heavy tasks (e.g., math, code, and STEM) and follows a conversational format.

Future Plans

  • We recognize the importance of function calling and structured outputs for many use cases, such as API integrations, automation, and data extraction.
  • We are actively exploring ways to add support for these features in future updates. This includes:
    • Extending the model’s capabilities to handle structured data formats (e.g., JSON, XML).
    • Adding support for function calling to enable seamless integration with external tools and APIs.

Timeline

  • While we don’t have a specific release date yet, we aim to roll out these features in the next major update.
  • We will keep the community updated on our progress through GitHub announcements and release notes.

Workarounds for Now

If you need structured outputs or function-like behavior in the meantime, here are some workarounds:

  1. Post-Processing Outputs:

    • Use a script to parse the model’s responses into structured formats (e.g., JSON).
    • Example:
      import json
      
      response = model.generate("Extract the following data as JSON: ...")
      structured_data = json.loads(response)
  2. Prompt Engineering:

    • Design prompts to guide the model to produce outputs in a specific format.
    • Example:
      Extract the following information and format it as JSON:
      - Name: ...
      - Age: ...
      - Location: ...
      
  3. Custom Wrapper:

    • Build a custom wrapper around the model to simulate function calling behavior.
    • Example:
      def call_function(model, function_name, args):
          prompt = f"Call function {function_name} with args {args} and return the result."
          return model.generate(prompt)

Community Feedback

We appreciate the enthusiasm from the community (x2 + 5 and counting!). Your feedback is invaluable in shaping the future of DeepSeek R1. If you have specific use cases or feature requests related to function calling and structured outputs, please share them in this thread.


Next Steps

  • We will prioritize this feature based on community demand and provide updates as development progresses.
  • Stay tuned for announcements and feel free to contribute ideas or suggestions!

Thank you for your patience and support as we work to make DeepSeek R1 even better! Let us know if you have further questions or need additional assistance.

ibndias

ibndias commented on Jan 22, 2025

@ibndias

Use R1 as the master brain for tool decision / plan, and rewrite the output in structure with another model.

jacobpretorius

jacobpretorius commented on Jan 22, 2025

@jacobpretorius

I would really like the model to support structured output, such as JSON. For now, no matter how much I tell it to only output JSON it is not consistent. I don't mind the section I think that is useful and very easy to remove with some string handling, but it needs to adhere to JSON output if asked in its final response.

added a commit that references this issue on Jan 22, 2025
449333d
Chrisbattarbee

Chrisbattarbee commented on Jan 22, 2025

@Chrisbattarbee

Also looking for this

feliks912

feliks912 commented on Jan 23, 2025

@feliks912

Bump, definitely bump

jayeew

jayeew commented on Jan 23, 2025

@jayeew

When will R1 support agent?

letscagefdn

letscagefdn commented on Jan 23, 2025

@letscagefdn

response_format: { type: 'json_object' }

54 remaining items

TonyGeez

TonyGeez commented on Apr 28, 2025

@TonyGeez

I think it will be a better approach to first fix the almost unusable function calling on V3 which is actually "support it".

flamezhang

flamezhang commented on Apr 28, 2025

@flamezhang

x2 + 6

aaronvg

aaronvg commented on Apr 29, 2025

@aaronvg

We got function-calling to work with R1 using our framework BAML: https://www.boundaryml.com/blog/deepseek-r1-function-calling . We haven't had any issues making it spit out structured data.

It doesn't need tool-apis or whatnot, we just serialize types into the prompt in an efficient way, and parse the output using a custom JSON parser to handle missing quotes etc.

Let us know if you do. Here is our open-source repo: https://github.com/BoundaryML/baml

note this still works with v3!

BradKML

BradKML commented on May 27, 2025

@BradKML

Can someone help out here? Especially for @aaronvg please make them work with agent coding tools for both debugging and feature development in more complex codebases cline/cline#3845
Also, cross-reference to some of the weird v3 issues deepseek-ai/DeepSeek-V3#826 deepseek-ai/DeepSeek-V3#302

chunlea

chunlea commented on May 29, 2025

@chunlea

https://api-docs.deepseek.com/news/news250528 mentioned the new DeepSeek-R1-0528 release support for functional calling and JSON outputs. Can we assume this issue has been done?

flamezhang

flamezhang commented on May 29, 2025

@flamezhang
BradKML

BradKML commented on May 30, 2025

@BradKML

Noted with thanks,are there any root cause for this with Ollama or OpenRouter, with RooCode / Cline or other IDEs, and maybe tools like OpenHands?

r1di

r1di commented on May 30, 2025

@r1di

https://api-docs.deepseek.com/news/news250528 mentioned the new DeepSeek-R1-0528 release support for functional calling and JSON outputs. Can we assume this issue has been done?

nope, still issues(tested in cursor).

aleksei-melinic

aleksei-melinic commented on May 30, 2025

@aleksei-melinic

No, the stability is not very good. Sometimes the function call will not be executed.

I've also got different scores/results in "tool_calls" vs "reasoning_content". Do you know if function call is executed after or before reasoning?

UPD. Day later.

Ok as per https://api-docs.deepseek.com/guides/reasoning_model it does use "reasoning_content" for "content" where function call happens.

Speaking about the function calling itself the tool_choice is not supported but out of 300 calls I've got 6 one time retry attempts where there were no function calls done. So just implement retry and this issue could be called done 👍🏻

The only issue is that it seems that function calling of the content and the reasoning_content CoT often seem to not align in their decision making at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @krasserm@hyacinthus@sammcj@chunlea@paulluap

      Issue actions

        Function calling · Issue #9 · deepseek-ai/DeepSeek-R1