split_brain_harness/backends/
ollama.rs1use super::InferenceEngine;
2use async_trait::async_trait;
3use reqwest::Client;
4use serde_json::json;
5
6pub struct OllamaNativeEngine {
7 pub endpoint: String,
8 pub model: String,
9 pub client: Client,
10}
11
12#[async_trait]
13impl InferenceEngine for OllamaNativeEngine {
14 async fn generate(&self, system_prompt: &str, prompt_payload: &str) -> Result<String, String> {
15 let body = json!({
16 "model": self.model,
17 "messages": [
18 { "role": "system", "content": system_prompt },
19 { "role": "user", "content": prompt_payload }
20 ],
21 "think": false,
22 "stream": false,
23 "options": { "temperature": 0.1, "num_predict": 600 }
24 });
25
26 let resp = self
27 .client
28 .post(format!("{}/api/chat", self.endpoint.trim_end_matches('/')))
29 .json(&body)
30 .send()
31 .await
32 .map_err(|e| e.to_string())?;
33
34 let json: serde_json::Value = resp.json().await.map_err(|e| e.to_string())?;
35
36 json["message"]["content"]
37 .as_str()
38 .map(|s| s.to_string())
39 .ok_or_else(|| "missing content field in Ollama response".into())
40 }
41}