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

feat: add parameter to control gpt model choice #264

Closed
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
3 changes: 3 additions & 0 deletions cmd/analyze_gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
gogpt "github.com/sashabaranov/go-openai"

"github.com/Legit-Labs/legitify/internal/common/namespace"
"github.com/Legit-Labs/legitify/internal/common/scm_type"
Expand All @@ -16,6 +17,7 @@ func init() {
var analyzeGptArgs args

const argOpenAiToken = "openai_token"
const argOpenAiGptModel = "model"

func newAnalyzeGptCommand() *cobra.Command {
analyzeCmd := &cobra.Command{
Expand All @@ -32,6 +34,7 @@ func newAnalyzeGptCommand() *cobra.Command {
flags.StringSliceVarP(&analyzeGptArgs.Organizations, argOrg, "", nil, "specific organizations to collect")
flags.StringSliceVarP(&analyzeGptArgs.Repositories, argRepository, "", nil, "specific repositories to collect (--repo owner/repo_name (e.g. ossf/scorecard)")
flags.StringVarP(&analyzeGptArgs.OpenAIToken, argOpenAiToken, "", "", "token to authenticate with openai API")
flags.StringVarP(&analyzeGptArgs.OpenAIGptModel, argOpenAiGptModel, "", gogpt.GPT3TextDavinci003, "gpt-model to use")
viper.AutomaticEnv()

return analyzeCmd
Expand Down
1 change: 1 addition & 0 deletions cmd/common_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type args struct {
Token string
OpenAIToken string
OpenAIGptModel string
Endpoint string
ScmType scm_type.ScmType
Organizations []string
Expand Down
2 changes: 1 addition & 1 deletion cmd/common_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ func provideContext(client Client, args *args) (context.Context, error) {
}

func provideGPTAnalyzer(context context.Context, args *args) *gpt.Analyzer {
return gpt.NewAnalyzer(context, args.OpenAIToken)
return gpt.NewAnalyzer(context, args.OpenAIToken, args.OpenAIGptModel)
}
6 changes: 4 additions & 2 deletions internal/gpt/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type Analyzer struct {
context context.Context
gptClient *gogpt.Client
gptModel string
}

type Result struct {
Expand All @@ -28,10 +29,11 @@ type Result struct {
GPTResult string
}

func NewAnalyzer(ctx context.Context, gptToken string) *Analyzer {
func NewAnalyzer(ctx context.Context, gptToken string, gptModel string) *Analyzer {
return &Analyzer{
context: ctx,
gptClient: gogpt.NewClient(gptToken),
gptModel: gptModel,
}
}

Expand Down Expand Up @@ -109,7 +111,7 @@ func (a *Analyzer) Analyze(dataChannel <-chan collectors.CollectedData) chan Res
prompt := generatePrompt(raw, entityType)

requestOptions := gogpt.CompletionRequest{
Model: gogpt.GPT3TextDavinci003,
Model: a.gptModel,
Prompt: prompt,
// Temperature sets how much freedom GPT-3 API has to introduce randomness in the response
// 1.0 means maximum freedom
Expand Down