Skip to content

Commit 8b48694

Browse files
committed
chore: add more information to README
1 parent 84470a7 commit 8b48694

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

readme.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,53 @@ An Golang native implementation to easily interacting with OpenAI API.
66

77
You can use environment variable to store API secret key
88
```
9-
export OPENAPI_KEY=YOUR_KEY
9+
export OPENAI_KEY=[YOUR_KEY]
1010
```
1111

1212
To initialize engine, use this:
1313
```go
14-
e := openai.New(os.Getenv("OPENAPI_KEY"))
14+
e := openai.New(os.Getenv("OPENAI_KEY"))
1515
```
1616

17+
### Tips
18+
19+
#### Model
20+
If you want to use the most powerful model to generate text outputs, ensure that you are using "text-davinci-003". This model is defined as constant `openai.ModelTextDavinci003`.
21+
22+
#### Text edition
23+
You can use the bundle Completion+Edit to regenerate the response based on the last context.
24+
```go
25+
e := openai.New(os.Getenv("OPENAI_KEY"))
26+
ctx := context.Background()
27+
completionResp, err := e.Completion(ctx, &openai.CompletionOptions{
28+
// Choose model, you can see list of available models in models.go file
29+
Model: openai.ModelTextDavinci001,
30+
// Number of completion tokens to generate response. By default - 1024
31+
MaxTokens: 1200,
32+
// Text to completion
33+
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
34+
})
35+
36+
editResp, err := e.Edit(ctx, &EditOptions{
37+
Model: ModelTextDavinci001,
38+
Input: completionResp.Choices[0],
39+
Instruction: "Please rewrite a bit more and add more information about Wikipedia in different aspects. Please build based on that for 4 topics",
40+
})
41+
```
42+
1743
### Text completion example
18-
Given a prompt, the model will return one or more predicted completions.
44+
Given a prompt, the model will return one or more predicted completions.
45+
46+
**Note**: the default number of completion tokens is 1024, if you want to increase or decrease this limit, you should change `MaxTokens` parameter.
1947

2048
```go
21-
e := openai.New(os.Getenv("OPENAPI_KEY"))
49+
e := openai.New(os.Getenv("OPENAI_KEY"))
2250
r, err := e.Completion(context.Background(), &openai.CompletionOptions{
23-
// Choose model, you can see list of available models in models.go file
51+
// Choose model, you can see list of available models in models.go file
2452
Model: openai.ModelTextDavinci001,
25-
// Text to completion
53+
// Number of completion tokens to generate response. By default - 1024
54+
MaxTokens: 1200,
55+
// Text to completion
2656
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
2757
})
2858
```
@@ -70,7 +100,7 @@ import (
70100
)
71101

72102
func main() {
73-
e := openai.New(os.Getenv("OPENAPI_KEY"))
103+
e := openai.New(os.Getenv("OPENAI_KEY"))
74104
r, err := e.Completion(context.Background(), &openai.CompletionOptions{
75105
// Choose model, you can see list of available models in models.go file
76106
Model: openai.ModelTextDavinci001,
@@ -93,7 +123,7 @@ func main() {
93123
Lists the currently available models, and provides basic information about each one such as the owner and availability.
94124

95125
```go
96-
e := openai.New(os.Getenv("OPENAPI_KEY"))
126+
e := openai.New(os.Getenv("OPENAI_KEY"))
97127
r, err := e.ListModels(context.Background())
98128
if err != nil {
99129
log.Fatal(err)
@@ -127,12 +157,12 @@ You will get the next output:
127157
...
128158
]
129159
}
130-
```
160+
```
131161

132162
To retrieve information about specified model instead of all models, you can do this:
133163

134164
```go
135-
e := openai.New(os.Getenv("OPENAPI_KEY"))
165+
e := openai.New(os.Getenv("OPENAI_KEY"))
136166
r, err := e.RetrieveModel(context.Background(), &openai.RetrieveModelOptions{
137167
ID: openai.ModelDavinci,
138168
})

0 commit comments

Comments
 (0)