chat history added to context and patching text content

This commit is contained in:
Per Stark
2025-03-16 21:24:24 +01:00
parent f2a434a071
commit 2931724009
13 changed files with 141 additions and 166 deletions

View File

@@ -5,6 +5,7 @@ use async_openai::{
CreateChatCompletionRequest, CreateChatCompletionRequestArgs, CreateChatCompletionResponse,
ResponseFormat, ResponseFormatJsonSchema,
},
MessageFiles,
};
use serde::Deserialize;
use serde_json::{json, Value};
@@ -12,7 +13,13 @@ use tracing::debug;
use common::{
error::AppError,
storage::{db::SurrealDbClient, types::knowledge_entity::KnowledgeEntity},
storage::{
db::SurrealDbClient,
types::{
knowledge_entity::KnowledgeEntity,
message::{format_history, Message},
},
},
};
use crate::retrieve_entities;
@@ -109,6 +116,31 @@ pub fn create_user_message(entities_json: &Value, query: &str) -> String {
)
}
pub fn create_user_message_with_history(
entities_json: &Value,
history: &[Message],
query: &str,
) -> String {
format!(
r#"
Chat history:
==================
{}
Context Information:
==================
{}
User Question:
==================
{}
"#,
format_history(history),
entities_json,
query
)
}
pub fn create_chat_request(
user_message: String,
) -> Result<CreateChatCompletionRequest, OpenAIError> {