a192441f68
* 3.0.11 * build * docs: update ollama usage readme (#301) Signed-off-by: Albert Simon <albert.simon.sge@mango.com> Co-authored-by: Albert Simon <albert.simon.sge@mango.com> * 🚨 BREAKING CHANGES 🚨 - feat(engine/ollama): add support for local models and change prompt format to improve AI performance + fix(engine/ollama): fix issue with local model not responding correctly to requests The commit message is now more concise, clear, and informative. It also includes a breaking changes section that highlights the significant changes made in this commit. --------- Signed-off-by: Albert Simon <albert.simon.sge@mango.com> Co-authored-by: di-sukharev <dim.sukharev@gmail.com> Co-authored-by: Albert Simon <47634918+willyw0nka@users.noreply.github.com> Co-authored-by: Albert Simon <albert.simon.sge@mango.com> Co-authored-by: Константин Шуткин <shutkin-kn@mosmetro.ru>
39 lines
1003 B
TypeScript
39 lines
1003 B
TypeScript
import axios, { AxiosError } from 'axios';
|
|
import { ChatCompletionRequestMessage } from 'openai';
|
|
import { AiEngine } from './Engine';
|
|
|
|
export class OllamaAi implements AiEngine {
|
|
async generateCommitMessage(
|
|
messages: Array<ChatCompletionRequestMessage>
|
|
): Promise<string | undefined> {
|
|
const model = 'mistral'; // todo: allow other models
|
|
|
|
//console.log(messages);
|
|
//process.exit()
|
|
|
|
const url = 'http://localhost:11434/api/chat';
|
|
const p = {
|
|
model,
|
|
messages,
|
|
options: {temperature: 0, top_p: 0.1},
|
|
stream: false
|
|
};
|
|
try {
|
|
const response = await axios.post(url, p, {
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
const message = response.data.message;
|
|
|
|
return message?.content;
|
|
} catch (err: any) {
|
|
const message = err.response?.data?.error ?? err.message;
|
|
throw new Error('local model issues. details: ' + message);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const ollamaAi = new OllamaAi();
|