mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-25 02:08:30 +02:00
chat history added to context and patching text content
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user