feat: implement service management API for VLM control
- Add /api/v1/mbe/health endpoint for status checks - Add /api/v2/service/start to start llama-server - Add /api/v2/service/stop to stop llama-server - Use TCP connection test for port detection (more reliable than lsof) - Add ps aux fallback for PID detection - Implement structured bilingual VLM tags - Add VLM integration documentation for Studio team Endpoints tested and working with Momentry Studio AdminView UI.
This commit is contained in:
+38
-15
@@ -32,22 +32,23 @@ struct Choice {
|
||||
}
|
||||
|
||||
pub async fn ask_llm(prompt: &str, system_prompt: &str) -> Result<String> {
|
||||
let req = ChatRequest {
|
||||
model: (*config::llm::SUMMARY_MODEL).clone(),
|
||||
messages: vec![
|
||||
ChatMessage {
|
||||
role: "system".to_string(),
|
||||
content: system_prompt.to_string(),
|
||||
let req = serde_json::json!({
|
||||
"model": (*config::llm::SUMMARY_MODEL).clone(),
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": system_prompt.to_string(),
|
||||
},
|
||||
ChatMessage {
|
||||
role: "user".to_string(),
|
||||
content: prompt.to_string(),
|
||||
{
|
||||
"role": "user",
|
||||
"content": prompt.to_string(),
|
||||
},
|
||||
],
|
||||
temperature: 0.1,
|
||||
max_tokens: 512,
|
||||
stream: false,
|
||||
};
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 512,
|
||||
"stream": false,
|
||||
"chat_template_kwargs": {"enable_thinking": false}
|
||||
});
|
||||
|
||||
debug!("Calling LLM: {}", *config::llm::SUMMARY_URL);
|
||||
|
||||
@@ -64,10 +65,32 @@ pub async fn ask_llm(prompt: &str, system_prompt: &str) -> Result<String> {
|
||||
anyhow::bail!("LLM API error: {}", text);
|
||||
}
|
||||
|
||||
let chat_res: ChatResponse = res.json().await?;
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ChatResponseExt {
|
||||
choices: Vec<ChoiceExt>,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ChoiceExt {
|
||||
message: ChatMessageExt,
|
||||
finish_reason: Option<String>,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ChatMessageExt {
|
||||
content: Option<String>,
|
||||
}
|
||||
|
||||
let chat_res: ChatResponseExt = res.json().await?;
|
||||
if let Some(choice) = chat_res.choices.first() {
|
||||
if choice.finish_reason.as_deref() == Some("length") {
|
||||
anyhow::bail!("LLM returned truncated response (finish_reason=length)");
|
||||
}
|
||||
}
|
||||
if let Some(choice) = chat_res.choices.into_iter().next() {
|
||||
Ok(choice.message.content.trim().to_string())
|
||||
let content = choice.message.content.filter(|s| !s.trim().is_empty()).unwrap_or_default();
|
||||
if content.trim().is_empty() {
|
||||
anyhow::bail!("Empty response from LLM");
|
||||
}
|
||||
Ok(content.trim().to_string())
|
||||
} else {
|
||||
anyhow::bail!("Empty response from LLM");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user