kipina-node: auth-viesti välittää mallinimen ja Ollama-mallilistauksen hubille
build_auth_message käyttää nyt oikeaa mallinimeä hardkoodatun sijaan. Lisäksi natiivisolmu hakee Ollaman mallilistauksen ja lähettää sen auth-viestissä hubille. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,6 +78,20 @@ impl LlmEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hakee kaikki Ollamaan asennetut mallit
|
||||
pub async fn fetch_models(&self) -> Result<serde_json::Value, String> {
|
||||
let resp = self.client.get(format!("{}/api/tags", self.ollama_url))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Ollama tags fetch: {}", e))?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
resp.json().await.map_err(|e| format!("Ollama tags json: {}", e))
|
||||
} else {
|
||||
Err(format!("Ollama tags epäonnistui: {}", resp.status()))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate(&self, prompt: &str, max_tokens: usize) -> Result<GenerateResult, String> {
|
||||
// System prompt tulee agentin konfiguraatiosta (frontend lähettää sen osana promptia).
|
||||
// Tässä ei yliajeta sitä — Ollama saa vain prompt-kentän.
|
||||
|
||||
@@ -222,7 +222,7 @@ fn collect_system_info() -> serde_json::Value {
|
||||
}
|
||||
|
||||
/// Koko auth-viesti hubille
|
||||
fn build_auth_message(allocated_gb: u32, model_name: &str) -> String {
|
||||
fn build_auth_message(allocated_gb: u32, model_name: &str, models_data: Option<serde_json::Value>) -> String {
|
||||
let sys = collect_system_info();
|
||||
let gpus = collect_all_gpus();
|
||||
|
||||
@@ -251,6 +251,10 @@ fn build_auth_message(allocated_gb: u32, model_name: &str) -> String {
|
||||
msg.as_object_mut().unwrap().insert("gpus".to_string(), json!(gpu_json));
|
||||
}
|
||||
|
||||
if let Some(models) = models_data {
|
||||
msg.as_object_mut().unwrap().insert("models".to_string(), models);
|
||||
}
|
||||
|
||||
msg.to_string()
|
||||
}
|
||||
|
||||
@@ -324,6 +328,19 @@ async fn main() {
|
||||
let active_model = llm.as_ref().map(|e| e.model_name()).unwrap_or_else(|| "unknown".to_string());
|
||||
tracing::info!("Käytettävä kielimalli konfiguroitu (selected_task): {}", active_model);
|
||||
|
||||
// Haetaan paikalliset mallit hubille lähetettäväksi
|
||||
let mut available_models = None;
|
||||
if let Some(ref engine) = llm {
|
||||
match engine.fetch_models().await {
|
||||
Ok(models) => {
|
||||
available_models = Some(models);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("Mallilistauksen haku epäonnistui: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yhdistetään hubiin
|
||||
loop {
|
||||
match connect_async(&hub_url).await {
|
||||
@@ -331,7 +348,7 @@ async fn main() {
|
||||
tracing::info!("Yhdistetty hubiin!");
|
||||
let (mut write, mut read) = ws_stream.split();
|
||||
|
||||
let auth = build_auth_message(allocated_gb, &active_model);
|
||||
let auth = build_auth_message(allocated_gb, &active_model, available_models.clone());
|
||||
if write.send(Message::Text(auth)).await.is_err() {
|
||||
tracing::error!("Auth-viestin lähetys epäonnistui");
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user