Skip to content
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

Function calling #9

Open
sigren opened this issue Jan 20, 2025 · 31 comments · May be fixed by #46
Open

Function calling #9

sigren opened this issue Jan 20, 2025 · 31 comments · May be fixed by #46

Comments

@sigren
Copy link

sigren commented Jan 20, 2025

When will R1 support function calling and structured outputs? Thanks

@FORNDODAper
Copy link

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

@reatang
Copy link

reatang commented Jan 21, 2025

x2 + 1

@flyfish101
Copy link

x2 + 2

@liberty-rapid
Copy link

x2 + 3

@lzl-mt
Copy link

lzl-mt commented Jan 21, 2025

x2 + 4

@juanjopc
Copy link

x2 + 5

@engalisabry
Copy link

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.

@reatang
Copy link

reatang commented Jan 22, 2025

Thank you developers for explaining your plans to us. Don’t worry, if the application direction of R1 is not in the Agent field, developers can go in their own direction.
If the LLM has two directions of development: more like a thinker, more like a worker, I hope he will be more like a thinker.

@ibndias
Copy link

ibndias commented Jan 22, 2025

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

@jacobpretorius
Copy link

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.

jasonkneen added a commit to jasonkneen/DeepSeek-R1 that referenced this issue Jan 22, 2025
Fixes deepseek-ai#9

Add support for function calling and structured outputs.

* **README.md**
  - Add a section about function calling and structured outputs.
  - Include examples of using function calling and structured outputs.
  - Mention the future plans for these features.

* **src/model.py**
  - Add support for structured data formats like JSON and XML.
  - Implement function calling capabilities.
  - Include integration with external tools and APIs.

* **src/utils.py**
  - Add utility functions for parsing and generating structured data formats.
  - Include helper functions for function calling.

* **tests/test_model.py**
  - Add unit tests for structured data format support.
  - Include tests for function calling capabilities.
  - Add tests for API integration.

* **tests/test_utils.py**
  - Add unit tests for utility functions related to structured data formats.
  - Include tests for helper functions for function calling.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/deepseek-ai/DeepSeek-R1/issues/9?shareId=XXXX-XXXX-XXXX-XXXX).
@jasonkneen jasonkneen linked a pull request Jan 22, 2025 that will close this issue
@Chrisbattarbee
Copy link

Also looking for this

@feliks912
Copy link

Bump, definitely bump

@jayeew
Copy link

jayeew commented Jan 23, 2025

When will R1 support agent?

@letscagefdn
Copy link

response_format: { type: 'json_object' }

@bgarnr
Copy link

bgarnr commented Jan 24, 2025

Thank you. I look forward to having a provider that allows my Microsoft Semantic Kernel powered application to use Deepseek as an alternative for auto function calling.

@Dey-Sumit
Copy link

x2

@justinlietz93
Copy link

https://github.com/justinlietz93/agent_tools

I built a suite of tools and a wrapper for deepseek reasoner to use, check it out

@enemchy
Copy link

enemchy commented Jan 25, 2025

My application automates code generation using file operations via functional calls. Currently, integrating R1 requires significant refactoring due to the lack of function calling support, even though this feature is already standardized in most models (OpenAI, Anthropic, Mistral, etc.). To migrate from other models to R1, I must rewrite critical components of the application, which increases transition costs and error risks. Without function calling support, developers are forced to adopt less efficient workarounds or delay adopting R1, despite its exceptional code generation capabilities.

Accelerating the development of function calling for R1 will lower the entry barrier for communities relying on industry-standard approaches.

@justinlietz93
Copy link

My application automates code generation using file operations via functional calls. Currently, integrating R1 requires significant refactoring due to the lack of function calling support, even though this feature is already standardized in most models (OpenAI, Anthropic, Mistral, etc.). To migrate from other models to R1, I must rewrite critical components of the application, which increases transition costs and error risks. Without function calling support, developers are forced to adopt less efficient workarounds or delay adopting R1, despite its exceptional code generation capabilities.

Accelerating the development of function calling for R1 will lower the entry barrier for communities relying on industry-standard approaches.

Can you please email me, feel free to look at my agent_tools repo, I have powerful tools for Deepseek R1 and I’m improving them daily. [email protected], I have more contact links on my github

@phpmac
Copy link

phpmac commented Jan 26, 2025

go

@vepicurean
Copy link

vepicurean commented Jan 26, 2025

Agree with the original feature request ( function calling and structured outputs standard features on a API now), without structured outputs, it's nearly impossible to achieve targeted data accuracy levels for many applications. When needing data accuracy of 99.999% on large volumes ( hundreds of thousands of records), structured outputs made a huge difference in the accuracy of my responses for unstructured ( document store) database queries using o1-mini.

Function calling, yes, I could do the workaround as suggested), but given the time and effort I already put into the development of the autonomous agent back end programming, I'd prefer not to go backwards and put in workarounds to use R1 when hopefully my existing code using function calling will be adequate when the R series of models and the DeepSeek API can in fact support function calling - hopefully the DeepSeek function calling and structured outputs performance will be just as good as on the OpenAI API using o1 and gpt-4o.

@abylikhsanov
Copy link

x2

@aaronvg
Copy link

aaronvg commented Jan 27, 2025

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

@dickens88
Copy link

I'm also looking forward

@justinlietz93
Copy link

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

Awesome I’m going to take a look, because I’ve been building something for the same idea, to allow any LLM to use any tool

@MehdiBukhari
Copy link

Looking forward deep seek with function calling

@jenyss
Copy link

jenyss commented Jan 29, 2025

+1

@thorwebdev
Copy link

In case this is helpful for others, looks like the Qwen-32B distillation https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/discussions/7 has support for function calling.

@danruggi
Copy link

Asking for
"response_format": {'type': 'json_object' }
too

Thanks for the effort

@krasserm
Copy link

krasserm commented Feb 6, 2025

One possible alternative to builtin function calling via JSON is to leverage DeepSeek-R1's strong coding capabilities and let the model generate code actions in Python. I experimented with this approach and found that it outperforms Claude 3.5 Sonnet on agentic tasks by a large margin (65.5% vs 53.1% on a GAIA validation subset). I used freeact as agent scaffold.

@sammcj
Copy link

sammcj commented Feb 9, 2025

I've spent the past week testing DeepSeek R1 with Cline, Roo Coder and a number of other agentic coding tools using a combination of templates and prompting methods. While R1 is clearly a very capable model in general - in reality it's not practical to use (especially in production) due to it's lack of tool/function calling.

I believe what we need is a battle-tested template or fine tune from DeepSeek to enable reliable tool/function calling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.