Skip to content

Commit

Permalink
chore: correct code samples and API reference link
Browse files Browse the repository at this point in the history
  • Loading branch information
0x9ef authored Jan 4, 2023
1 parent a1494ea commit 15d339d
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Golang OpenAI API Client

An Golang native implementation to easily interacting with OpenAI API.

https://beta.openai.com/docs/api-reference/

## Usage
Expand All @@ -23,22 +24,22 @@ If you want to use the most powerful model to generate text outputs, ensure that
#### Text edition
You can use the bundle Completion+Edit to regenerate the response based on the last context.
```go
e := openai.New(os.Getenv("OPENAI_KEY"))
ctx := context.Background()
completionResp, err := e.Completion(ctx, &openai.CompletionOptions{
// Choose model, you can see list of available models in models.go file
Model: openai.ModelTextDavinci001,
// Number of completion tokens to generate response. By default - 1024
MaxTokens: 1200,
// Text to completion
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
})

editResp, err := e.Edit(ctx, &EditOptions{
Model: ModelTextDavinci001,
Input: completionResp.Choices[0],
Instruction: "Please rewrite a bit more and add more information about Wikipedia in different aspects. Please build based on that for 4 topics",
})
e := openai.New(os.Getenv("OPENAI_KEY"))
ctx := context.Background()
completionResp, err := e.Completion(ctx, &openai.CompletionOptions{
// Choose model, you can see list of available models in models.go file
Model: openai.ModelTextDavinci001,
// Number of completion tokens to generate response. By default - 1024
MaxTokens: 1200,
// Text to completion
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
})

editResp, err := e.Edit(ctx, &EditOptions{
Model: ModelTextDavinci001,
Input: completionResp.Choices[0],
Instruction: "Please rewrite a bit more and add more information about Wikipedia in different aspects. Please build based on that for 4 topics",
})
```

### Text completion example
Expand All @@ -47,15 +48,15 @@ Given a prompt, the model will return one or more predicted completions.
**Note**: the default number of completion tokens is 1024, if you want to increase or decrease this limit, you should change `MaxTokens` parameter.

```go
e := openai.New(os.Getenv("OPENAI_KEY"))
r, err := e.Completion(context.Background(), &openai.CompletionOptions{
// Choose model, you can see list of available models in models.go file
Model: openai.ModelTextDavinci001,
// Number of completion tokens to generate response. By default - 1024
MaxTokens: 1200,
// Text to completion
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
})
e := openai.New(os.Getenv("OPENAI_KEY"))
r, err := e.Completion(context.Background(), &openai.CompletionOptions{
// Choose model, you can see list of available models in models.go file
Model: openai.ModelTextDavinci001,
// Number of completion tokens to generate response. By default - 1024
MaxTokens: 1200,
// Text to completion
Prompt: []string{"Write a little bit of Wikipedia. What is that?"},
})
```

You will get the next output:
Expand Down Expand Up @@ -162,13 +163,13 @@ You will get the next output:
To retrieve information about specified model instead of all models, you can do this:

```go
e := openai.New(os.Getenv("OPENAI_KEY"))
r, err := e.RetrieveModel(context.Background(), &openai.RetrieveModelOptions{
ID: openai.ModelDavinci,
})
if err != nil {
log.Fatal(err)
}
e := openai.New(os.Getenv("OPENAI_KEY"))
r, err := e.RetrieveModel(context.Background(), &openai.RetrieveModelOptions{
ID: openai.ModelDavinci,
})
if err != nil {
log.Fatal(err)
}
```

## License
Expand Down

0 comments on commit 15d339d

Please sign in to comment.