diff --git a/README.md b/README.md index 8783dda..fca8b71 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ $ go run main.go { "api_key": "xxxxxxxxx", // openai api_key "base_url": "api.openai.com", // 如果你想指定请求url的地址,可通过这个参数进行配置,默认为官方地址,不需要再添加 /v1 - "model": "gpt-3.5-turbo", // 指定模型,默认为 gpt-3.5-turbo ,具体选项参考官网训练场 + "model": "gpt-3.5-turbo", // 指定模型,默认为 gpt-3.5-turbo , 可选参数有: "gpt-4-32k-0314", "gpt-4-32k", "gpt-4-0314", "gpt-4", "gpt-3.5-turbo-0301", "gpt-3.5-turbo", "text-davinci-003", "text-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001", "text-davinci-001", "davinci-instruct-beta", "davinci", "curie-instruct-beta", "curie", "ada", "babbage" "session_timeout": 600, // 会话超时时间,默认600秒,在会话时间内所有发送给机器人的信息会作为上下文 "http_proxy": "", // 指定请求时使用的代理,如果为空,则不使用代理 "default_mode": "单聊" // 默认对话模式,可根据实际场景自定义,如果不设置,默认为单聊 diff --git a/go.mod b/go.mod index e7bf5ec..1e61b43 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( ) require ( - github.com/sashabaranov/go-openai v1.5.0 // indirect + github.com/sashabaranov/go-openai v1.5.1 // indirect golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect ) diff --git a/go.sum b/go.sum index 00ca00b..4bd2157 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/sashabaranov/go-openai v1.5.0 h1:4Gr/7g/KtVzW0ddn7TC2aUlyzvhZBIM+qRZ6Ae2kMa0= -github.com/sashabaranov/go-openai v1.5.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= +github.com/sashabaranov/go-openai v1.5.1 h1:w9pO7L0X4CLuyH3NZ0WXBBU1wvPeA2JEcxMdlPosInY= +github.com/sashabaranov/go-openai v1.5.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM= golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/chatgpt/chatgpt.go b/pkg/chatgpt/chatgpt.go index 6c028a8..c751612 100644 --- a/pkg/chatgpt/chatgpt.go +++ b/pkg/chatgpt/chatgpt.go @@ -28,7 +28,6 @@ func New(userId string) *ChatGPT { var ctx context.Context var cancel func() - // public.Config.BaseURL, public.Config.ApiKey, public.Config.HttpProxy if public.Config.SessionTimeout == 0 { ctx, cancel = context.WithCancel(context.Background()) } else { diff --git a/pkg/chatgpt/context.go b/pkg/chatgpt/context.go index 8955583..0dad187 100644 --- a/pkg/chatgpt/context.go +++ b/pkg/chatgpt/context.go @@ -157,9 +157,13 @@ func (c *ChatGPT) ChatWithContext(question string) (answer string, err error) { return "", OverMaxTextLength } - if public.Config.Model == openai.GPT3Dot5Turbo0301 || public.Config.Model == openai.GPT3Dot5Turbo { + model := public.Config.Model + if model == openai.GPT3Dot5Turbo0301 || + model == openai.GPT3Dot5Turbo || + model == openai.GPT4 || model == openai.GPT40314 || + model == openai.GPT432K || model == openai.GPT432K0314 { req := openai.ChatCompletionRequest{ - Model: public.Config.Model, + Model: model, Messages: []openai.ChatCompletionMessage{ { Role: "user", @@ -183,7 +187,7 @@ func (c *ChatGPT) ChatWithContext(question string) (answer string, err error) { return resp.Choices[0].Message.Content, nil } else { req := openai.CompletionRequest{ - Model: public.Config.Model, + Model: model, MaxTokens: c.maxAnswerLen, Prompt: prompt, Temperature: 0.9,