Rename and update docs (#120)
This commit is contained in:
116
README.md
116
README.md
@@ -1,17 +1,22 @@
|
||||
# go-gpt3
|
||||
[](https://godoc.org/github.com/sashabaranov/go-gpt3)
|
||||
[](https://goreportcard.com/report/github.com/sashabaranov/go-gpt3)
|
||||
# Go OpenAI
|
||||
[](https://godoc.org/github.com/sashabaranov/go-openai)
|
||||
[](https://goreportcard.com/report/github.com/sashabaranov/go-openai)
|
||||
|
||||
|
||||
[OpenAI ChatGPT](https://platform.openai.com/), GPT-3, DALL·E 2, and Whisper API client for Go
|
||||
This library provides Go clients for [OpenAI API](https://platform.openai.com/). We support:
|
||||
|
||||
* ChatGPT
|
||||
* GPT-3
|
||||
* DALL·E 2
|
||||
* Whisper
|
||||
|
||||
Installation:
|
||||
```
|
||||
go get github.com/sashabaranov/go-gpt3
|
||||
go get github.com/sashabaranov/go-openai
|
||||
```
|
||||
|
||||
|
||||
Example usage:
|
||||
ChatGPT example usage:
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -22,6 +27,48 @@ import (
|
||||
gogpt "github.com/sashabaranov/go-gpt3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := gogpt.NewClient("your token")
|
||||
ctx := context.Background()
|
||||
|
||||
resp, err := c.CreateChatCompletion(
|
||||
ctx,
|
||||
gogpt.ChatCompletionRequest{
|
||||
Model: gogpt.GPT3Dot5Turbo,
|
||||
Messages: []gogpt.ChatCompletionMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Hello!",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(resp.Choices[0].Message.Content)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
Other examples:
|
||||
|
||||
<details>
|
||||
<summary>GPT-3 completion</summary>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
gogpt "github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := gogpt.NewClient("your token")
|
||||
ctx := context.Background()
|
||||
@@ -38,8 +85,10 @@ func main() {
|
||||
fmt.Println(resp.Choices[0].Text)
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
Streaming response example:
|
||||
<details>
|
||||
<summary>GPT-3 streaming completion</summary>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -49,7 +98,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
gogpt "github.com/sashabaranov/go-gpt3"
|
||||
gogpt "github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -85,3 +134,54 @@ func main() {
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>GPT-3 streaming completion</summary>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
gogpt "github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := gogpt.NewClient("your token")
|
||||
ctx := context.Background()
|
||||
|
||||
req := gogpt.CompletionRequest{
|
||||
Model: gogpt.GPT3Ada,
|
||||
MaxTokens: 5,
|
||||
Prompt: "Lorem ipsum",
|
||||
Stream: true,
|
||||
}
|
||||
stream, err := c.CreateCompletionStream(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
for {
|
||||
response, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
fmt.Println("Stream finished")
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Stream error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fmt.Printf("Stream response: %v\n", response)
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
||||
module github.com/sashabaranov/go-gpt3
|
||||
module github.com/sashabaranov/go-openai
|
||||
|
||||
go 1.17
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gogpt_test
|
||||
|
||||
import (
|
||||
. "github.com/sashabaranov/go-gpt3"
|
||||
"github.com/sashabaranov/go-gpt3/internal/test"
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
Reference in New Issue
Block a user