fix(ai_tools): Update LLM request parameters and improve response handling

- Add `stream: Some(false)` to file search and data catalog tools
- Make `json_schema` optional in `ResponseFormat` serialization
- Enhance logging in search file tool with debug and warning messages
- Improve error context when parsing LLM JSON responses
This commit is contained in:
dal 2025-02-07 11:05:39 -07:00
parent 864257bc24
commit 8054bedf1a
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 8 additions and 4 deletions

View File

@ -191,6 +191,7 @@ impl Message {
pub struct ResponseFormat {
#[serde(rename = "type")]
pub type_: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub json_schema: Option<Value>,
}

View File

@ -99,7 +99,7 @@ impl SearchDataCatalogTool {
content: prompt,
name: None,
}],
temperature: Some(0.0),
stream: Some(false),
response_format: Some(ResponseFormat {
type_: "json_object".to_string(),
json_schema: None,

View File

@ -97,7 +97,7 @@ impl SearchFilesTool {
content: prompt,
name: None,
}],
temperature: Some(0.0),
stream: Some(false),
response_format: Some(ResponseFormat {
type_: "json_object".to_string(),
json_schema: None,
@ -116,7 +116,10 @@ impl SearchFilesTool {
Message::Assistant {
content: Some(content),
..
} => content,
} => {
debug!("Received LLM response content: {}", content);
content
}
_ => {
error!("LLM response missing content");
return Err(anyhow::anyhow!("LLM response missing content"));
@ -125,7 +128,7 @@ impl SearchFilesTool {
// Parse into structured response
serde_json::from_str(content).map_err(|e| {
warn!(error = %e, "Failed to parse LLM response as JSON");
warn!(error = %e, content = content, "Failed to parse LLM response as JSON");
anyhow::anyhow!("Failed to parse search results: {}", e)
})
}