koodilabran v0.1

This commit is contained in:
2026-04-02 10:07:48 +03:00
parent 11bd802be5
commit 8e20b06344
6 changed files with 881 additions and 62 deletions

View File

@@ -25,7 +25,7 @@ const ALLOWED_ORIGINS: &[&str] = &[
];
// Sallitut viestityyypit clientilta
const ALLOWED_MSG_TYPES: &[&str] = &["auth", "result", "pair_done", "llm_chunk", "llm_done", "download_progress"];
const ALLOWED_MSG_TYPES: &[&str] = &["auth", "result", "pair_done", "llm_chunk", "llm_done", "download_progress", "user_text"];
struct AppState {
next_node_id: Mutex<u64>,
@@ -304,7 +304,28 @@ async fn main() {
});
let _ = state_for_task.stats_tx.send(phi3_msg.to_string());
tracing::debug!("Tehtävät lähetetty: pair + smollm + qwen + phi3");
// Coder-promptit — pieniä Python-tehtäviä
let code_prompts = vec![
"Write a Python function that checks if a number is prime.",
"Write a Python function that reverses a string without using slicing.",
"Write a Python function to find the factorial of a number using recursion.",
"Write a Python function that returns the Fibonacci sequence up to n numbers.",
"Write a Python function to check if a string is a palindrome.",
"Write a Python function that sorts a list using bubble sort.",
"Write a Python function to count the occurrences of each character in a string.",
"Write a Python function that flattens a nested list.",
"Write a Python function to find the greatest common divisor of two numbers.",
"Write a Python function that converts Celsius to Fahrenheit.",
];
let code_idx = (rng_state as usize / 13) % code_prompts.len();
let coder_msg = serde_json::json!({
"type": "llm_prompt",
"prompt": code_prompts[code_idx],
"model": "qwen-coder",
});
let _ = state_for_task.stats_tx.send(coder_msg.to_string());
tracing::debug!("Tehtävät lähetetty: pair + smollm + qwen + phi3 + coder");
}
});
@@ -678,6 +699,36 @@ async fn handle_socket(socket: WebSocket, state: Arc<AppState>, ip: IpAddr) {
}
broadcast_stats(&state).await;
}
} else if msg_type == "user_text" {
// Käyttäjän lähettämä teksti — broadcastataan pair_taskina ja llm_promptina
let text = json.get("text").and_then(|v| v.as_str()).unwrap_or("").to_string();
let task_type = json.get("task_type").and_then(|v| v.as_str()).unwrap_or("tokenize");
if !text.is_empty() {
tracing::info!("Solmu {} lähetti oman tekstin ({}): \"{}\"", node_id, task_type, &text[..text.len().min(80)]);
match task_type {
"tokenize" => {
// Tokenisoidaan käyttäjän teksti EN-puolella, FI jätetään tyhjäksi
let pair = serde_json::json!({
"type": "pair_task",
"en": text,
"fi": text,
"user_submitted": true,
});
let _ = state.stats_tx.send(pair.to_string());
}
_ => {
// LLM-prompti
for model in &["smollm-135m", "qwen-05b", "phi3-mini", "qwen-coder"] {
let prompt = serde_json::json!({
"type": "llm_prompt",
"prompt": text,
"model": model,
});
let _ = state.stats_tx.send(prompt.to_string());
}
}
}
}
}
}