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