diff --git a/common/src/error/mod.rs b/common/src/error/mod.rs new file mode 100644 index 0000000..e8ae652 --- /dev/null +++ b/common/src/error/mod.rs @@ -0,0 +1 @@ +pub mod queue; diff --git a/common/src/error/queue.rs b/common/src/error/queue.rs new file mode 100644 index 0000000..e69de29 diff --git a/common/src/model/ai.rs b/common/src/model/ai.rs new file mode 100644 index 0000000..e5833b0 --- /dev/null +++ b/common/src/model/ai.rs @@ -0,0 +1,120 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize)] +pub struct ChatCompletionRequestBody { + pub model: String, + pub messages: Vec, + pub stream: bool, + pub tools: Vec, + pub extra_body: Option, +} +#[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, + pub tool_calls: Option>, +} +impl ChatCompletionRequestMessage { + pub fn new(role: String, content: String) -> Self { + Self { + role, + content, + tool_call_id: None, + tool_calls: None, + } + } + pub fn assistant( + role: String, + content: String, + tool_calls: Option>, + ) -> 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, + } + } +} + +// {"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, + pub usage: ChatCompletionUsage, +} + +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +pub struct ChatCompletionResponseChoice { + index: u32, + pub message: ChatCompletionResponseMessage, + logprobs: Option, + finish_reason: String, +} +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +pub struct ChatCompletionResponseMessage { + pub role: String, + pub content: String, + pub reasoning_content: Option, + pub tool_calls: Option>, +} +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct ChatCompletionToolCall { + pub function: Option, + pub id: String, + #[serde(rename = "type")] + pub call_type: String, +} +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct ChatCompletionFunction { + pub arguments: String, + pub name: String, +} + +#[derive(Debug, Deserialize)] +pub struct ChatCompletionUsage { + pub prompt_tokens: u32, + pub completion_tokens: u32, + pub total_tokens: u32, + pub prompt_tokens_details: ChatCompletionUsagePrompt, + pub completion_tokens_details: ChatCompletionUsageCompletion, +} + +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +pub struct ChatCompletionUsagePrompt { + pub cached_tokens: u32, +} +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +pub struct ChatCompletionUsageCompletion { + pub reasoning_tokens: u32, +} diff --git a/common/src/model/mod.rs b/common/src/model/mod.rs new file mode 100644 index 0000000..4c704d3 --- /dev/null +++ b/common/src/model/mod.rs @@ -0,0 +1 @@ +pub mod ai;