Skip to content

Commit

Permalink
feat(cz-git,cli): add aiModel to support choose OpenAI model
Browse files Browse the repository at this point in the history
link #180
  • Loading branch information
Zhengqbbb committed Sep 26, 2024
1 parent 79a7833 commit ed0e06d
Show file tree
Hide file tree
Showing 24 changed files with 350 additions and 222 deletions.
15 changes: 10 additions & 5 deletions docs/.vitepress/theme/style/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ img.error {
img.error::before {
content: '';
position: absolute;
left: 0;
left: 0;
top: 0;
width: 100%;
width: 100%;
height: 100%;
color: transparent;
--un-icon: url("data:image/svg+xml,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M304.128 456.192c48.64 0 88.064-39.424 88.064-88.064s-39.424-88.064-88.064-88.064-88.064 39.424-88.064 88.064 39.424 88.064 88.064 88.064zm0-116.224c15.36 0 28.16 12.288 28.16 28.16s-12.288 28.16-28.16 28.16-28.16-12.288-28.16-28.16 12.288-28.16 28.16-28.16z' fill='%23aaaaaa'/%3E%3Cpath d='M887.296 159.744H136.704C96.768 159.744 64 192 64 232.448v559.104c0 39.936 32.256 72.704 72.704 72.704h198.144L500.224 688.64l-36.352-222.72 162.304-130.56-61.44 143.872 92.672 214.016-105.472 171.008h335.36C927.232 864.256 960 832 960 791.552V232.448c0-39.936-32.256-72.704-72.704-72.704zm-138.752 71.68v.512H857.6c16.384 0 30.208 13.312 30.208 30.208v399.872L673.28 408.064l75.264-176.64zM304.64 792.064H165.888c-16.384 0-30.208-13.312-30.208-30.208v-9.728l138.752-164.352 104.96 124.416-74.752 79.872zm81.92-355.84l37.376 228.864-.512.512-142.848-169.984c-3.072-3.584-9.216-3.584-12.288 0L135.68 652.8V262.144c0-16.384 13.312-30.208 30.208-30.208h474.624L386.56 436.224zm501.248 325.632c0 16.896-13.312 30.208-29.696 30.208H680.96l57.344-93.184-87.552-202.24 7.168-7.68 229.888 272.896z' fill='%23aaaaaa'/%3E%3C/svg%3E");
Expand All @@ -114,7 +114,7 @@ img.error::after {
color: inherit;
font-size: 0.85rem;
position: absolute;
left: 0;
left: 0;
bottom: 0;
width: 100%;
background-color: var(--vp-c-bg-nav);
Expand Down Expand Up @@ -185,7 +185,7 @@ img.error::after {
.VPHome .VPTeamMembersItem {
border: 1px solid var(--vp-button-alt-border);
}
.VPHome .VPTeamMembersItem .profile {
.VPHome .VPTeamMembersItem .profile {
background: none;
color: var(--vp-button-alt-text);
}
Expand Down Expand Up @@ -233,6 +233,11 @@ img.error::after {
color: var(--vp-custom-block-danger-text-deep);
}

.vp-doc .custom-block a {
text-decoration-color: inherit;
-webkit-text-decoration-color: inherit;
}

.vp-doc .custom-block a:hover,
.vp-doc .custom-block a:active {
color: inherit;
Expand All @@ -255,7 +260,7 @@ img.error::after {
.dark .DocSearch-Button-Key {
box-shadow: none;
}
.DocSearch-Modal .cls-1,
.DocSearch-Modal .cls-1,
.DocSearch-Modal .cls-2{
fill: var(--vp-c-docsearch-logo-color);
}
Expand Down
8 changes: 5 additions & 3 deletions docs/cli/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ czg --api-key=sk-xxxxx
## Options

| Shorthand, Name | Description |
| --- | --- |
| `-N=<number>`<br>`--ai-num=<number>` | Setting AI return number subjects and Turn on choose mode |
| `--no-ai` | Turn off AI prompt mode in this session |
| --- | --- |
| `-N=<number>`<br>`--ai-num=<number>` | Sets AI return multiple subjects and Turn on choose mode |
| `-M=<model>`<br>`--ai-model=<model>` | Sets AI model in this session |
| `--no-ai` | Turn off AI prompt mode in this session |
| `--api-key=<token>` | Setup OpenAI API secret key to local (.config/.czrc) |
| `--api-model=<model>` | Setup request OpenAI API model to local (.config/.czrc) |
| `--api-proxy=<proxy_URL>` | Setup request OpenAI API proxy to local (.config/.czrc)<br>e.g:<br> 1. `npx czg --api-proxy="socks5://127.0.0.1:1080"`<br>2. `npx czg --api-proxy="http://127.0.0.1:1080"` |
| `--api-endpoint=<url>` | Setup request OpenAI API endpoint to local<br>Default `"https://api.openai.com/v1"` |
| `--unset-proxy` | Unset request API proxy on local configure |
Expand Down
70 changes: 37 additions & 33 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,41 +82,45 @@ More information about configure file and options. See → [Config](/config/)
https://cz-git.qbb.sh/cli/
https://github.com/Zhengqbbb/cz-git
[33mSYNOPSIS:[0m
[33mSYNOPSIS:[39m
czg [subcommand...] [options...] [git-commit-options...]
SUBCOMMAND:
ai Turn on OpenAI generate subject mode
break Turn on appends a ! after the type/scope
emoji Turn on output message with emoji mode
checkbox Turn on scope checkbox mode
gpg Turn on use GPG sign commit message
OPTIONS:
:, --alias= Directly submit the defined commit message
--config= Specify the configuration file to use
OpenAI:
-N=,--ai-num= Setting AI return number subjects and Turn on choose mode
--api-key= Setup request OpenAI API secret key to local (.config/.czrc)
--api-proxy= Setup request OpenAI API proxy to local (.config/.czrc)
--api-endpoint= Setup request OpenAI API endpoint to local (.config/.czrc)
[default: "https://api.openai.com/v1"]
FLAG:
-r, --retry Directly retry submit by the last message
--no-ai Turn off AI prompt mode in this session
--unset-proxy Unset request API proxy on local configure
-h, --help Show help
-v, --version Show version
EXAMPLES:
czg
czg emoji
czg :fd
czg --config="./config/cz.json"
czg --api-key="sk-XXXXX"
czg ai -N=3
SUBCOMMAND:
ai Turn on OpenAI generate subject mode
break Turn on appends a ! after the type/scope
emoji Turn on output message with emoji mode
checkbox Turn on scope checkbox mode
gpg Turn on use GPG sign commit message
OPTIONS:
:, --alias= Directly submit the defined commit message
--config= Specify the configuration file to use
OpenAI:
-N=,--ai-num= Sets AI return multiple subjects and Turn on choose mode
-M=,--ai-model= Sets AI model in this session
[default: "gpt-4o-mini"]
[example: "gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini" ...]
--api-key= Setup request OpenAI API secret key to local (.config/.czrc)
--api-model= Setup request OpenAI API model to local (.config/.czrc)
--api-proxy= Setup request OpenAI API proxy to local (.config/.czrc)
--api-endpoint= Setup request OpenAI API endpoint to local (.config/.czrc)
[default: "https://api.openai.com/v1"]
FLAG:
-r, --retry Directly retry submit by the last message
--no-ai Turn off AI prompt mode in this session
--unset-proxy Unset request API proxy on local configure
-h, --help Show help
-v, --version Show version
EXAMPLES:
czg
czg emoji
czg :fd
czg --config="./config/cz.json"
czg --api-key="sk-XXXXX"
czg ai -N=3 -M="gpt-4o"
Extends 'git commit' options.
See 'git commit --help' for more information.
Expand Down
41 changes: 28 additions & 13 deletions docs/config/engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ Try running command to **use OpenAI API to auto generate **subject** in the curr
Demo And Usage [⇒ see the recipes](/recipes/openai)
:::

## aiModel

- **description**: Choose the AI model you want to use
- **examples**: `gpt-3.5-turbo` | `gpt-4` | `gpt-4o` | `gpt-4o-mini` <br>... (and models compatible with the [/chat/completions endpoint](https://platform.openai.com/docs/models/model-endpoint-compatibility)) <br>For example: [GitHub models](https://github.com/marketplace/models) and local models ([Ollama](https://ollama.com/library))
- **type**: `string`
- **default**: `gpt-4o-mini`

:::tip
Try running the command to **switch AI models directly in the current session**
- Commitizen CLI + cz-git: `czai=1 cz_aimodel=gpt-3.5-turbo cz`
- czg CLI: `czg ai -M=gpt-3.5-turbo`

Demo And Usage [⇒ see the recipes](/recipes/openai)
:::

:::info
If `aiModel` is set globally or in the project, it will override the value set using `npx czg --api-model=<model>`

<hr>

**Priority explanation, from high to low:**
1. Environment variable specification `cz_aimodel=`, `czg` command parameter specification `-M=|--ai-model=`
2. Global configuration or project configuration: `aiModel` field
3. The `apiModel` field in `~/.config/.czrc` configured via the `npx czg --api-model=<model>` command
:::


## aiNumber

- **description** : If >1 will **turn on select mode**, select generate options like returned by OpenAI
Expand All @@ -132,18 +159,6 @@ Try running command to **select multiple results returned by OpenAI in the curre
Demo And Usage [⇒ see the recipes](/recipes/openai)
:::

## aiType

- **description** : Choose the AI model you want to use

| aiType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Description |
| --- | --- | --- |
| openAI-Turbo | gpt-3.5-turbo | faster and optimized for chat at 1/10th the cost of `text-davinci-003` |
| openAI-Davinci | text-davinci-003 | better quality, longer output, and consistent instruction-following |

- **type** : `"openAI-Turbo" | "openAI-Davinci"`
- **default** : `openAI-Turbo`

## aiDiffIgnore

- **description** : To ignore selection diff codes when sending AI API requests
Expand All @@ -165,7 +180,7 @@ export interface GenerateAIPromptType {
diff?: string
}
```
- **example** :
- **example** :

```js
module.exports = {
Expand Down
Loading

0 comments on commit ed0e06d

Please sign in to comment.