Skip to content

Commit 47887bf

Browse files
authored
Rename and update docs (#120)
1 parent 202b629 commit 47887bf

11 files changed

+125
-25
lines changed

README.md

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
# go-gpt3
2-
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/sashabaranov/go-gpt3)
3-
[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-gpt3)](https://goreportcard.com/report/github.com/sashabaranov/go-gpt3)
1+
# Go OpenAI
2+
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/sashabaranov/go-openai)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-openai)](https://goreportcard.com/report/github.com/sashabaranov/go-openai)
44

55

6-
[OpenAI ChatGPT](https://platform.openai.com/), GPT-3, DALL·E 2, and Whisper API client for Go
6+
This library provides Go clients for [OpenAI API](https://platform.openai.com/). We support:
7+
8+
* ChatGPT
9+
* GPT-3
10+
* DALL·E 2
11+
* Whisper
712

813
Installation:
914
```
10-
go get github.com/sashabaranov/go-gpt3
15+
go get github.com/sashabaranov/go-openai
1116
```
1217

1318

14-
Example usage:
19+
ChatGPT example usage:
1520

1621
```go
1722
package main
@@ -22,6 +27,48 @@ import (
2227
gogpt "github.com/sashabaranov/go-gpt3"
2328
)
2429

30+
func main() {
31+
c := gogpt.NewClient("your token")
32+
ctx := context.Background()
33+
34+
resp, err := c.CreateChatCompletion(
35+
ctx,
36+
gogpt.ChatCompletionRequest{
37+
Model: gogpt.GPT3Dot5Turbo,
38+
Messages: []gogpt.ChatCompletionMessage{
39+
{
40+
Role: "user",
41+
Content: "Hello!",
42+
},
43+
},
44+
},
45+
)
46+
47+
if err != nil {
48+
return
49+
}
50+
51+
fmt.Println(resp.Choices[0].Message.Content)
52+
}
53+
54+
```
55+
56+
57+
58+
Other examples:
59+
60+
<details>
61+
<summary>GPT-3 completion</summary>
62+
63+
```go
64+
package main
65+
66+
import (
67+
"context"
68+
"fmt"
69+
gogpt "github.com/sashabaranov/go-openai"
70+
)
71+
2572
func main() {
2673
c := gogpt.NewClient("your token")
2774
ctx := context.Background()
@@ -38,8 +85,10 @@ func main() {
3885
fmt.Println(resp.Choices[0].Text)
3986
}
4087
```
88+
</details>
4189

42-
Streaming response example:
90+
<details>
91+
<summary>GPT-3 streaming completion</summary>
4392

4493
```go
4594
package main
@@ -49,7 +98,57 @@ import (
4998
"context"
5099
"fmt"
51100
"io"
52-
gogpt "github.com/sashabaranov/go-gpt3"
101+
gogpt "github.com/sashabaranov/go-openai"
102+
)
103+
104+
func main() {
105+
c := gogpt.NewClient("your token")
106+
ctx := context.Background()
107+
108+
req := gogpt.CompletionRequest{
109+
Model: gogpt.GPT3Ada,
110+
MaxTokens: 5,
111+
Prompt: "Lorem ipsum",
112+
Stream: true,
113+
}
114+
stream, err := c.CreateCompletionStream(ctx, req)
115+
if err != nil {
116+
return
117+
}
118+
defer stream.Close()
119+
120+
for {
121+
response, err := stream.Recv()
122+
if errors.Is(err, io.EOF) {
123+
fmt.Println("Stream finished")
124+
return
125+
}
126+
127+
if err != nil {
128+
fmt.Printf("Stream error: %v\n", err)
129+
return
130+
}
131+
132+
133+
fmt.Printf("Stream response: %v\n", response)
134+
}
135+
}
136+
```
137+
</details>
138+
139+
140+
<details>
141+
<summary>GPT-3 streaming completion</summary>
142+
143+
```go
144+
package main
145+
146+
import (
147+
"errors"
148+
"context"
149+
"fmt"
150+
"io"
151+
gogpt "github.com/sashabaranov/go-openai"
53152
)
54153

55154
func main() {
@@ -85,3 +184,4 @@ func main() {
85184
}
86185
}
87186
```
187+
</details>

api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
4+
. "github.com/sashabaranov/go-openai"
55

66
"context"
77
"errors"

audio_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"path/filepath"
1212
"strings"
1313

14-
. "github.com/sashabaranov/go-gpt3"
15-
"github.com/sashabaranov/go-gpt3/internal/test"
14+
. "github.com/sashabaranov/go-openai"
15+
"github.com/sashabaranov/go-openai/internal/test"
1616

1717
"context"
1818
"testing"

completion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
5-
"github.com/sashabaranov/go-gpt3/internal/test"
4+
. "github.com/sashabaranov/go-openai"
5+
"github.com/sashabaranov/go-openai/internal/test"
66

77
"context"
88
"encoding/json"

edits_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
5-
"github.com/sashabaranov/go-gpt3/internal/test"
4+
. "github.com/sashabaranov/go-openai"
5+
"github.com/sashabaranov/go-openai/internal/test"
66

77
"context"
88
"encoding/json"

embeddings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
4+
. "github.com/sashabaranov/go-openai"
55

66
"bytes"
77
"encoding/json"

files_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
5-
"github.com/sashabaranov/go-gpt3/internal/test"
4+
. "github.com/sashabaranov/go-openai"
5+
"github.com/sashabaranov/go-openai/internal/test"
66

77
"context"
88
"encoding/json"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/sashabaranov/go-gpt3
1+
module github.com/sashabaranov/go-openai
22

33
go 1.17

image_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
5-
"github.com/sashabaranov/go-gpt3/internal/test"
4+
. "github.com/sashabaranov/go-openai"
5+
"github.com/sashabaranov/go-openai/internal/test"
66

77
"context"
88
"encoding/json"

moderation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gogpt_test
22

33
import (
4-
. "github.com/sashabaranov/go-gpt3"
5-
"github.com/sashabaranov/go-gpt3/internal/test"
4+
. "github.com/sashabaranov/go-openai"
5+
"github.com/sashabaranov/go-openai/internal/test"
66

77
"context"
88
"encoding/json"

0 commit comments

Comments
 (0)