File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed
Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,21 @@ import { AiEngine, AiEngineConfig } from './Engine';
66
77interface MLXConfig extends AiEngineConfig { }
88
9+ const DEFAULT_MLX_URL = 'http://localhost:8080' ;
10+ const MLX_CHAT_PATH = '/v1/chat/completions' ;
11+
912export class MLXEngine implements AiEngine {
1013 config : MLXConfig ;
1114 client : AxiosInstance ;
15+ private chatUrl : string ;
1216
1317 constructor ( config ) {
1418 this . config = config ;
19+
20+ const baseUrl = config . baseURL || DEFAULT_MLX_URL ;
21+ this . chatUrl = `${ baseUrl } ${ MLX_CHAT_PATH } ` ;
22+
1523 this . client = axios . create ( {
16- url : config . baseURL
17- ? `${ config . baseURL } /${ config . apiKey } `
18- : 'http://localhost:8080/v1/chat/completions' ,
1924 headers : { 'Content-Type' : 'application/json' }
2025 } ) ;
2126 }
@@ -31,10 +36,7 @@ export class MLXEngine implements AiEngine {
3136 stream : false
3237 } ;
3338 try {
34- const response = await this . client . post (
35- this . client . getUri ( this . config ) ,
36- params
37- ) ;
39+ const response = await this . client . post ( this . chatUrl , params ) ;
3840
3941 const choices = response . data . choices ;
4042 const message = choices [ 0 ] . message ;
Original file line number Diff line number Diff line change @@ -6,25 +6,27 @@ import { AiEngine, AiEngineConfig } from './Engine';
66
77interface OllamaConfig extends AiEngineConfig { }
88
9+ const DEFAULT_OLLAMA_URL = 'http://localhost:11434' ;
10+ const OLLAMA_CHAT_PATH = '/api/chat' ;
11+
912export class OllamaEngine implements AiEngine {
1013 config : OllamaConfig ;
1114 client : AxiosInstance ;
15+ private chatUrl : string ;
1216
1317 constructor ( config ) {
1418 this . config = config ;
1519
20+ const baseUrl = config . baseURL || DEFAULT_OLLAMA_URL ;
21+ this . chatUrl = `${ baseUrl } ${ OLLAMA_CHAT_PATH } ` ;
22+
1623 // Combine base headers with custom headers
1724 const headers = {
1825 'Content-Type' : 'application/json' ,
1926 ...config . customHeaders
2027 } ;
2128
22- this . client = axios . create ( {
23- url : config . baseURL
24- ? `${ config . baseURL } /${ config . apiKey } `
25- : 'http://localhost:11434/api/chat' ,
26- headers
27- } ) ;
29+ this . client = axios . create ( { headers } ) ;
2830 }
2931
3032 async generateCommitMessage (
@@ -37,10 +39,7 @@ export class OllamaEngine implements AiEngine {
3739 stream : false
3840 } ;
3941 try {
40- const response = await this . client . post (
41- this . client . getUri ( this . config ) ,
42- params
43- ) ;
42+ const response = await this . client . post ( this . chatUrl , params ) ;
4443
4544 const { message } = response . data ;
4645 let content = message ?. content ;
You can’t perform that action at this time.
0 commit comments