chore: return highlight search content (#1340)

This commit is contained in:
Nathan.fooo 2025-04-15 16:39:48 +08:00 committed by GitHub
parent 542937b16c
commit 9ea3c46c26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 4 deletions

View file

@ -78,14 +78,15 @@ impl AzureOpenAIChat {
}
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
pub struct SearchSummary {
pub content: String,
pub highlights: String,
pub sources: Vec<Uuid>,
pub score: f32,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
pub struct SummarySearchResponse {
pub summaries: Vec<SearchSummary>,
}
@ -94,6 +95,7 @@ pub struct SummarySearchResponse {
#[serde(deny_unknown_fields)]
struct SummarySearchSchema {
pub answer: String,
pub highlights: String,
pub score: String,
pub sources: Vec<String>,
}
@ -108,6 +110,7 @@ Instructions:
Output must include:
- `answer`: a concise summary.
- `highlights`:A markdown bullet list that highlights key themes and important details (e.g., date, time, location, etc.).
- `score`: relevance score (0.01.0), where:
- 1.0 = fully supported by context,
- 0.0 = unsupported,
@ -120,6 +123,7 @@ You are a strict, context-bound question answering assistant. Answer solely base
Output must include:
- `answer`: a concise answer.
- `highlights`:A markdown bullet list that highlights key themes and important details (e.g., date, time, location, etc.).
- `score`: relevance score (0.01.0), where:
- 1.0 = fully supported by context,
- 0.0 = unsupported,
@ -171,7 +175,7 @@ pub async fn summarize_documents<C: Config>(
let response_format = ResponseFormat::JsonSchema {
json_schema: ResponseFormatJsonSchema {
description: Some(
"A response containing a final answer, score and relevance sources".to_string(),
"A response containing a final answer, highlight, score and relevance sources".to_string(),
),
name: "SummarySearchSchema".into(),
schema: Some(schema_value),
@ -230,6 +234,7 @@ pub async fn summarize_documents<C: Config>(
let summary = SearchSummary {
content: response.answer,
highlights: response.highlights,
sources: response
.sources
.into_iter()

View file

@ -52,6 +52,8 @@ fn default_search_score_limit() -> f64 {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Summary {
pub content: String,
#[serde(default)]
pub highlights: String,
pub sources: Vec<Uuid>,
}

View file

@ -219,6 +219,7 @@ pub async fn summarize_search_results(
.map(|s| Summary {
content: s.content,
sources: s.sources,
highlights: s.highlights,
})
.collect();
},

View file

@ -63,7 +63,7 @@ async fn summary_search_result() {
.unwrap();
dbg!(&resp);
assert_eq!(resp.summaries.len(), 1);
assert_eq!(resp.summaries[0].sources.len(), 3);
assert!(resp.summaries[0].sources.len() > 1);
let resp = ai_chat
.summarize_documents("multiplayer game", model_name, docs.clone(), true)