Skip to content

Commit a9c9bcf

Browse files
authored
Merge pull request #547 from keith666666/fix/ollama-url-resolution
fix(engine): fix broken URL resolution in Ollama and MLX engines
2 parents 9923dab + 0ee82f7 commit a9c9bcf

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/engine/mlx.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import { AiEngine, AiEngineConfig } from './Engine';
66

77
interface MLXConfig extends AiEngineConfig {}
88

9+
const DEFAULT_MLX_URL = 'http://localhost:8080';
10+
const MLX_CHAT_PATH = '/v1/chat/completions';
11+
912
export 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;

src/engine/ollama.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ import { AiEngine, AiEngineConfig } from './Engine';
66

77
interface OllamaConfig extends AiEngineConfig {}
88

9+
const DEFAULT_OLLAMA_URL = 'http://localhost:11434';
10+
const OLLAMA_CHAT_PATH = '/api/chat';
11+
912
export 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;

0 commit comments

Comments
 (0)