Skip to content

Commit

Permalink
Merge pull request #23 from ytkg/add-model-option
Browse files Browse the repository at this point in the history
Add model option to config
  • Loading branch information
ytkg authored Jun 3, 2023
2 parents 2a98e2c + e1a730f commit e25e0be
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ $ cg config list
api_key = sk-HogehogeXXX
```

| Key | Description |
|---------|--------------------------------------------------------|
| api_key | API key used for authentication with OpenAI |
| model | model name for OpenAI (e.g., `gpt-3.5-turbo`, `gpt-4`) |

## License
The source code is licensed MIT.
2 changes: 1 addition & 1 deletion commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class SetCommand extends Command {
constructor() {
super();
this.description("Update configuration with a value for the given key")
.type("config", new EnumType(["api_key"]))
.type("config", new EnumType(["api_key", "model"]))
.arguments("<key:config> <value:string>")
.action(async (_, key, value) => {
const config = await loadConfig();
Expand Down
7 changes: 3 additions & 4 deletions commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export class MainCommand extends Command {
.env("OPENAI_ACCESS_TOKEN=<value:string>", "OPENAI ACCESS TOKEN")
.env("OPENAI_API_KEY=<value:string>", "OPENAI API KEY")
.type("model-type", modelType)
.option("-m --model <model:model-type>", "Model Type", {
default: "gpt-3.5-turbo" as const,
})
.option("-m --model <model:model-type>", "Model name")
.action(async (options) => {
const config = await loadConfig();
const apiKey = options.openaiAccessToken || options.openaiApiKey ||
Expand All @@ -35,10 +33,11 @@ export class MainCommand extends Command {
}

const diffText = await getDiffText();
const model = options.model || config.model || "gpt-3.5-turbo";
const commitMessageSuggestion = await getCommitMessageSuggestion(
apiKey,
diffText,
options.model,
model,
);

console.log(commitMessageSuggestion);
Expand Down
2 changes: 1 addition & 1 deletion commands/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deno.test("help command", () => {
Options:
-m, --model <model> - Model Type (Default: "gpt-3.5-turbo", Values: "gpt-3.5-turbo", "gpt-4")
-m, --model <model> - Model name (Values: "gpt-3.5-turbo", "gpt-4")
Commands:
Expand Down
3 changes: 2 additions & 1 deletion lib/get_commit_message_suggestion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenAI } from "../deps.ts";
import { ChatCompletion } from "https://deno.land/x/[email protected]/mod.ts";
import { Model } from "../types.d.ts";

interface CustomChatCompletion extends ChatCompletion {
error: {
Expand All @@ -10,7 +11,7 @@ interface CustomChatCompletion extends ChatCompletion {
export const getCommitMessageSuggestion = async (
openaiAccessToken: string,
diffText: string,
model: "gpt-3.5-turbo" | "gpt-4",
model: Model,
): Promise<string> => {
const openAI = new OpenAI(openaiAccessToken);

Expand Down
6 changes: 1 addition & 5 deletions lib/load_config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { exists, parse } from "../deps.ts";

type Config = {
api_key?: string;
[key: string]: string | undefined;
};
import { Config } from "../types.d.ts";

export const loadConfig = async (): Promise<Config> => {
const filePath = `${Deno.env.get("HOME")}/.config/commit_genius/config.toml`;
Expand Down
7 changes: 7 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type Model = "gpt-3.5-turbo" | "gpt-4";

export type Config = {
api_key?: string;
model?: Model;
[key: string]: string | undefined;
};

0 comments on commit e25e0be

Please sign in to comment.