mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-28 04:11:51 +01:00
refactor: single object queue
This commit is contained in:
112
src/models/text_content.rs
Normal file
112
src/models/text_content.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::models::file_info::FileInfo;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Represents a single piece of text content extracted from various sources.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct TextContent {
|
||||
pub text: String,
|
||||
pub file_info: Option<FileInfo>,
|
||||
pub instructions: String,
|
||||
pub category: String,
|
||||
}
|
||||
|
||||
impl TextContent {
|
||||
/// Creates a new `TextContent` instance.
|
||||
pub fn new(text: String, file_info: Option<FileInfo>, instructions: String, category: String) -> Self {
|
||||
Self {
|
||||
text,
|
||||
file_info,
|
||||
instructions,
|
||||
category,
|
||||
}
|
||||
}
|
||||
|
||||
/// Processes the `TextContent` by sending it to an LLM, storing in a graph DB, and vector DB.
|
||||
pub async fn process(&self) -> Result<(), ProcessingError> {
|
||||
// Step 1: Send to LLM for analysis
|
||||
let analysis = self.send_to_llm().await?;
|
||||
|
||||
// Step 2: Store analysis results in Graph DB
|
||||
self.store_in_graph_db(&analysis).await?;
|
||||
|
||||
// Step 3: Split text and store in Vector DB
|
||||
self.store_in_vector_db().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sends text to an LLM for analysis.
|
||||
async fn send_to_llm(&self) -> Result<LLMAnalysis, ProcessingError> {
|
||||
// TODO: Implement interaction with your specific LLM API.
|
||||
// Example using reqwest:
|
||||
/*
|
||||
let client = reqwest::Client::new();
|
||||
let response = client.post("http://llm-api/analyze")
|
||||
.json(&serde_json::json!({ "text": self.text }))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ProcessingError::LLMError(e.to_string()))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(ProcessingError::LLMError(format!("LLM API returned status: {}", response.status())));
|
||||
}
|
||||
|
||||
let analysis: LLMAnalysis = response.json().await
|
||||
.map_err(|e| ProcessingError::LLMError(e.to_string()))?;
|
||||
|
||||
Ok(analysis)
|
||||
*/
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Stores analysis results in a graph database.
|
||||
async fn store_in_graph_db(&self, analysis: &LLMAnalysis) -> Result<(), ProcessingError> {
|
||||
// TODO: Implement storage logic for your specific graph database.
|
||||
// Example:
|
||||
/*
|
||||
let graph_db = GraphDB::new("http://graph-db:8080");
|
||||
graph_db.insert_analysis(analysis).await.map_err(|e| ProcessingError::GraphDBError(e.to_string()))?;
|
||||
*/
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Splits text and stores it in a vector database.
|
||||
async fn store_in_vector_db(&self) -> Result<(), ProcessingError> {
|
||||
// TODO: Implement text splitting and vector storage logic.
|
||||
// Example:
|
||||
/*
|
||||
let chunks = text_splitter::split(&self.text);
|
||||
let vector_db = VectorDB::new("http://vector-db:5000");
|
||||
for chunk in chunks {
|
||||
vector_db.insert(chunk).await.map_err(|e| ProcessingError::VectorDBError(e.to_string()))?;
|
||||
}
|
||||
*/
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the analysis results from the LLM.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct LLMAnalysis {
|
||||
pub entities: Vec<String>,
|
||||
pub summary: String,
|
||||
// Add other fields based on your LLM's output.
|
||||
}
|
||||
|
||||
/// Error types for processing `TextContent`.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ProcessingError {
|
||||
#[error("LLM processing error: {0}")]
|
||||
LLMError(String),
|
||||
|
||||
#[error("Graph DB storage error: {0}")]
|
||||
GraphDBError(String),
|
||||
|
||||
#[error("Vector DB storage error: {0}")]
|
||||
VectorDBError(String),
|
||||
|
||||
#[error("Unknown processing error")]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user