调整公共模块结构,方便后续延伸

This commit is contained in:
2026-06-29 11:58:16 +08:00
parent 46544e9c42
commit 6d45b8fb7a
12 changed files with 14 additions and 170 deletions
+3 -6
View File
@@ -2,7 +2,7 @@ use std::sync::OnceLock;
use tokio::sync::Mutex;
use common::ai::{ChatCompletionRequestMessage, ChatCompletionToolCall};
use common::model::ai::{ChatCompletionRequestMessage, ChatCompletionToolCall};
static CHAT_CONTEXT: OnceLock<Mutex<Vec<ChatCompletionRequestMessage>>> = OnceLock::new();
@@ -24,11 +24,8 @@ pub async fn add_assistant_message(
content: String,
tool_calls: Option<Vec<ChatCompletionToolCall>>,
) {
let message = ChatCompletionRequestMessage::assistant(
"assistant".to_string(),
content,
tool_calls,
);
let message =
ChatCompletionRequestMessage::assistant("assistant".to_string(), content, tool_calls);
push_context_message(message).await;
}
+1 -2
View File
@@ -3,7 +3,6 @@ use crate::core::context::{
};
use ai::core::send_message;
use common::queue::QueueMessage;
use serde_json::error;
use tokio::sync::{mpsc::Receiver, mpsc::Sender};
use wechat::manager::WeChatMultiAccountManager;
@@ -11,7 +10,7 @@ pub async fn create_queue(
sender: Sender<QueueMessage>,
mut receiver: Receiver<QueueMessage>,
manager: WeChatMultiAccountManager,
) -> Result<(), error::Error> {
) -> anyhow::Result<()> {
tokio::spawn(async move {
while let Some(msg) = receiver.recv().await {
let queue_sender = sender.clone();
-34
View File
@@ -1,34 +0,0 @@
use axum::{
Json,
http::StatusCode,
response::{IntoResponse, Response},
};
use serde_json::json;
#[allow(unused)]
#[derive(Debug, thiserror::Error)]
pub enum AppError {
#[error("not found")]
NotFound,
#[error(transparent)]
AnyHow(#[from] anyhow::Error),
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, message) = match self {
AppError::NotFound => (StatusCode::NOT_FOUND, "resource not found".to_string()),
AppError::AnyHow(err) => {
eprintln!("internal error: {err:?}");
(
StatusCode::INTERNAL_SERVER_ERROR,
"internal server error".to_string(),
)
}
};
(status, Json(json!({"error":message}))).into_response()
}
}
#[allow(unused)]
pub type AppResult<T> = Result<T, AppError>;
-1
View File
@@ -1,6 +1,5 @@
mod channel;
mod core;
mod error;
mod http;
mod model;
mod repository;