feat: model configuration to support different models (#183)
Co-authored-by: hiroki osame <hiroki.osame@gmail.com>
This commit is contained in:
@@ -180,6 +180,12 @@ To clear the proxy option, you can use the command (note the empty value after t
|
|||||||
aicommits config set proxy=
|
aicommits config set proxy=
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### model
|
||||||
|
|
||||||
|
Default: `gpt-3.5-turbo`
|
||||||
|
|
||||||
|
The Chat Completions (`/v1/chat/completions`) model to use. Consult the list of models available in the [OpenAI Documentation](https://platform.openai.com/docs/models/model-endpoint-compatibility).
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
This CLI tool runs `git diff` to grab all your latest code changes, sends them to OpenAI's GPT-3, then returns the AI generated commit message.
|
This CLI tool runs `git diff` to grab all your latest code changes, sends them to OpenAI's GPT-3, then returns the AI generated commit message.
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export default async (
|
|||||||
try {
|
try {
|
||||||
messages = await generateCommitMessage(
|
messages = await generateCommitMessage(
|
||||||
config.OPENAI_KEY,
|
config.OPENAI_KEY,
|
||||||
|
config.model,
|
||||||
config.locale,
|
config.locale,
|
||||||
staged.diff,
|
staged.diff,
|
||||||
config.generate,
|
config.generate,
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export default () => (async () => {
|
|||||||
try {
|
try {
|
||||||
messages = await generateCommitMessage(
|
messages = await generateCommitMessage(
|
||||||
config.OPENAI_KEY,
|
config.OPENAI_KEY,
|
||||||
|
config.model,
|
||||||
config.locale,
|
config.locale,
|
||||||
staged!.diff,
|
staged!.diff,
|
||||||
config.generate,
|
config.generate,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fs from 'fs/promises';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import ini from 'ini';
|
import ini from 'ini';
|
||||||
|
import type { TiktokenModel } from '@dqbd/tiktoken';
|
||||||
import { fileExists } from './fs.js';
|
import { fileExists } from './fs.js';
|
||||||
import { KnownError } from './error.js';
|
import { KnownError } from './error.js';
|
||||||
|
|
||||||
@@ -60,6 +61,13 @@ const configParsers = {
|
|||||||
|
|
||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
|
model(model?: string) {
|
||||||
|
if (!model || model.length === 0) {
|
||||||
|
return 'gpt-3.5-turbo';
|
||||||
|
}
|
||||||
|
|
||||||
|
return model as TiktokenModel;
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
type ConfigKeys = keyof typeof configParsers;
|
type ConfigKeys = keyof typeof configParsers;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import https from 'https';
|
import https from 'https';
|
||||||
import type { ClientRequest, IncomingMessage } from 'http';
|
import type { ClientRequest, IncomingMessage } from 'http';
|
||||||
import type { CreateChatCompletionRequest, CreateChatCompletionResponse } from 'openai';
|
import type { CreateChatCompletionRequest, CreateChatCompletionResponse } from 'openai';
|
||||||
import { encoding_for_model as encodingForModel } from '@dqbd/tiktoken';
|
import { type TiktokenModel, encoding_for_model as encodingForModel } from '@dqbd/tiktoken';
|
||||||
import createHttpsProxyAgent from 'https-proxy-agent';
|
import createHttpsProxyAgent from 'https-proxy-agent';
|
||||||
import { KnownError } from './error.js';
|
import { KnownError } from './error.js';
|
||||||
|
|
||||||
@@ -99,10 +99,9 @@ const deduplicateMessages = (array: string[]) => Array.from(new Set(array));
|
|||||||
|
|
||||||
const getPrompt = (locale: string, diff: string) => `Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff without prefacing it with anything, the response must be in the language ${locale}:\n${diff}`;
|
const getPrompt = (locale: string, diff: string) => `Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff without prefacing it with anything, the response must be in the language ${locale}:\n${diff}`;
|
||||||
|
|
||||||
const model = 'gpt-3.5-turbo';
|
|
||||||
|
|
||||||
export const generateCommitMessage = async (
|
export const generateCommitMessage = async (
|
||||||
apiKey: string,
|
apiKey: string,
|
||||||
|
model: TiktokenModel,
|
||||||
locale: string,
|
locale: string,
|
||||||
diff: string,
|
diff: string,
|
||||||
completions: number,
|
completions: number,
|
||||||
|
|||||||
Reference in New Issue
Block a user