-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathollama.js
63 lines (53 loc) · 2.6 KB
/
ollama.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const ollama = {
/**
* send prompt to ai.
*/
sendMessage: async (input, { apiKey, model = 'mistral' }) => {
const url = "http://127.0.0.1:11434/api/chat";
const messages = [{ role: "user", content: input }];
const data = { model, stream: false, messages };
console.log(`Prompting Ollama with model: ${model}...`);
try {
// Initial request
const initialResponse = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
const initialResult = await initialResponse.json();
console.log("Initial answer from Ollama:", initialResult);
const answer = initialResult.message;
console.log("Response from Ollama:", answer.content);
return answer.content;
} catch (err) {
console.error("Error during AI processing:", err.message);
throw new Error(`Local model issues. Details: ${err.message}`);
}
},
getPromptForSingleCommit: (diff, { commitType, customMessageConvention, language }) => {
return (
`Write a professional git commit message based on the a diff below in ${language} language` +
(commitType ? ` with commit type '${commitType}'. ` : ". ") +
"Do not preface the commit with anything, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>)" +
`${customMessageConvention ? `. Additionally apply these JSON formatted rules to your response, even though they might be against previous mentioned rules ${customMessageConvention}: ` : ': '}` +
'\n\n' +
diff
);
},
getPromptForMultipleCommits: (
diff,
{ commitType, customMessageConvention, numOptions, language }
) => {
const prompt = `Please write a professional commit message for me to push to github based on this git diff: ${diff}. Message should be in ${language} language ` +
(commitType ? ` with commit type '${commitType}.', ` : ", ") +
`and make ${numOptions} options that are separated by ";".` +
"For each option, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>)" +
`${customMessageConvention ? `. Additionally apply these JSON formatted rules to your response, even though they might be against previous mentioned rules ${customMessageConvention}: ` : ': '}`
return prompt;
},
filterApi: ({ prompt, numCompletion = 1, filterFee }) => {
//ollama dont have any limits and is free so we dont need to filter anything
return true;
}
};
export default ollama;