mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-11-30 15:55:49 +08:00
fix: omit tools field from provider requests when empty
vLLM and some OpenAI-compatible APIs reject requests containing an empty `tools: []` array with a 400 Bad Request. This affects the model connectivity test which sends no tools. Instead of always including the tools field, conditionally add it only when tools are present.
This commit is contained in:
1 parent
14d6a501a0
commit
e4515dc4e0
3 files changed
+17
-11
No files matched your search
@@ -54,11 +54,13 @@ impl Provider for AnthropicProvider {
|
||||
.unwrap_or(DEFAULT_MAX_OUTPUT_TOKENS);
|
||||
let mut body = json!({
|
||||
"model": request.model.model_id, "system": request.prompt.instructions, "messages": messages,
|
||||
"max_tokens": max_tokens, "stream": true,
|
||||
"tools": request.prompt.tools.iter().map(|tool| json!({
|
||||
"name": tool.name, "description": tool.description, "input_schema": tool.parameters
|
||||
})).collect::<Vec<_>>()
|
||||
"max_tokens": max_tokens, "stream": true
|
||||
});
|
||||
if !request.prompt.tools.is_empty() {
|
||||
body["tools"] = json!(request.prompt.tools.iter().map(|tool| json!({
|
||||
"name": tool.name, "description": tool.description, "input_schema": tool.parameters
|
||||
})).collect::<Vec<_>>());
|
||||
}
|
||||
apply_model(&mut body, &request.model)?;
|
||||
merge_extra_params(&mut body, &request.model.extra_params)?;
|
||||
if let Some(recorder) = &recorder {
|
||||
|
||||
@@ -65,12 +65,14 @@ impl Provider for OpenAiChatProvider {
|
||||
let mut body = json!({
|
||||
"model": request.model.model_id,
|
||||
"messages": messages,
|
||||
"tools": request.prompt.tools.iter().map(|tool| json!({"type":"function","function":{
|
||||
"name": tool.name, "description": tool.description, "parameters": tool.parameters
|
||||
}})).collect::<Vec<_>>(),
|
||||
"stream": true,
|
||||
"stream_options": {"include_usage": true}
|
||||
});
|
||||
if !request.prompt.tools.is_empty() {
|
||||
body["tools"] = json!(request.prompt.tools.iter().map(|tool| json!({"type":"function","function":{
|
||||
"name": tool.name, "description": tool.description, "parameters": tool.parameters
|
||||
}})).collect::<Vec<_>>());
|
||||
}
|
||||
apply_model(&mut body, &request.model, config.max_output_tokens)?;
|
||||
merge_extra_params(&mut body, &request.model.extra_params)?;
|
||||
apply_openai_prompt_cache_key(&mut body, &request.model.model_id)?;
|
||||
|
||||
@@ -69,12 +69,14 @@ impl Provider for OpenAiResponsesProvider {
|
||||
let mut body = json!({
|
||||
"model": request.model.model_id, "input": input, "stream": true,
|
||||
"instructions": request.prompt.instructions,
|
||||
"include": ["reasoning.encrypted_content"],
|
||||
"tools": request.prompt.tools.iter().map(|tool| json!({
|
||||
"include": ["reasoning.encrypted_content"]
|
||||
});
|
||||
if !request.prompt.tools.is_empty() {
|
||||
body["tools"] = json!(request.prompt.tools.iter().map(|tool| json!({
|
||||
"type":"function", "name":tool.name, "description":tool.description,
|
||||
"parameters":tool.parameters, "strict":false
|
||||
})).collect::<Vec<_>>()
|
||||
});
|
||||
})).collect::<Vec<_>>());
|
||||
}
|
||||
apply_model(&mut body, &request.model, config.max_output_tokens)?;
|
||||
merge_extra_params(&mut body, &request.model.extra_params)?;
|
||||
apply_openai_prompt_cache_key(&mut body, &request.model.model_id)?;
|
||||
|
||||
Reference in new issue
Block a user