diff --git a/src/engine/mlx.ts b/src/engine/mlx.ts index 7068bb43..cb131864 100644 --- a/src/engine/mlx.ts +++ b/src/engine/mlx.ts @@ -6,16 +6,21 @@ import { AiEngine, AiEngineConfig } from './Engine'; interface MLXConfig extends AiEngineConfig {} +const DEFAULT_MLX_URL = 'http://localhost:8080'; +const MLX_CHAT_PATH = '/v1/chat/completions'; + export class MLXEngine implements AiEngine { config: MLXConfig; client: AxiosInstance; + private chatUrl: string; constructor(config) { this.config = config; + + const baseUrl = config.baseURL || DEFAULT_MLX_URL; + this.chatUrl = `${baseUrl}${MLX_CHAT_PATH}`; + this.client = axios.create({ - url: config.baseURL - ? `${config.baseURL}/${config.apiKey}` - : 'http://localhost:8080/v1/chat/completions', headers: { 'Content-Type': 'application/json' } }); } @@ -31,10 +36,7 @@ export class MLXEngine implements AiEngine { stream: false }; try { - const response = await this.client.post( - this.client.getUri(this.config), - params - ); + const response = await this.client.post(this.chatUrl, params); const choices = response.data.choices; const message = choices[0].message; diff --git a/src/engine/ollama.ts b/src/engine/ollama.ts index 1b530737..621bfcc3 100644 --- a/src/engine/ollama.ts +++ b/src/engine/ollama.ts @@ -6,25 +6,27 @@ import { AiEngine, AiEngineConfig } from './Engine'; interface OllamaConfig extends AiEngineConfig {} +const DEFAULT_OLLAMA_URL = 'http://localhost:11434'; +const OLLAMA_CHAT_PATH = '/api/chat'; + export class OllamaEngine implements AiEngine { config: OllamaConfig; client: AxiosInstance; + private chatUrl: string; constructor(config) { this.config = config; + const baseUrl = config.baseURL || DEFAULT_OLLAMA_URL; + this.chatUrl = `${baseUrl}${OLLAMA_CHAT_PATH}`; + // Combine base headers with custom headers const headers = { 'Content-Type': 'application/json', ...config.customHeaders }; - this.client = axios.create({ - url: config.baseURL - ? `${config.baseURL}/${config.apiKey}` - : 'http://localhost:11434/api/chat', - headers - }); + this.client = axios.create({ headers }); } async generateCommitMessage( @@ -37,10 +39,7 @@ export class OllamaEngine implements AiEngine { stream: false }; try { - const response = await this.client.post( - this.client.getUri(this.config), - params - ); + const response = await this.client.post(this.chatUrl, params); const { message } = response.data; let content = message?.content;