mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
* 📝 (README.md): add support for custom AI models and update documentation to reflect new environment variable OCO_ AI_PROVIDER (#351) * feat/add gemini (#349) * fix: prompt-module/@commitlint (#336) * docs: spelling fix (#325) --------- Co-authored-by: tumf <y.takahara@gmail.com> Co-authored-by: Drew Payment <drew.payment@gmail.com> Co-authored-by: Takanori Matsumoto <matscube@gmail.com> Co-authored-by: Kellan Stevens <kellan@kellanstevens.com> Co-authored-by: JMN09 <jmn09@mail.aub.edu> Co-authored-by: JMN09 <157629053+JMN09@users.noreply.github.com>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import axios, { AxiosError } from 'axios';
|
|
import { ChatCompletionRequestMessage } from 'openai';
|
|
import { AiEngine } from './Engine';
|
|
|
|
import {
|
|
getConfig
|
|
} from '../commands/config';
|
|
|
|
const config = getConfig();
|
|
|
|
export class FlowiseAi implements AiEngine {
|
|
|
|
async generateCommitMessage(
|
|
messages: Array<ChatCompletionRequestMessage>
|
|
): Promise<string | undefined> {
|
|
|
|
const gitDiff = messages[ messages.length - 1 ]?.content?.replace(/\\/g, '\\\\')
|
|
.replace(/"/g, '\\"')
|
|
.replace(/\n/g, '\\n')
|
|
.replace(/\r/g, '\\r')
|
|
.replace(/\t/g, '\\t');
|
|
const url = `http://${config?.OCO_FLOWISE_ENDPOINT}/api/v1/prediction/${config?.OCO_FLOWISE_API_KEY}`;
|
|
const payload = {
|
|
question : gitDiff,
|
|
overrideConfig : {
|
|
systemMessagePrompt: messages[0]?.content,
|
|
},
|
|
history : messages.slice( 1, -1 )
|
|
}
|
|
try {
|
|
const response = await axios.post(url, payload, {
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
const message = response.data;
|
|
return message?.text;
|
|
} catch (err: any) {
|
|
const message = err.response?.data?.error ?? err.message;
|
|
throw new Error('local model issues. details: ' + message);
|
|
}
|
|
}
|
|
}
|