Make endpoint url for Ollama configurable (#355)

This commit is contained in:
senovr
2024-07-02 20:59:55 +03:00
committed by GitHub
parent fef25a2d06
commit 18f52772b3
5 changed files with 89 additions and 4 deletions
+10 -1
View File
@@ -27,7 +27,8 @@ export enum CONFIG_KEYS {
OCO_AI_PROVIDER = 'OCO_AI_PROVIDER',
OCO_GITPUSH = 'OCO_GITPUSH',
OCO_ONE_LINE_COMMIT = 'OCO_ONE_LINE_COMMIT',
OCO_AZURE_ENDPOINT = 'OCO_AZURE_ENDPOINT'
OCO_AZURE_ENDPOINT = 'OCO_AZURE_ENDPOINT',
OCO_OLLAMA_API_URL = 'OCO_API_URL',
}
export enum CONFIG_MODES {
@@ -270,6 +271,14 @@ export const configValidators = {
return value;
},
[CONFIG_KEYS.OCO_OLLAMA_API_URL](value: any) { // add simple api validator
validateConfig(
CONFIG_KEYS.OCO_API_URL,
typeof value === 'string' && value.startsWith('http'),
`${value} is not a valid URL`
);
return value;
},
};
export type ConfigType = {
+6 -1
View File
@@ -10,10 +10,15 @@ const config = getConfig();
export class OllamaAi implements AiEngine {
private model = "mistral"; // as default model of Ollama
private url = "http://localhost:11434/api/chat"; // default URL of Ollama API
setModel(model: string) {
this.model = model ?? config?.OCO_MODEL ?? 'mistral';
}
setUrl(url: string) {
this.url = url ?? config?.OCO_OLLAMA_API_URL ?? 'http://localhost:11434/api/chat';
}
async generateCommitMessage(
messages: Array<ChatCompletionRequestMessage>
): Promise<string | undefined> {
@@ -22,7 +27,7 @@ export class OllamaAi implements AiEngine {
//console.log(messages);
//process.exit()
const url = 'http://localhost:11434/api/chat';
const url = this.url;
const p = {
model,
messages,