* migrate away from deprecated OpenAI endpoints Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com> * test embedding correctness Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>
51 lines
1.0 KiB
Markdown
51 lines
1.0 KiB
Markdown
# go-gpt3
|
|
[](https://godoc.org/github.com/sashabaranov/go-gpt3)
|
|
[](https://goreportcard.com/report/github.com/sashabaranov/go-gpt3)
|
|
|
|
|
|
[OpenAI GPT-3](https://beta.openai.com/) API wrapper for Go
|
|
|
|
Installation:
|
|
```
|
|
go get github.com/sashabaranov/go-gpt3
|
|
```
|
|
|
|
|
|
Example usage:
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
gogpt "github.com/sashabaranov/go-gpt3"
|
|
)
|
|
|
|
func main() {
|
|
c := gogpt.NewClient("your token")
|
|
ctx := context.Background()
|
|
|
|
req := gogpt.CompletionRequest{
|
|
Model: "ada",
|
|
MaxTokens: 5,
|
|
Prompt: "Lorem ipsum",
|
|
}
|
|
resp, err := c.CreateCompletion(ctx, req)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(resp.Choices[0].Text)
|
|
|
|
searchReq := gogpt.SearchRequest{
|
|
Documents: []string{"White House", "hospital", "school"},
|
|
Query: "the president",
|
|
}
|
|
searchResp, err := c.Search(ctx, "ada", searchReq)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(searchResp.SearchResults)
|
|
}
|
|
```
|