初步完成channel->queueu->[tool]->[queue]->[assistant]->channel的流程
【待处理】上下文管理和错误处理。
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ edition = "2024"
|
||||
[dependencies]
|
||||
# ── 序列化 ──
|
||||
serde = { version = "1.0", features = ["derive"] } # 序列化/反序列化
|
||||
serde_json = "1.0"
|
||||
serde_json = "1.0"
|
||||
+28
-15
@@ -23,6 +23,7 @@ pub struct ChatCompletionRequestMessage {
|
||||
pub role: String,
|
||||
pub content: String,
|
||||
pub tool_call_id: Option<String>,
|
||||
pub tool_calls: Option<Vec<ChatCompletionToolCall>>,
|
||||
}
|
||||
impl ChatCompletionRequestMessage {
|
||||
pub fn new(role: String, content: String) -> Self {
|
||||
@@ -30,13 +31,28 @@ impl ChatCompletionRequestMessage {
|
||||
role,
|
||||
content,
|
||||
tool_call_id: None,
|
||||
tool_calls: None,
|
||||
}
|
||||
}
|
||||
pub fn assistant(
|
||||
role: String,
|
||||
content: String,
|
||||
tool_calls: Option<Vec<ChatCompletionToolCall>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
role,
|
||||
content,
|
||||
tool_call_id: None,
|
||||
tool_calls: tool_calls,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tool(role: String, content: String, tool_call_id: String) -> Self {
|
||||
Self {
|
||||
role,
|
||||
content,
|
||||
tool_call_id: Some(tool_call_id),
|
||||
tool_calls: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +67,7 @@ pub struct ChatCompletionResponseBody {
|
||||
model: String,
|
||||
service_tier: String,
|
||||
pub choices: Vec<ChatCompletionResponseChoice>,
|
||||
pub usage: ChatCompletionResponseUsage,
|
||||
pub usage: ChatCompletionUsage,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -68,40 +84,37 @@ pub struct ChatCompletionResponseMessage {
|
||||
pub role: String,
|
||||
pub content: String,
|
||||
pub reasoning_content: Option<String>,
|
||||
pub tool_calls: Option<Vec<ChatCompletionResponseToolCall>>,
|
||||
pub tool_calls: Option<Vec<ChatCompletionToolCall>>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseToolCall {
|
||||
pub function: Option<ChatCompletionResponseFunction>,
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ChatCompletionToolCall {
|
||||
pub function: Option<ChatCompletionFunction>,
|
||||
pub id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub call_type: String,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseFunction {
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ChatCompletionFunction {
|
||||
pub arguments: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsage {
|
||||
pub struct ChatCompletionUsage {
|
||||
pub prompt_tokens: u32,
|
||||
pub completion_tokens: u32,
|
||||
pub total_tokens: u32,
|
||||
pub prompt_tokens_details: ChatCompletionResponseUsagePrompt,
|
||||
pub completion_tokens_details: ChatCompletionResponseUsageCompletion,
|
||||
pub prompt_tokens_details: ChatCompletionUsagePrompt,
|
||||
pub completion_tokens_details: ChatCompletionUsageCompletion,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsagePrompt {
|
||||
pub struct ChatCompletionUsagePrompt {
|
||||
pub cached_tokens: u32,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsageCompletion {
|
||||
pub struct ChatCompletionUsageCompletion {
|
||||
pub reasoning_tokens: u32,
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pub mod user;
|
||||
@@ -1,22 +0,0 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WechatUser {
|
||||
pub id: isize,
|
||||
pub user_name: String,
|
||||
pub token: String,
|
||||
pub account_id: String,
|
||||
pub base_url: String,
|
||||
pub user_id: String,
|
||||
pub user_status: isize,
|
||||
pub created_at: isize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WechatUserCreate {
|
||||
pub user_name: String,
|
||||
pub token: String,
|
||||
pub account_id: String,
|
||||
pub base_url: String,
|
||||
pub user_id: String,
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
pub mod ai;
|
||||
pub mod db;
|
||||
pub mod queue;
|
||||
|
||||
+23
-4
@@ -1,14 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::ai::ChatCompletionToolCall;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum QueueMessage {
|
||||
Channel(String, String),
|
||||
Aissitant(String, String),
|
||||
Tool(String, String, String),
|
||||
Channel(ChannelMessage),
|
||||
Aissitant(ChannelMessage, AssistantMessage),
|
||||
Tool(ChannelMessage, String, String, String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ChannelMessage {
|
||||
pub channel: String,
|
||||
pub account_id: String,
|
||||
pub from_user_id: String,
|
||||
pub content: String,
|
||||
pub context: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AssistantMessage {
|
||||
pub reasoning: Option<String>,
|
||||
pub content: String,
|
||||
pub tool_calls: Option<Vec<ChatCompletionToolCall>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ToolMessage {
|
||||
pub tool_call_id: String,
|
||||
pub name: String,
|
||||
pub result: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user