初步完成channel->queueu->[tool]->[queue]->[assistant]->channel的流程
【待处理】上下文管理和错误处理。
This commit is contained in:
@@ -2,7 +2,7 @@ use std::sync::OnceLock;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use common::ai::ChatCompletionRequestMessage;
|
||||
use common::ai::{ChatCompletionRequestMessage, ChatCompletionToolCall};
|
||||
|
||||
static CHAT_CONTEXT: OnceLock<Mutex<Vec<ChatCompletionRequestMessage>>> = OnceLock::new();
|
||||
|
||||
@@ -20,8 +20,15 @@ pub async fn snapshot_context() -> Vec<ChatCompletionRequestMessage> {
|
||||
context.clone()
|
||||
}
|
||||
|
||||
pub async fn add_assistant_message(content: String) {
|
||||
let message = ChatCompletionRequestMessage::new("assistant".to_string(), content);
|
||||
pub async fn add_assistant_message(
|
||||
content: String,
|
||||
tool_calls: Option<Vec<ChatCompletionToolCall>>,
|
||||
) {
|
||||
let message = ChatCompletionRequestMessage::assistant(
|
||||
"assistant".to_string(),
|
||||
content,
|
||||
tool_calls,
|
||||
);
|
||||
push_context_message(message).await;
|
||||
}
|
||||
|
||||
@@ -31,6 +38,6 @@ pub async fn add_user_message(content: String) {
|
||||
}
|
||||
|
||||
pub async fn add_tool_message(call_id: String, result: String) {
|
||||
let message = ChatCompletionRequestMessage::tool("user".to_string(), result, call_id);
|
||||
let message = ChatCompletionRequestMessage::tool("tool".to_string(), result, call_id);
|
||||
push_context_message(message).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user