调整公共模块结构,方便后续延伸
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,6 +1,5 @@
|
||||
mod channel;
|
||||
mod core;
|
||||
mod error;
|
||||
mod http;
|
||||
mod model;
|
||||
mod repository;
|
||||
|
||||
Reference in New Issue
Block a user