refactor: LLM Typen und Traits nach nazarick-core verschoben, BaseAgent extrahiert
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/// Abstraktionsschicht für alle LLM-Provider.
|
||||
/// Neue Provider (Ollama, Mistral) werden hier als weitere Submodule ergänzt.
|
||||
pub mod provider;
|
||||
pub mod lmstudio;
|
||||
|
||||
// Re-export der wichtigsten Typen damit Nutzer nur `api::llm::X` schreiben müssen
|
||||
pub use provider::{LlmProvider, LlmRequest, LlmResponse, Message};
|
||||
// Re-export aus nazarick-core damit bestehende Importe `api::llm::X` weiter funktionieren
|
||||
pub use nazarick_core::llm::{LlmProvider, LlmRequest, LlmResponse, Message};
|
||||
@@ -3,7 +3,7 @@ use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use nazarick_core::types::Result;
|
||||
use nazarick_core::error::NazarickError;
|
||||
use crate::llm::provider::{LlmProvider, LlmRequest, LlmResponse, Message};
|
||||
use nazarick_core::llm::{LlmProvider, LlmRequest, LlmResponse, Message};
|
||||
|
||||
/// LM Studio Provider — für lokale Entwicklung auf dem Entwicklungsrechner.
|
||||
/// LM Studio emuliert die OpenAI Chat Completions API, daher nutzen
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
use nazarick_core::types::Result;
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// Zentraler Trait für alle LLM-Provider.
|
||||
#[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;
|
||||
}
|
||||
Reference in New Issue
Block a user