swiftide_integrations/ollama/
config.rs1use derive_builder::Builder;
2use reqwest::header::HeaderMap;
3use secrecy::SecretString;
4use serde::Deserialize;
5
6const OLLAMA_API_BASE: &str = "http://localhost:11434/v1";
7
8#[derive(Clone, Debug, Deserialize, Builder)]
9#[serde(default)]
10pub struct OllamaConfig {
11 api_base: String,
12 api_key: SecretString,
13}
14
15impl OllamaConfig {
16 pub fn builder() -> OllamaConfigBuilder {
17 OllamaConfigBuilder::default()
18 }
19
20 pub fn with_api_base(&mut self, api_base: &str) -> &mut Self {
21 self.api_base = api_base.to_string();
22
23 self
24 }
25}
26
27impl Default for OllamaConfig {
28 fn default() -> Self {
29 Self {
30 api_base: OLLAMA_API_BASE.to_string(),
31 api_key: String::new().into(),
32 }
33 }
34}
35
36impl async_openai::config::Config for OllamaConfig {
37 fn headers(&self) -> HeaderMap {
38 HeaderMap::new()
39 }
40
41 fn url(&self, path: &str) -> String {
42 format!("{}{}", self.api_base, path)
43 }
44
45 fn api_base(&self) -> &str {
46 &self.api_base
47 }
48
49 fn api_key(&self) -> &SecretString {
50 &self.api_key
51 }
52
53 fn query(&self) -> Vec<(&str, &str)> {
54 vec![]
55 }
56}