mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-12 23:28:16 -05:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8d5c53db1 | ||
|
|
fc4326233d | ||
|
|
07f7a05c4b | ||
|
|
9b2e41d255 | ||
|
|
6fad862aa5 | ||
|
|
c425878f21 | ||
|
|
1fb592afb2 | ||
|
|
684f3dadfc | ||
|
|
76e6070012 | ||
|
|
cb72837866 | ||
|
|
2432ef9de3 | ||
|
|
026fd1822a | ||
|
|
b42a52ef24 | ||
|
|
10b031ab36 | ||
|
|
d63b825ae5 | ||
|
|
b66da48106 | ||
|
|
6f24afc600 | ||
|
|
a80dcb03c4 | ||
|
|
bebbed856f | ||
|
|
2d5882c257 | ||
|
|
37fb140563 |
838
out/cli.cjs
838
out/cli.cjs
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "3.0.17",
|
||||
"version": "3.0.18",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opencommit",
|
||||
"version": "3.0.17",
|
||||
"version": "3.0.18",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "3.0.17",
|
||||
"version": "3.0.18",
|
||||
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
||||
"keywords": [
|
||||
"git",
|
||||
@@ -46,7 +46,8 @@
|
||||
"dev:gemini": "OCO_AI_PROVIDER='gemini' ts-node ./src/cli.ts",
|
||||
"build": "rimraf out && node esbuild.config.js",
|
||||
"build:push": "npm run build && git add . && git commit -m 'build' && git push",
|
||||
"deploy": "npm version patch && npm run build:push && git push --tags && npm publish --tag latest",
|
||||
"deploy": "npm run build:push && git push --tags && npm publish --tag latest",
|
||||
"deploy:patch": "npm version patch && npm run deploy",
|
||||
"lint": "eslint src --ext ts && tsc --noEmit",
|
||||
"format": "prettier --write src",
|
||||
"test": "node --no-warnings --experimental-vm-modules $( [ -f ./node_modules/.bin/jest ] && echo ./node_modules/.bin/jest || which jest ) test/unit",
|
||||
@@ -97,5 +98,8 @@
|
||||
"ini": "^3.0.1",
|
||||
"inquirer": "^9.1.4",
|
||||
"openai": "^3.2.1"
|
||||
},
|
||||
"overrides": {
|
||||
"whatwg-url": "13.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ export enum CONFIG_KEYS {
|
||||
OCO_AZURE_ENDPOINT = 'OCO_AZURE_ENDPOINT',
|
||||
OCO_TEST_MOCK_TYPE = 'OCO_TEST_MOCK_TYPE',
|
||||
OCO_API_URL = 'OCO_API_URL',
|
||||
OCO_OLLAMA_API_URL = 'OCO_OLLAMA_API_URL'
|
||||
OCO_OLLAMA_API_URL = 'OCO_OLLAMA_API_URL',
|
||||
OCO_FLOWISE_ENDPOINT = 'OCO_FLOWISE_ENDPOINT',
|
||||
OCO_FLOWISE_API_KEY = 'OCO_FLOWISE_API_KEY'
|
||||
}
|
||||
|
||||
export enum CONFIG_MODES {
|
||||
@@ -72,9 +74,10 @@ export const MODEL_LIST = {
|
||||
],
|
||||
|
||||
anthropic: [
|
||||
'claude-3-haiku-20240307',
|
||||
'claude-3-5-sonnet-20240620',
|
||||
'claude-3-opus-20240229',
|
||||
'claude-3-sonnet-20240229',
|
||||
'claude-3-opus-20240229'
|
||||
'claude-3-haiku-20240307'
|
||||
],
|
||||
|
||||
gemini: [
|
||||
@@ -129,7 +132,8 @@ export const configValidators = {
|
||||
config.OCO_ANTHROPIC_API_KEY ||
|
||||
config.OCO_AI_PROVIDER.startsWith('ollama') ||
|
||||
config.OCO_AZURE_API_KEY ||
|
||||
config.OCO_AI_PROVIDER == 'test',
|
||||
config.OCO_AI_PROVIDER == 'test' ||
|
||||
config.OCO_AI_PROVIDER == 'flowise',
|
||||
'You need to provide an OpenAI/Anthropic/Azure API key'
|
||||
);
|
||||
validateConfig(
|
||||
@@ -148,7 +152,8 @@ export const configValidators = {
|
||||
config.OCO_OPENAI_API_KEY ||
|
||||
config.OCO_AZURE_API_KEY ||
|
||||
config.OCO_AI_PROVIDER == 'ollama' ||
|
||||
config.OCO_AI_PROVIDER == 'test',
|
||||
config.OCO_AI_PROVIDER == 'test' ||
|
||||
config.OCO_AI_PROVIDER == 'flowise',
|
||||
'You need to provide an OpenAI/Anthropic/Azure API key'
|
||||
);
|
||||
|
||||
@@ -174,13 +179,24 @@ export const configValidators = {
|
||||
value ||
|
||||
config.OCO_OPENAI_API_KEY ||
|
||||
config.OCO_AI_PROVIDER == 'ollama' ||
|
||||
config.OCO_AI_PROVIDER == 'test',
|
||||
config.OCO_AI_PROVIDER == 'test' ||
|
||||
config.OCO_AI_PROVIDER == 'flowise',
|
||||
'You need to provide an OpenAI/Anthropic API key'
|
||||
);
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_FLOWISE_API_KEY](value: any, config: any = {}) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_FLOWISE_API_KEY,
|
||||
value || config.OCO_AI_PROVIDER != 'flowise',
|
||||
'You need to provide a flowise API key'
|
||||
);
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_DESCRIPTION](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_DESCRIPTION,
|
||||
@@ -267,7 +283,8 @@ export const configValidators = {
|
||||
].includes(value) ||
|
||||
config.OCO_AI_PROVIDER == 'ollama' ||
|
||||
config.OCO_AI_PROVIDER == 'azure' ||
|
||||
config.OCO_AI_PROVIDER == 'test',
|
||||
config.OCO_AI_PROVIDER == 'test' ||
|
||||
config.OCO_AI_PROVIDER == 'flowise',
|
||||
`${value} is not supported yet, use:\n\n ${[
|
||||
...MODEL_LIST.openai,
|
||||
...MODEL_LIST.anthropic,
|
||||
@@ -307,9 +324,16 @@ export const configValidators = {
|
||||
[CONFIG_KEYS.OCO_AI_PROVIDER](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_AI_PROVIDER,
|
||||
['', 'openai', 'anthropic', 'gemini', 'azure', 'test'].includes(value) ||
|
||||
value.startsWith('ollama'),
|
||||
`${value} is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini' or 'openai' (default)`
|
||||
[
|
||||
'',
|
||||
'openai',
|
||||
'anthropic',
|
||||
'gemini',
|
||||
'azure',
|
||||
'test',
|
||||
'flowise'
|
||||
].includes(value) || value.startsWith('ollama'),
|
||||
`${value} is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini', 'flowise' or 'openai' (default)`
|
||||
);
|
||||
return value;
|
||||
},
|
||||
@@ -323,6 +347,7 @@ export const configValidators = {
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_AZURE_ENDPOINT](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_AZURE_ENDPOINT,
|
||||
@@ -332,6 +357,17 @@ export const configValidators = {
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_FLOWISE_ENDPOINT](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_FLOWISE_ENDPOINT,
|
||||
typeof value === 'string' && value.includes(':'),
|
||||
'Value must be string and should include both I.P. and port number' // Considering the possibility of DNS lookup or feeding the I.P. explicitely, there is no pattern to verify, except a column for the port number
|
||||
);
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_TEST_MOCK_TYPE,
|
||||
@@ -360,7 +396,6 @@ export type ConfigType = {
|
||||
|
||||
const defaultConfigPath = pathJoin(homedir(), '.opencommit');
|
||||
const defaultEnvPath = pathResolve(process.cwd(), '.env');
|
||||
|
||||
export const getConfig = ({
|
||||
configPath = defaultConfigPath,
|
||||
envPath = defaultEnvPath
|
||||
@@ -394,10 +429,12 @@ export const getConfig = ({
|
||||
OCO_GITPUSH: process.env.OCO_GITPUSH === 'false' ? false : true,
|
||||
OCO_ONE_LINE_COMMIT:
|
||||
process.env.OCO_ONE_LINE_COMMIT === 'true' ? true : false,
|
||||
OCO_AZURE_ENDPOINT: process.env.OCO_AZURE_ENDPOINT || '',
|
||||
OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE || 'commit-message'
|
||||
OCO_AZURE_ENDPOINT: process.env.OCO_AZURE_ENDPOINT || undefined,
|
||||
OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE || 'commit-message',
|
||||
OCO_FLOWISE_ENDPOINT: process.env.OCO_FLOWISE_ENDPOINT || ':',
|
||||
OCO_FLOWISE_API_KEY: process.env.OCO_FLOWISE_API_KEY || undefined,
|
||||
OCO_OLLAMA_API_URL: process.env.OCO_OLLAMA_API_URL || undefined
|
||||
};
|
||||
|
||||
const configExists = existsSync(configPath);
|
||||
if (!configExists) return configFromEnv;
|
||||
|
||||
|
||||
@@ -48,15 +48,13 @@ if (
|
||||
|
||||
const MODEL = config?.OCO_MODEL;
|
||||
if (provider === 'anthropic' &&
|
||||
!MODEL_LIST.anthropic.includes(MODEL) &&
|
||||
command !== 'config' &&
|
||||
mode !== CONFIG_MODES.set) {
|
||||
outro(
|
||||
`${chalk.red('✖')} Unsupported model ${MODEL} for Anthropic. Supported models are: ${MODEL_LIST.anthropic.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
process.exit(1);
|
||||
MODEL.typeof !== 'string' &&
|
||||
command !== 'config' &&
|
||||
mode !== CONFIG_MODES.set) {
|
||||
outro(
|
||||
`${chalk.red('✖')} Unsupported model ${MODEL}. The model can be any string, but the current configuration is not supported.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export class AnthropicAi implements AiEngine {
|
||||
|
||||
43
src/engine/flowise.ts
Normal file
43
src/engine/flowise.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,15 +54,12 @@ if (
|
||||
|
||||
const MODEL = config?.OCO_MODEL || 'gpt-3.5-turbo';
|
||||
if (provider === 'openai' &&
|
||||
!MODEL_LIST.openai.includes(MODEL) &&
|
||||
MODEL.typeof !== 'string' &&
|
||||
command !== 'config' &&
|
||||
mode !== CONFIG_MODES.set) {
|
||||
outro(
|
||||
`${chalk.red('✖')} Unsupported model ${MODEL} for OpenAI. Supported models are: ${MODEL_LIST.openai.join(
|
||||
', '
|
||||
)}`
|
||||
`${chalk.red('✖')} Unsupported model ${MODEL}. The model can be any string, but the current configuration is not supported.`
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"localLanguage": "简体中文",
|
||||
"commitFix": "修复(server.ts):将端口变量从小写port改为大写PORT",
|
||||
"commitFeat": "功能(server.ts):添加对process.env.PORT环境变量的支持",
|
||||
"commitFix": "fix(server.ts):将端口变量从小写port改为大写PORT",
|
||||
"commitFeat": "feat(server.ts):添加对process.env.PORT环境变量的支持",
|
||||
"commitDescription": "现在端口变量被命名为PORT,这提高了命名约定的一致性,因为PORT是一个常量。环境变量的支持使应用程序更加灵活,因为它现在可以通过process.env.PORT环境变量在任何可用端口上运行。"
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { OllamaAi } from '../engine/ollama';
|
||||
import { AnthropicAi } from '../engine/anthropic'
|
||||
import { TestAi } from '../engine/testAi';
|
||||
import { Azure } from '../engine/azure';
|
||||
import { FlowiseAi } from '../engine/flowise'
|
||||
|
||||
export function getEngine(): AiEngine {
|
||||
const config = getConfig();
|
||||
@@ -13,9 +14,11 @@ export function getEngine(): AiEngine {
|
||||
|
||||
if (provider?.startsWith('ollama')) {
|
||||
const ollamaAi = new OllamaAi();
|
||||
const model = provider.split('/')[1];
|
||||
if (model) ollamaAi.setModel(model);
|
||||
|
||||
const model = provider.substring('ollama/'.length);
|
||||
if (model) {
|
||||
ollamaAi.setModel(model);
|
||||
ollamaAi.setUrl(config?.OCO_OLLAMA_API_URL);
|
||||
}
|
||||
return ollamaAi;
|
||||
} else if (provider == 'anthropic') {
|
||||
return new AnthropicAi();
|
||||
@@ -25,6 +28,8 @@ export function getEngine(): AiEngine {
|
||||
return new Gemini();
|
||||
} else if (provider == 'azure') {
|
||||
return new Azure();
|
||||
} else if( provider == 'flowise'){
|
||||
return new FlowiseAi();
|
||||
}
|
||||
|
||||
//open ai gpt by default
|
||||
|
||||
@@ -102,4 +102,4 @@ OCO_ONE_LINE_COMMIT="true"
|
||||
|
||||
await envFile.cleanup();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user