mirror of
https://github.com/Pull-Pal/pull-pal.git
synced 2024-12-22 01:56:26 -05:00
parse openAI api responses. get fully automated behavior kind of working
This commit is contained in:
parent
99bd1929b5
commit
3a312b2b9b
@ -91,14 +91,19 @@ func parseFiles(filesSection string) []File {
|
||||
// first item in the list is just gonna be "Files:"
|
||||
fileStringList = fileStringList[1:]
|
||||
|
||||
replacer := strings.NewReplacer(
|
||||
"\\n", "\n",
|
||||
"\\\"", "\"",
|
||||
"```", "",
|
||||
)
|
||||
fileList := make([]File, len(fileStringList))
|
||||
for i, f := range fileStringList {
|
||||
fileParts := strings.Split(f, "contents:")
|
||||
path := strings.TrimSpace(fileParts[0])
|
||||
// TODO currently, copy-pasting code from chatgpt also copies some additional text
|
||||
// the following separates this unintended section from the actual intended contents of the file
|
||||
contentParts := strings.Split(fileParts[1], "Copy code")
|
||||
contents := strings.TrimSpace(contentParts[1])
|
||||
path := replacer.Replace(fileParts[0])
|
||||
path = strings.TrimSpace(path)
|
||||
|
||||
contents := replacer.Replace(fileParts[1])
|
||||
contents = strings.TrimSpace(contents)
|
||||
|
||||
fileList[i] = File{
|
||||
Path: path,
|
||||
|
@ -2,17 +2,19 @@ package llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OpenAIClient struct {
|
||||
log *zap.Logger
|
||||
client *openai.Client
|
||||
}
|
||||
|
||||
func NewOpenAIClient(token string) *OpenAIClient {
|
||||
func NewOpenAIClient(log *zap.Logger, token string) *OpenAIClient {
|
||||
return &OpenAIClient{
|
||||
log: log,
|
||||
client: openai.NewClient(token),
|
||||
}
|
||||
}
|
||||
@ -32,12 +34,14 @@ func (oc *OpenAIClient) EvaluateCCR(ctx context.Context, req CodeChangeRequest)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("ChatCompletion error: %v\n", err)
|
||||
oc.log.Error("chat completion error", zap.Error(err))
|
||||
return res, err
|
||||
}
|
||||
|
||||
// TODO use different choices/different options in different branches/worktrees?
|
||||
choice := resp.Choices[0].Message.Content
|
||||
|
||||
oc.log.Debug("got response from llm", zap.String("output", choice))
|
||||
|
||||
return ParseCodeChangeResponse(choice), nil
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func NewPullPal(ctx context.Context, log *zap.Logger, listIssueOptions vc.ListIs
|
||||
|
||||
vcClient: ghClient,
|
||||
localGitClient: localGitClient,
|
||||
openAIClient: llm.NewOpenAIClient(openAIToken),
|
||||
openAIClient: llm.NewOpenAIClient(log.Named("openaiClient"), openAIToken),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user