Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/engine/mlx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
});
}
Expand All @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions src/engine/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down
Loading