feat(growth): 扩展 LlmDriverForExtraction — 新增 extract_combined_all 默认实现
This commit is contained in:
@@ -19,6 +19,21 @@ pub trait LlmDriverForExtraction: Send + Sync {
|
|||||||
messages: &[Message],
|
messages: &[Message],
|
||||||
extraction_type: MemoryType,
|
extraction_type: MemoryType,
|
||||||
) -> Result<Vec<ExtractedMemory>>;
|
) -> Result<Vec<ExtractedMemory>>;
|
||||||
|
|
||||||
|
/// 单次 LLM 调用提取全部类型(记忆 + 经验 + 画像信号)
|
||||||
|
/// 默认实现:退化到 3 次独立调用
|
||||||
|
async fn extract_combined_all(
|
||||||
|
&self,
|
||||||
|
messages: &[Message],
|
||||||
|
) -> Result<crate::types::CombinedExtraction> {
|
||||||
|
let mut combined = crate::types::CombinedExtraction::default();
|
||||||
|
for mt in [MemoryType::Preference, MemoryType::Knowledge, MemoryType::Experience] {
|
||||||
|
if let Ok(mems) = self.extract_memories(messages, mt).await {
|
||||||
|
combined.memories.extend(mems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(combined)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Memory Extractor - extracts memories from conversations
|
/// Memory Extractor - extracts memories from conversations
|
||||||
@@ -362,6 +377,14 @@ mod tests {
|
|||||||
assert!(!result.is_empty());
|
assert!(!result.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_extract_combined_all_default_impl() {
|
||||||
|
let driver = MockLlmDriver;
|
||||||
|
let messages = vec![Message::user("Hello")];
|
||||||
|
let result = driver.extract_combined_all(&messages).await.unwrap();
|
||||||
|
assert_eq!(result.memories.len(), 3); // 3 types
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prompts_available() {
|
fn test_prompts_available() {
|
||||||
assert!(!prompts::get_extraction_prompt(MemoryType::Preference).is_empty());
|
assert!(!prompts::get_extraction_prompt(MemoryType::Preference).is_empty());
|
||||||
|
|||||||
Reference in New Issue
Block a user