gpt: reset client when prompt changes

This commit is contained in:
Chris Sexton 2023-03-03 12:14:06 -05:00
parent 92ce4979b4
commit 8b8ac7b244
1 changed files with 4 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import (
) )
import "github.com/andrewstuart/openai" import "github.com/andrewstuart/openai"
var session *openai.ChatSession var session openai.ChatSession
var client *openai.Client var client *openai.Client
func (p *GPTPlugin) getClient() (*openai.Client, error) { func (p *GPTPlugin) getClient() (*openai.Client, error) {
@ -14,14 +14,11 @@ func (p *GPTPlugin) getClient() (*openai.Client, error) {
if token == "" { if token == "" {
return nil, fmt.Errorf("no GPT token given") return nil, fmt.Errorf("no GPT token given")
} }
if client == nil {
return openai.NewClient(token) return openai.NewClient(token)
} }
return client, nil
}
func (p *GPTPlugin) chatGPT(request string) (string, error) { func (p *GPTPlugin) chatGPT(request string) (string, error) {
if session == nil { if client == nil {
if err := p.setDefaultPrompt(); err != nil { if err := p.setDefaultPrompt(); err != nil {
return "", err return "", err
} }
@ -38,7 +35,6 @@ func (p *GPTPlugin) setPrompt(prompt string) error {
if err != nil { if err != nil {
return err return err
} }
sess := client.NewChatSession(prompt) session = client.NewChatSession(prompt)
session = &sess
return nil return nil
} }