improve OCO_AI_PROVIDER=ollama[/model name] (#327)
* 🐛 (config.ts, engine/ollama.ts, utils/engine.ts): improve Ollama AI configuration and usage ✨ (config.ts): add support for multiple Ollama models and allow users to specify the model in their config ✅ (engine/ollama.ts, utils/engine.ts): refactor code to use the specified Ollama model instead of hardcoding it * add build results
This commit is contained in:
+2141
-15274
File diff suppressed because one or more lines are too long
+2145
-28599
File diff suppressed because one or more lines are too long
@@ -82,7 +82,7 @@ export const configValidators = {
|
|||||||
//need api key unless running locally with ollama
|
//need api key unless running locally with ollama
|
||||||
validateConfig(
|
validateConfig(
|
||||||
'OpenAI API_KEY',
|
'OpenAI API_KEY',
|
||||||
value || config.OCO_ANTHROPIC_API_KEY || config.OCO_AI_PROVIDER == 'ollama' || config.OCO_AI_PROVIDER == 'test',
|
value || config.OCO_ANTHROPIC_API_KEY || config.OCO_AI_PROVIDER.startsWith('ollama') || config.OCO_AI_PROVIDER == 'test',
|
||||||
'You need to provide an OpenAI/Anthropic API key'
|
'You need to provide an OpenAI/Anthropic API key'
|
||||||
);
|
);
|
||||||
validateConfig(
|
validateConfig(
|
||||||
@@ -223,10 +223,9 @@ export const configValidators = {
|
|||||||
'',
|
'',
|
||||||
'openai',
|
'openai',
|
||||||
'anthropic',
|
'anthropic',
|
||||||
'ollama',
|
|
||||||
'test'
|
'test'
|
||||||
].includes(value),
|
].includes(value) || value.startsWith('ollama'),
|
||||||
`${value} is not supported yet, use 'ollama' 'anthropic' or 'openai' (default)`
|
`${value} is not supported yet, use 'ollama/{model}' 'anthropic' or 'openai' (default)`
|
||||||
);
|
);
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ import { ChatCompletionRequestMessage } from 'openai';
|
|||||||
import { AiEngine } from './Engine';
|
import { AiEngine } from './Engine';
|
||||||
|
|
||||||
export class OllamaAi implements AiEngine {
|
export class OllamaAi implements AiEngine {
|
||||||
|
private model = "mistral"; // as default model of Ollama
|
||||||
|
|
||||||
|
setModel(model: string) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
async generateCommitMessage(
|
async generateCommitMessage(
|
||||||
messages: Array<ChatCompletionRequestMessage>
|
messages: Array<ChatCompletionRequestMessage>
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
const model = 'mistral'; // todo: allow other models
|
const model = this.model;
|
||||||
|
|
||||||
//console.log(messages);
|
//console.log(messages);
|
||||||
//process.exit()
|
//process.exit()
|
||||||
|
|||||||
+7
-2
@@ -7,13 +7,18 @@ import { testAi } from '../engine/testAi';
|
|||||||
|
|
||||||
export function getEngine(): AiEngine {
|
export function getEngine(): AiEngine {
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
if (config?.OCO_AI_PROVIDER == 'ollama') {
|
const provider = config?.OCO_AI_PROVIDER;
|
||||||
|
if (provider?.startsWith('ollama')) {
|
||||||
|
const model = provider.split('/')[1];
|
||||||
|
if (model) {
|
||||||
|
ollamaAi.setModel(model);
|
||||||
|
}
|
||||||
return ollamaAi;
|
return ollamaAi;
|
||||||
} else if (config?.OCO_AI_PROVIDER == 'anthropic') {
|
} else if (config?.OCO_AI_PROVIDER == 'anthropic') {
|
||||||
return anthropicAi;
|
return anthropicAi;
|
||||||
} else if (config?.OCO_AI_PROVIDER == 'test') {
|
} else if (config?.OCO_AI_PROVIDER == 'test') {
|
||||||
return testAi;
|
return testAi;
|
||||||
}
|
}
|
||||||
//open ai gpt by default
|
// open ai gpt by default
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user