refactor: LLM Typen und Traits nach nazarick-core verschoben, BaseAgent extrahiert

This commit is contained in:
Sithies
2026-03-16 22:06:30 +01:00
parent df29fdfa60
commit 30d63debd9
11 changed files with 127 additions and 66 deletions
+10
View File
@@ -0,0 +1,10 @@
// nazarick-core/src/llm/mod.rs
//
// LLM-Modul — Typen und Traits für alle LLM-Provider.
// Re-exportiert alles damit Nutzer nur `nazarick_core::llm::X` schreiben müssen.
mod types;
mod traits;
pub use types::{Message, LlmRequest, LlmResponse};
pub use traits::LlmProvider;
+19
View File
@@ -0,0 +1,19 @@
// nazarick-core/src/llm/traits.rs
//
// LlmProvider Trait — gemeinsame Schnittstelle für alle LLM-Backends.
// Neue Provider (Ollama, Mistral) implementieren diesen Trait.
use crate::types::Result;
use crate::llm::types::{LlmRequest, LlmResponse};
/// Zentraler Trait für alle LLM-Provider.
/// Jeder Provider (LmStudio, Ollama, Mistral) implementiert diesen Trait.
#[async_trait::async_trait]
pub trait LlmProvider: Send + Sync {
/// Sendet eine Anfrage an das LLM und gibt die Antwort zurück.
async fn complete(&self, request: LlmRequest) -> Result<LlmResponse>;
/// Gibt den Namen des Providers zurück.
/// Wird für Logging und Usage-Tracking verwendet.
fn name(&self) -> &str;
}
+53
View File
@@ -0,0 +1,53 @@
// nazarick-core/src/llm/types.rs
//
// Gemeinsame Datentypen für alle LLM-Provider.
// Jeder Provider (LmStudio, Ollama, Mistral) nutzt diese Typen.
/// Repräsentiert eine einzelne Nachricht in einem Gespräch.
/// Entspricht dem Message-Format das alle gängigen LLM APIs verwenden.
#[derive(Debug, Clone)]
pub struct Message {
/// Rolle des Absenders: "system", "user" oder "assistant"
pub role: String,
/// Inhalt der Nachricht
pub content: String,
}
impl Message {
/// Erstellt eine System-Nachricht (z.B. den Persönlichkeits-Prompt)
pub fn system(content: impl Into<String>) -> Self {
Self { role: "system".to_string(), content: content.into() }
}
/// Erstellt eine User-Nachricht
pub fn user(content: impl Into<String>) -> Self {
Self { role: "user".to_string(), content: content.into() }
}
/// Erstellt eine Assistant-Nachricht (vorherige Antworten für Kontext)
pub fn assistant(content: impl Into<String>) -> Self {
Self { role: "assistant".to_string(), content: content.into() }
}
}
/// Konfiguration für einen einzelnen LLM-Aufruf.
#[derive(Debug, Clone)]
pub struct LlmRequest {
/// Der vollständige Gesprächsverlauf inklusive System-Prompt
pub messages: Vec<Message>,
/// Maximale Anzahl Token in der Antwort
pub max_tokens: u32,
/// Kreativität der Antwort (0.0 = deterministisch, 1.0 = sehr kreativ)
pub temperature: f32,
}
/// Antwort eines LLM-Aufrufs.
#[derive(Debug, Clone)]
pub struct LlmResponse {
/// Der generierte Text
pub content: String,
/// Anzahl der Input-Token (für Usage-Tracking)
pub tokens_input: u64,
/// Anzahl der Output-Token (für Usage-Tracking)
pub tokens_output: u64,
}