refactor: rename ollama config field api_key => api_auth (#453)

pull/454/head
sigoden 1 month ago committed by GitHub
parent 338b0438dc
commit 7bda1eace2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

@ -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)

Loading…
Cancel
Save