mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
chore: return highlight search content (#1340)
This commit is contained in:
parent
542937b16c
commit
9ea3c46c26
4 changed files with 12 additions and 4 deletions
|
@ -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.0–1.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.0–1.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()
|
||||
|
|
|
@ -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>,
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ pub async fn summarize_search_results(
|
|||
.map(|s| Summary {
|
||||
content: s.content,
|
||||
sources: s.sources,
|
||||
highlights: s.highlights,
|
||||
})
|
||||
.collect();
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue