Skip to content

Commit 9a0f412

Browse files
authored
fix(config.ts): add optional config parameter to [CONFIG_KEYS.OCO_ MODEL] validator to allow for dynamic model selection based on configuration (#337)
feat(engine/ollama.ts): integrate with config command to load OCO_MODEL from configuration and use it as the default AI engine model
1 parent 7cd3ef0 commit 9a0f412

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/commands/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ export const configValidators = {
180180
return value;
181181
},
182182

183-
[CONFIG_KEYS.OCO_MODEL](value: any) {
183+
[CONFIG_KEYS.OCO_MODEL](value: any, config: any = {}) {
184184
validateConfig(
185185
CONFIG_KEYS.OCO_MODEL,
186-
[...MODEL_LIST.openai, ...MODEL_LIST.anthropic].includes(value),
186+
[...MODEL_LIST.openai, ...MODEL_LIST.anthropic].includes(value) || config.OCO_AI_PROVIDER == 'ollama' || config.OCO_AI_PROVIDER == 'test',
187187
`${value} is not supported yet, use 'gpt-4', 'gpt-4-turbo', 'gpt-3.5-turbo' (default), 'gpt-3.5-turbo-0125', 'gpt-4-1106-preview', 'gpt-4-turbo-preview', 'gpt-4-0125-preview', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229' or 'claude-3-haiku-20240307'`
188188
);
189189
return value;

src/engine/ollama.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import axios, { AxiosError } from 'axios';
22
import { ChatCompletionRequestMessage } from 'openai';
33
import { AiEngine } from './Engine';
44

5+
import {
6+
getConfig
7+
} from '../commands/config';
8+
9+
const config = getConfig();
10+
511
export class OllamaAi implements AiEngine {
612
async generateCommitMessage(
713
messages: Array<ChatCompletionRequestMessage>
814
): Promise<string | undefined> {
9-
const model = 'mistral'; // todo: allow other models
15+
const model = config?.OCO_MODEL || 'mistral';
1016

1117
//console.log(messages);
1218
//process.exit()

0 commit comments

Comments
 (0)