summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-28 13:54:51 +0800
committerGitHub <noreply@github.com>2024-04-28 13:54:51 +0800
commit7bda1eace29dde7c1c7ce5e8ab4bc911cfb90c3f (patch)
tree7127d1fe88282c79650fdd6e9c90c05f50e3dc37
parent338b0438dc34280f31cd7642a3da4f565490c749 (diff)
downloadaichat-7bda1eace29dde7c1c7ce5e8ab4bc911cfb90c3f.tar.gz
refactor: rename ollama config field api_key => api_auth (#453)
-rw-r--r--config.example.yaml4
-rw-r--r--src/client/ollama.rs12
2 files changed, 8 insertions, 8 deletions
diff --git a/config.example.yaml b/config.example.yaml
index a0c6da8..e0a4689 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -78,7 +78,7 @@ clients:
name: localai
api_base: http://localhost:8080/v1
api_key: sk-xxx # ENV: {client_name}_API_BASE
- chat_endpoint: /chat/completions
+ chat_endpoint: /chat/completions # Optional
models:
- name: llama3
max_input_tokens: 8192
@@ -86,7 +86,7 @@ clients:
# See https://github.com/jmorganca/ollama
- type: ollama
api_base: http://localhost:11434
- api_key: Basic xxx # Set authorization header, ENV: {client_name}_API_BASE
+ api_auth: Basic xxx # ENV: {client_name}_API_AUTH
chat_endpoint: /api/chat # Optional
models:
- name: llama3
diff --git a/src/client/ollama.rs b/src/client/ollama.rs
index e869e87..5ec50a1 100644
--- a/src/client/ollama.rs
+++ b/src/client/ollama.rs
@@ -15,18 +15,18 @@ use serde_json::{json, Value};
pub struct OllamaConfig {
pub name: Option<String>,
pub api_base: String,
- pub api_key: Option<String>,
+ pub api_auth: Option<String>,
pub chat_endpoint: Option<String>,
pub models: Vec<ModelConfig>,
pub extra: Option<ExtraConfig>,
}
impl OllamaClient {
- config_get_fn!(api_key, get_api_key);
+ config_get_fn!(api_auth, get_api_auth);
pub const PROMPTS: [PromptType<'static>; 4] = [
("api_base", "API Base:", true, PromptKind::String),
- ("api_key", "API Key:", false, PromptKind::String),
+ ("api_auth", "API Key:", false, PromptKind::String),
("models[].name", "Model Name:", true, PromptKind::String),
(
"models[].max_input_tokens",
@@ -37,7 +37,7 @@ impl OllamaClient {
];
fn request_builder(&self, client: &ReqwestClient, data: SendData) -> Result<RequestBuilder> {
- let api_key = self.get_api_key().ok();
+ let api_auth = self.get_api_auth().ok();
let mut body = build_body(data, &self.model)?;
self.model.merge_extra_fields(&mut body);
@@ -49,8 +49,8 @@ impl OllamaClient {
debug!("Ollama Request: {url} {body}");
let mut builder = client.post(url).json(&body);
- if let Some(api_key) = api_key {
- builder = builder.header("Authorization", api_key)
+ if let Some(api_auth) = api_auth {
+ builder = builder.header("Authorization", api_auth)
}
Ok(builder)