使用MistralAI Python SDK调用本地Pixtral服务报错400的解决方法
问题解决方法
问题原因
mistralai SDK 1.2.3版本在调用chat.complete时,默认会自动向请求体中添加safe_prompt=False参数,但你的本地Pixtral服务器API不支持这个额外参数,因此返回400错误。
解决步骤
直接在chat.complete调用中显式设置safe_prompt=None,阻止SDK发送该参数:
from mistralai import Mistral model = "mistralai/Pixtral-12B-2409" client = Mistral(server_url="http://localhost:8000") chat_response = client.chat.complete( messages=[ { "role": "user", "content": "What is the best French cheese?" } ], model=model, safe_prompt=None # 添加这一行,禁用默认的safe_prompt参数 ) print(chat_response.choices[0].message.content)
验证
修改后重新运行代码,请求将不再包含safe_prompt参数,与你之前正常工作的curl请求结构一致,即可成功获取服务器响应。
内容的提问来源于stack exchange,提问作者Javide
相关产品推荐
相关产品推荐

