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 other finish reasons for OpenAiClient (deepseek) #33327

Merged
merged 6 commits into from
Feb 18, 2025

Conversation

thomasht86
Copy link
Contributor

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

When hitting OpenAI-compatible endpoints, such as https://docs.together.ai/docs/openai-api-compatibility, other models may often have other finish_reasons than OpenAI's models, based on their stop-tokens.

Examples:

  • meta-llama/Llama-3.3-70B-Instruct-Turbo:
curl -X POST "https://api.together.xyz/v1/chat/completions" \
  -H "Authorization: Bearer $TOGETHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
    "messages": [],
    "max_tokens": null,
    "temperature": 0.7,
    "top_p": 0.7,
    "top_k": 50,
    "repetition_penalty": 1,
    "stop": ["<|eot_id|>","<|eom_id|>"],
    "stream": true
  }'
  • deepseek-ai/DeepSeek-R1:
curl -X POST "https://api.together.xyz/v1/chat/completions" \
 -H "Authorization: Bearer $TOGETHER_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{
   "model": "deepseek-ai/DeepSeek-R1",
   "messages": [],
   "max_tokens": null,
   "temperature": 0.6,
   "top_p": 0.95,
   "top_k": 50,
   "repetition_penalty": 1,
   "stop": ["<|end▁of▁sentence|>"],
   "stream": true
 }'

Before this PR, a request to this endpoint would result in:

"fields": {
    "error": "Unknown OpenAi completion finish reason 'eos'",
    "source": "openai",
    "code": 400
}

This PR changes the default behavior to only throw exception on finish_reason=error, and let through other ones, making our OpenAiClient more generic.

@thomasht86 thomasht86 changed the title Thomasht86/support other finish reasons for OpenAiClient (deepseek) Support other finish reasons for OpenAiClient (deepseek) Feb 14, 2025
glebashnik
glebashnik previously approved these changes Feb 14, 2025
Copy link
Contributor

@glebashnik glebashnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@thomasht86 thomasht86 merged commit 1128cdd into master Feb 18, 2025
3 checks passed
@thomasht86 thomasht86 deleted the thomasht86/add-llm-configs-deepseek branch February 18, 2025 13:52
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 this pull request may close these issues.

3 participants