f
This commit is contained in:
@@ -20,6 +20,7 @@ func NewClient(token string) *Client {
|
||||
}
|
||||
|
||||
func (c Client) Completions(prompt string) (*CompletionResponse, error) {
|
||||
fmt.Printf("\ncompletions: %s", prompt)
|
||||
body := &CompletionPayload{
|
||||
Model: "text-davinci-003",
|
||||
Prompt: cleanPrompt(prompt),
|
||||
@@ -33,6 +34,8 @@ func (c Client) Completions(prompt string) (*CompletionResponse, error) {
|
||||
return nil, fmt.Errorf("failed to marshal the payload. %s", err.Error())
|
||||
}
|
||||
|
||||
fmt.Printf("\nsend request to openai")
|
||||
|
||||
res, err := c.HttpClient.NewRequest().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(b).
|
||||
@@ -41,6 +44,8 @@ func (c Client) Completions(prompt string) (*CompletionResponse, error) {
|
||||
return nil, fmt.Errorf("failed to query openai. Error: %s", err.Error())
|
||||
}
|
||||
|
||||
fmt.Printf("\nreceived openai response: %+v", res.StatusCode())
|
||||
|
||||
var r CompletionResponse
|
||||
if err := json.Unmarshal(res.Body(), &r); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse the openai response. Error: %s", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user