feat: OpenAI-kompatibler Modell-Client für strata
Backend in config.toml wählbar (ollama oder openai), Standard-URL für strata im LAN (192.168.12.4:8082). Nachrichten werden ins OpenAI-Format umgeschrieben, Tool-Antworten bekommen die passende tool_call_id. Test für die Umwandlung grün (42 Unit-Tests). Verbindung zu strata noch nicht möglich: alle drei Adressen lehnen ab. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
use crate::agent::{
|
||||
run_agent_cancellable, AgentLimits, ErrorClass, Message, ModelClient, ModelError,
|
||||
OllamaClient, SandboxWorkspace,
|
||||
OllamaClient, OpenAiClient, SandboxWorkspace,
|
||||
};
|
||||
use crate::sandbox::{container_name, remove_by_name, Limits, Sandbox};
|
||||
use crate::store::{RunRecord, Store};
|
||||
@ -33,6 +33,8 @@ pub struct Job {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RunConfig {
|
||||
pub runtime: String,
|
||||
/// `ollama` oder `openai`.
|
||||
pub backend: String,
|
||||
pub endpoint_url: String,
|
||||
pub data_dir: PathBuf,
|
||||
pub limits: Limits,
|
||||
@ -119,6 +121,7 @@ pub fn run_batch(
|
||||
) -> Result<BatchSummary, String> {
|
||||
let config_json = json!({
|
||||
"runtime": cfg.runtime,
|
||||
"backend": cfg.backend,
|
||||
"endpoint": cfg.endpoint_url,
|
||||
"limits": { "memory": cfg.limits.memory, "cpus": cfg.limits.cpus },
|
||||
"system_prompt": crate::agent::SYSTEM_PROMPT,
|
||||
@ -150,7 +153,7 @@ pub fn run_batch(
|
||||
}
|
||||
|
||||
'models: for model in &models {
|
||||
let client = OllamaClient::new(&cfg.endpoint_url, model)?;
|
||||
let client = make_client(cfg, model)?;
|
||||
let warm = client.chat(
|
||||
&[Message::new("user", "ping")],
|
||||
&json!([]),
|
||||
@ -211,7 +214,7 @@ pub fn run_batch(
|
||||
},
|
||||
transcript: vec![],
|
||||
},
|
||||
None => match execute_job(cfg, batch_id, i, job, &client, cancel)? {
|
||||
None => match execute_job(cfg, batch_id, i, job, &*client, cancel)? {
|
||||
JobResult::Cancelled => {
|
||||
summary.cancelled = true;
|
||||
break 'models;
|
||||
@ -250,12 +253,21 @@ enum JobResult {
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
/// Baut den Modell-Client für das gewählte Backend.
|
||||
pub fn make_client(cfg: &RunConfig, model: &str) -> Result<Box<dyn ModelClient>, String> {
|
||||
match cfg.backend.as_str() {
|
||||
"ollama" => Ok(Box::new(OllamaClient::new(&cfg.endpoint_url, model)?)),
|
||||
"openai" => Ok(Box::new(OpenAiClient::new(&cfg.endpoint_url, model)?)),
|
||||
other => Err(format!("Unbekanntes Backend: {other} (erlaubt: ollama, openai)")),
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_job(
|
||||
cfg: &RunConfig,
|
||||
batch_id: i64,
|
||||
seq: usize,
|
||||
job: &Job,
|
||||
client: &OllamaClient,
|
||||
client: &dyn ModelClient,
|
||||
cancel: &AtomicBool,
|
||||
) -> Result<JobResult, String> {
|
||||
let meta = &job.task.meta;
|
||||
@ -442,6 +454,7 @@ mod tests {
|
||||
let jobs = plan(&[model.clone()], &tasks, 2);
|
||||
let cfg = RunConfig {
|
||||
runtime: "podman".into(),
|
||||
backend: "ollama".into(),
|
||||
endpoint_url: url,
|
||||
data_dir: base.join("data"),
|
||||
limits: Limits::default(),
|
||||
@ -484,6 +497,7 @@ mod tests {
|
||||
let jobs = plan(&[model.clone()], &tasks, 1);
|
||||
let cfg = RunConfig {
|
||||
runtime: "podman".into(),
|
||||
backend: "ollama".into(),
|
||||
endpoint_url: url,
|
||||
data_dir: data.clone(),
|
||||
limits: Limits::default(),
|
||||
|
||||
Reference in New Issue
Block a user