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 gpt model option #29

Merged
merged 1 commit into from
Jul 8, 2023
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/gpt_pullrequest_updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.number }}
OPENAI_MODEL: gpt-4

- name: Review Pull Request
if: github.event.action == 'opened'
Expand All @@ -47,3 +48,4 @@ jobs:
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.number }}
OPENAI_MODEL: gpt-4
3 changes: 2 additions & 1 deletion cmd/description/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var opts struct {
Owner string `long:"owner" env:"OWNER" description:"GitHub owner" required:"true"`
Repo string `long:"repo" env:"REPO" description:"GitHub repo" required:"true"`
PRNumber int `long:"pr-number" env:"PR_NUMBER" description:"Pull request number" required:"true"`
OpenAIModel string `long:"openai-model" env:"OPENAI_MODEL" description:"OpenAI model" default:"gpt-3.5-turbo"`
Test bool `long:"test" env:"TEST" description:"Test mode"`
JiraURL string `long:"jira-url" env:"JIRA_URL" description:"Jira URL. Example: https://jira.atlassian.com"`
}
Expand All @@ -43,7 +44,7 @@ func main() {
}

func run(ctx context.Context) error {
openAIClient := oAIClient.NewClient(opts.OpenAIToken)
openAIClient := oAIClient.NewClient(opts.OpenAIToken, opts.OpenAIModel)
githubClient := ghClient.NewClient(ctx, opts.GithubToken)

pr, err := githubClient.GetPullRequest(ctx, opts.Owner, opts.Repo, opts.PRNumber)
Expand Down
3 changes: 2 additions & 1 deletion cmd/review/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var opts struct {
Owner string `long:"owner" env:"OWNER" description:"GitHub owner" required:"true"`
Repo string `long:"repo" env:"REPO" description:"GitHub repo" required:"true"`
PRNumber int `long:"pr-number" env:"PR_NUMBER" description:"Pull request number" required:"true"`
OpenAIModel string `long:"openai-model" env:"OPENAI_MODEL" description:"OpenAI model" default:"gpt-3.5-turbo"`
Test bool `long:"test" env:"TEST" description:"Test mode"`
}

Expand All @@ -40,7 +41,7 @@ func main() {
}

func run(ctx context.Context) error {
openAIClient := oAIClient.NewClient(opts.OpenAIToken)
openAIClient := oAIClient.NewClient(opts.OpenAIToken, opts.OpenAIModel)
githubClient := ghClient.NewClient(ctx, opts.GithubToken)

pr, err := githubClient.GetPullRequest(ctx, opts.Owner, opts.Repo, opts.PRNumber)
Expand Down
14 changes: 8 additions & 6 deletions openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ var PromptDescribeOverall string

type Client struct {
client *openai.Client
model string
}

func NewClient(token string) *Client {
func NewClient(token, model string) *Client {
return &Client{
client: openai.NewClient(token),
model: model,
}
}

func (o *Client) ChatCompletion(ctx context.Context, messages []openai.ChatCompletionMessage) (string, error) {
resp, err := o.client.CreateChatCompletion(
func (c *Client) ChatCompletion(ctx context.Context, messages []openai.ChatCompletionMessage) (string, error) {
resp, err := c.client.CreateChatCompletion(
ctx,
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Model: c.model,
Messages: messages,
Temperature: 0.1,
},
Expand All @@ -47,10 +49,10 @@ func (o *Client) ChatCompletion(ctx context.Context, messages []openai.ChatCompl
fmt.Println("Retrying after 1 minute")
// retry once after 1 minute
time.Sleep(time.Minute)
resp, err = o.client.CreateChatCompletion(
resp, err = c.client.CreateChatCompletion(
ctx,
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Model: c.model,
Messages: messages,
Temperature: 0.1,
},
Expand Down