Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to set custom openai model #154

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ added 1 package in 0.582s
</tr>
</table>


## Get Started

> 「cz-git & czg」 require Node >=**v12.20**
Expand Down Expand Up @@ -174,12 +173,11 @@ added 1 package in 0.582s
## LICENSE

MIT
Copyright (c) 2022-present Qiubin Zheng <zhengqbbb@gmail.com> (https://github.com/Zhengqbbb)
Copyright (c) 2022-present Qiubin Zheng <zhengqbbb@gmail.com> (<https://github.com/Zhengqbbb>)

> I just do my best to make thing well, Could you give a [star ⭐](https://github.com/Zhengqbbb/cz-git) to encourage me ?

<a target="_blank" href="https://packagephobia.com/result?p=cz-git,czg">
<img src="https://user-images.githubusercontent.com/40693636/252157675-32634902-fc02-4a07-a12c-a07ec5ee5f1a.png" alt="size-overview"><br>
<sub>https://packagephobia.com/result?p=cz-git,czg</sub>
</a>

9 changes: 7 additions & 2 deletions docs/public/schema/cz-git.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@
"openAI-Turbo",
"openAI-Davinci"
],
"description": "choose your AI model: gpt-3.5-turbo | text-davinci-003\n\ngpt-3.5-turbo: Lower price consumption (10x) and faster\n\ntext-davinci-003: Get more reliable information",
"description": "Choose your OpenAI model: gpt-3.5-turbo | text-davinci-003\n\ngpt-3.5-turbo: Lower price consumption (10x) and faster\n\ntext-davinci-003: Get more reliable information",
"default": "openAI-Turbo"
},
"aiModel": {
"type": "string",
"description": "Choose any OpenAI model: e.g. gpt-4-1106-preview",
"default": "gpt-3.5-turbo"
},
"openAIToken": {
"type": "string",
"description": ": Alert!!! Save on \"$HOME/.czrc\" or \"$HOME/.config/.czrc\". Do not save on project"
Expand Down Expand Up @@ -464,4 +469,4 @@
"additionalProperties": false
}
}
}
}
27 changes: 12 additions & 15 deletions packages/cz-git/src/generator/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,22 @@ export async function fetchOpenAIMessage(options: CommitizenGitOptions, prompt:

// https://platform.openai.com/docs/api-reference/chat/create
function useModelStrategy(options: CommitizenGitOptions, prompt: string) {
const modelOptions = {
temperature: 0.7,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
max_tokens: 200,
stream: false,
n: options.aiNumber ?? 1,
}
switch (options.aiType) {
case 'openAI-Davinci':
return {
payload: {
model: 'text-davinci-003',
prompt,
temperature: 0.7,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
max_tokens: 200,
stream: false,
n: options.aiNumber || 1,
...modelOptions,
},
url: `${options.apiEndpoint}/completions`,
parseFn: (res: any) => res?.text,
Expand All @@ -84,15 +87,9 @@ function useModelStrategy(options: CommitizenGitOptions, prompt: string) {
default:
return {
payload: {
model: 'gpt-3.5-turbo',
model: options.aiModel || 'gpt-3.5-turbo',
messages: [{ role: 'user', content: prompt }],
temperature: 0.7,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
max_tokens: 200,
stream: false,
n: options.aiNumber || 1,
...modelOptions,
},
url: `${options.apiEndpoint}/chat/completions`,
parseFn: (res: any) => res?.message?.content,
Expand Down
1 change: 1 addition & 0 deletions packages/cz-git/src/generator/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function generateOptions(config: UserConfig): CommitizenGitOptions {
aiNumber: parseInt(cz_ainum || '0', 10) || promptConfig.aiNumber || defaultConfig.aiNumber,
aiDiffIgnore: promptConfig.aiDiffIgnore ?? promptConfig.aiDiffIgnore,
aiType: promptConfig.aiType ?? defaultConfig.aiType,
aiModel: promptConfig.aiModel ?? defaultConfig.aiModel,
aiQuestionCB: promptConfig.aiQuestionCB ?? defaultConfig.aiQuestionCB,
openAIToken: process.env.CZ_OPENAI_TOKEN || process.env.CZ_OPENAI_API_KEY || promptConfig.openAIToken || defaultConfig.openAIToken,
apiProxy: promptConfig.apiProxy || defaultConfig.apiProxy,
Expand Down
17 changes: 14 additions & 3 deletions packages/cz-git/src/shared/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,25 @@ export interface CommitizenGitOptions {
aiDiffIgnore?: string[]

/**
* Choose the AI model you want to use: gpt-3.5-turbo | text-davinci-003
* Choose your Open AI model: gpt-3.5-turbo | text-davinci-003
*
* gpt-3.5-turbo: Lower price consumption (10x) and faster
* text-davinci-003: Get more reliable information
*
* @default openAI-Turbo
* text-davinci-003: Gets more reliable information
*
* @default "openAI-Turbo"
*/
aiType?: 'openAI-Turbo' | 'openAI-Davinci'

/**
* Choose any Open AI model: gpt-4 | gpt-4-1106-preview | etc
*
* This should a Chat model, not a Completion model like `gpt-3.5-turbo-instruct`. See https://platform.openai.com/docs/models/model-endpoint-compatibility
*
* @default "gpt-3.5-turbo"
*/
aiModel?: 'gpt-3.5-turbo' | string

/**
* @description: Alert!!! Save on "$HOME/.czrc" or "$HOME/.config/.czrc". Do not save on project
*/
Expand Down
13 changes: 11 additions & 2 deletions scripts/czrc-schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,25 @@ export interface CommitizenGitOptions {
aiDiffIgnore?: string[]

/**
* choose your AI model: gpt-3.5-turbo | text-davinci-003
* Choose your Open AI model: gpt-3.5-turbo | text-davinci-003
*
* gpt-3.5-turbo: Lower price consumption (10x) and faster
*
* text-davinci-003: Get more reliable information
* text-davinci-003: Gets more reliable information
*
* @default "openAI-Turbo"
*/
aiType?: 'openAI-Turbo' | 'openAI-Davinci'

/**
* Choose any Open AI model: gpt-4 | gpt-4-1106-preview | etc
*
* Note that this should a Chat model, not a Completion model like `gpt-3.5-turbo-instruct`. See https://platform.openai.com/docs/models/model-endpoint-compatibility
*
* @default "gpt-3.5-turbo"
*/
aiModel?: 'gpt-3.5-turbo' | string

/**
* @description: Alert!!! Save on "$HOME/.czrc" or "$HOME/.config/.czrc". Do not save on project
*/
Expand Down