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

Support Reasoning via Deepseek and Openrouter API (OpenAI Compatible) #1664

Open
gururise opened this issue Jan 22, 2025 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@gururise
Copy link
Contributor

gururise commented Jan 22, 2025

The Thinking indicator never shows up if using the Deepseek API or OpenRouter (via OpenAI compatibility):

Config:

  {
    "name": "deepseek-ai/DeepSeek-R1",
    "modelUrl": "https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
    "websiteUrl": "https://deepseek.com/",
    "logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/deepseek-logo.png",
    "description": "The first reasoning model from DeepSeek. Outperforms OpenAI GPT-4-o1 on multiple benchmarks.",
    "reasoning": {
      "type": "tokens",
      "beginToken": "<think>",
      "endToken": "</think>"
    },
    "promptExamples": [
      {
        "title": "Rs in strawberry",
        "prompt": "how many R in strawberry?"
      },
      {
        "title": "Larger number",
        "prompt": "9.11 or 9.9 which number is larger?"
      },
      {
        "title": "Measuring 6 liters",
        "prompt": "I have a 6- and a 12-liter jug. I want to measure exactly 6 liters."
      }
    ],
    "endpoints": [
      {
        "type": "openai",
        "baseURL": "https://openrouter.ai/api/v1",
        "apiKey": "<API KEY REMOVED>"
      }
    ]
  },

The problem is DeekSeek API returns the reasoning in a separate reasoning_content field in the response.

reasoning_content = response.choices[0].message.reasoning_content
content = response.choices[0].message.content

As far as I can tell, none of the three existing methods will work to read this extra field in the response.

  • tokens
  • summary
  • regex

Example streaming response:

from openai import OpenAI
client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com")

# Round 1
messages = [{"role": "user", "content": "9.11 and 9.8, which is greater?"}]
response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=messages,
    stream=True
)

reasoning_content = ""
content = ""

for chunk in response:
    if chunk.choices[0].delta.reasoning_content:
        reasoning_content += chunk.choices[0].delta.reasoning_content # This is where the reasoning content is
    else:
        content += chunk.choices[0].delta.content

Please add support for DeepSeek API and OpenRouter API by adding an additional parameter to parse an extra field in the response for reasoning.

@gururise gururise added the enhancement New feature or request label Jan 22, 2025
@nsarrazin
Copy link
Collaborator

Hi thanks for opening this! Yeah this is not ideal since the way we currently handle reasoning is directly on the token stream (find begin/end tokens, things like that) which is endpoint agonistic but this would require endpoint specific-code.

Not yet sure what the best way to tackle this is, I'm open to suggestions!

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

No branches or pull requests

2 participants