ValueError
deepseek.errors.ValueError
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7, top_p=0.9)
File "/usr/local/lib/python3.9/site-packages/deepseek/client.py", line 120, in create
raise ValueError("Cannot set both temperature and top_p parameters together.")
ValueError: Cannot set both temperature and top_p parameters together. Why it happens
DeepSeek's sampling configuration requires either temperature or top_p to control randomness, but not both simultaneously. Setting both causes an internal conflict in the sampling algorithm, triggering this error.
Detection
Check your API call parameters before sending requests; log or assert that only one of temperature or top_p is set to avoid this conflict error.
Causes & fixes
Both temperature and top_p parameters are set in the DeepSeek chat completion call.
Remove one of the parameters so only temperature or top_p is specified, never both.
Using a wrapper or helper function that sets default temperature and top_p simultaneously.
Review and update helper functions or config to ensure only one sampling parameter is passed to DeepSeek client.
Misunderstanding of DeepSeek API sampling parameters leading to simultaneous use.
Consult DeepSeek documentation to understand that temperature and top_p are mutually exclusive and choose the appropriate one.
Code: broken vs fixed
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
messages = [{"role": "user", "content": "Hello"}]
# This line causes the ValueError due to both parameters set
response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7, top_p=0.9)
print(response) from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
messages = [{"role": "user", "content": "Hello"}]
# Fixed: Removed top_p parameter to avoid conflict
response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7)
print(response) Workaround
If you cannot change the call immediately, wrap the client call in try/except catching ValueError and retry the call with only one sampling parameter set.
Prevention
Design your configuration and wrapper functions to enforce mutually exclusive setting of temperature and top_p before calling DeepSeek APIs to prevent this error.