重构并拆分项目
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
# ── 序列化 ──
|
||||
serde = { version = "1.0", features = ["derive"] } # 序列化/反序列化
|
||||
serde_json = "1.0"
|
||||
@@ -0,0 +1,107 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ChatCompletionRequestBody {
|
||||
pub model: String,
|
||||
pub messages: Vec<ChatCompletionRequestMessage>,
|
||||
pub stream: bool,
|
||||
pub tools: Vec<serde_json::Value>,
|
||||
pub extra_body: Option<ChatCompletionRequestExtra>,
|
||||
}
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ChatCompletionRequestExtra {
|
||||
pub thinking: ChatCompletionRequestThinking,
|
||||
}
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ChatCompletionRequestThinking {
|
||||
#[serde(rename = "type")]
|
||||
pub thinking_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ChatCompletionRequestMessage {
|
||||
pub role: String,
|
||||
pub content: String,
|
||||
pub tool_call_id: Option<String>,
|
||||
}
|
||||
impl ChatCompletionRequestMessage {
|
||||
pub fn new(role: String, content: String) -> Self {
|
||||
Self {
|
||||
role,
|
||||
content,
|
||||
tool_call_id: None,
|
||||
}
|
||||
}
|
||||
pub fn tool(role: String, content: String, tool_call_id: String) -> Self {
|
||||
Self {
|
||||
role,
|
||||
content,
|
||||
tool_call_id: Some(tool_call_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// {"choices":[{"finish_reason":"stop","index":0,"logprobs":null,"message":{"content":"你好!😊 有什么我可以帮你的吗?","role":"assistant"}}],"created":1782208455,"id":"02178220845277286f296e4c58ddf650991f54d763d292af8529b","model":"deepseek-v4-flash-260425","service_tier":"default","object":"chat.completion","usage":{"prompt_tokens":2005,"completion_tokens":125,"total_tokens":2130,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":114}}}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseBody {
|
||||
id: String,
|
||||
object: String,
|
||||
created: i64,
|
||||
model: String,
|
||||
service_tier: String,
|
||||
pub choices: Vec<ChatCompletionResponseChoice>,
|
||||
pub usage: ChatCompletionResponseUsage,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseChoice {
|
||||
index: u32,
|
||||
pub message: ChatCompletionResponseMessage,
|
||||
logprobs: Option<serde_json::Value>,
|
||||
finish_reason: String,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseMessage {
|
||||
pub role: String,
|
||||
pub content: String,
|
||||
pub reasoning_content: Option<String>,
|
||||
pub tool_calls: Option<Vec<ChatCompletionResponseToolCall>>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseToolCall {
|
||||
pub function: Option<ChatCompletionResponseFunction>,
|
||||
pub id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub call_type: String,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseFunction {
|
||||
pub arguments: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsage {
|
||||
pub prompt_tokens: u32,
|
||||
pub completion_tokens: u32,
|
||||
pub total_tokens: u32,
|
||||
pub prompt_tokens_details: ChatCompletionResponseUsagePrompt,
|
||||
pub completion_tokens_details: ChatCompletionResponseUsageCompletion,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsagePrompt {
|
||||
pub cached_tokens: u32,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ChatCompletionResponseUsageCompletion {
|
||||
pub reasoning_tokens: u32,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod user;
|
||||
@@ -0,0 +1,22 @@
|
||||
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,
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod ai;
|
||||
pub mod db;
|
||||
pub mod queue;
|
||||
@@ -0,0 +1,14 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum QueueMessage {
|
||||
Channel(String, String),
|
||||
Aissitant(String, String),
|
||||
Tool(String, String, String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct ChannelMessage {
|
||||
pub channel: String,
|
||||
pub content: String,
|
||||
}
|
||||
Reference in New Issue
Block a user