feat: multi-branch template scanning from git repo + manual template selection
- Rewrite template.rs to scan all remote branches via git commands (git fetch/branch -r/ls-tree/git show/git archive) - Add manual template picker dropdown in CreateForm UI - Remove sentence-transformers/embed.py from Dockerfile (separate container) - Clean up Gitea API approach, use local git repo instead - Add chat panel and sidebar layout improvements
This commit is contained in:
53
src/api/chat.rs
Normal file
53
src/api/chat.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::sync::Arc;
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
routing::post,
|
||||
Json, Router,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::llm::{ChatMessage, LlmClient};
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ChatRequest {
|
||||
messages: Vec<SimpleChatMessage>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SimpleChatMessage {
|
||||
role: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
pub fn router(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/chat", post(chat))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
async fn chat(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(input): Json<ChatRequest>,
|
||||
) -> Result<Json<serde_json::Value>, Response> {
|
||||
let llm = LlmClient::new(&state.config.llm);
|
||||
let messages: Vec<ChatMessage> = input
|
||||
.messages
|
||||
.into_iter()
|
||||
.map(|m| ChatMessage {
|
||||
role: m.role,
|
||||
content: Some(m.content),
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let reply = llm.chat(messages).await.map_err(|e| {
|
||||
tracing::error!("Chat LLM error: {}", e);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response()
|
||||
})?;
|
||||
|
||||
Ok(Json(serde_json::json!({ "reply": reply })))
|
||||
}
|
||||
Reference in New Issue
Block a user