Switch ollama api endpoint from /api/generate to /api/chat (#304)

* 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>
This commit is contained in:
digitalstudium
2024-03-08 05:08:52 +03:00
committed by GitHub
parent 744bb9b11d
commit a192441f68
6 changed files with 25 additions and 25 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ You can also run it with local model through ollama:
```sh ```sh
git add <files...> git add <files...>
AI_PROVIDER='ollama' opencommit OCO_AI_PROVIDER='ollama' opencommit
``` ```
### Flags ### Flags
+7 -8
View File
@@ -16384,7 +16384,7 @@ function G3(t, e2) {
// package.json // package.json
var package_default = { var package_default = {
name: "opencommit", name: "opencommit",
version: "3.0.10", version: "3.0.11",
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}", description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
keywords: [ keywords: [
"git", "git",
@@ -21991,12 +21991,11 @@ var api = new OpenAi();
var OllamaAi = class { var OllamaAi = class {
async generateCommitMessage(messages) { async generateCommitMessage(messages) {
const model = "mistral"; const model = "mistral";
let prompt = messages.map((x4) => x4.content).join("\n"); const url3 = "http://localhost:11434/api/chat";
prompt += "Summarize above git diff in 10 words or less";
const url3 = "http://localhost:11434/api/generate";
const p4 = { const p4 = {
model, model,
prompt, messages,
options: { temperature: 0, top_p: 0.1 },
stream: false stream: false
}; };
try { try {
@@ -22005,8 +22004,8 @@ var OllamaAi = class {
"Content-Type": "application/json" "Content-Type": "application/json"
} }
}); });
const answer = response.data?.response; const message = response.data.message;
return answer; return message?.content;
} catch (err) { } catch (err) {
const message = err.response?.data?.error ?? err.message; const message = err.response?.data?.error ?? err.message;
throw new Error("local model issues. details: " + message); throw new Error("local model issues. details: " + message);
@@ -22661,7 +22660,7 @@ var hookCommand = G3(
return ce(`${source_default.green("\u2714")} Hook is removed`); return ce(`${source_default.green("\u2714")} Hook is removed`);
} }
throw new Error( throw new Error(
`Unsupported mode: ${mode2}. Supported modes are: 'set' or 'unset'` `Unsupported mode: ${mode2}. Supported modes are: 'set' or 'unset', do: \`oco hook set\``
); );
} catch (error) { } catch (error) {
ce(`${source_default.red("\u2716")} ${error}`); ce(`${source_default.red("\u2716")} ${error}`);
+5 -6
View File
@@ -27486,12 +27486,11 @@ var api = new OpenAi();
var OllamaAi = class { var OllamaAi = class {
async generateCommitMessage(messages) { async generateCommitMessage(messages) {
const model = "mistral"; const model = "mistral";
let prompt = messages.map((x2) => x2.content).join("\n"); const url2 = "http://localhost:11434/api/chat";
prompt += "Summarize above git diff in 10 words or less";
const url2 = "http://localhost:11434/api/generate";
const p2 = { const p2 = {
model, model,
prompt, messages,
options: { temperature: 0, top_p: 0.1 },
stream: false stream: false
}; };
try { try {
@@ -27500,8 +27499,8 @@ var OllamaAi = class {
"Content-Type": "application/json" "Content-Type": "application/json"
} }
}); });
const answer = response.data?.response; const message = response.data.message;
return answer; return message?.content;
} catch (err) { } catch (err) {
const message = err.response?.data?.error ?? err.message; const message = err.response?.data?.error ?? err.message;
throw new Error("local model issues. details: " + message); throw new Error("local model issues. details: " + message);
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "opencommit", "name": "opencommit",
"version": "3.0.10", "version": "3.0.11",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "opencommit", "name": "opencommit",
"version": "3.0.10", "version": "3.0.11",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "opencommit", "name": "opencommit",
"version": "3.0.10", "version": "3.0.11",
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫", "description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [ "keywords": [
"git", "git",
+9 -7
View File
@@ -8,14 +8,14 @@ export class OllamaAi implements AiEngine {
): Promise<string | undefined> { ): Promise<string | undefined> {
const model = 'mistral'; // todo: allow other models const model = 'mistral'; // todo: allow other models
let prompt = messages.map((x) => x.content).join('\n'); //console.log(messages);
//hoftix: local models are not so clever so im changing the prompt a bit... //process.exit()
prompt += 'Summarize above git diff in 10 words or less';
const url = 'http://localhost:11434/api/generate'; const url = 'http://localhost:11434/api/chat';
const p = { const p = {
model, model,
prompt, messages,
options: {temperature: 0, top_p: 0.1},
stream: false stream: false
}; };
try { try {
@@ -24,8 +24,10 @@ export class OllamaAi implements AiEngine {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
const answer = response.data?.response;
return answer; const message = response.data.message;
return message?.content;
} catch (err: any) { } catch (err: any) {
const message = err.response?.data?.error ?? err.message; const message = err.response?.data?.error ?? err.message;
throw new Error('local model issues. details: ' + message); throw new Error('local model issues. details: ' + message);