* Add speech to text example in docs * Add caption formats for audio transcription * Add caption example to README * Address sanity check errors * Add tests for decodeResponse * Use typechecker for audio response format * Decoding response refactors * Migrated examples to example_test.go * Add some executable examples * Update error docs * Avoid linting example files which break conventions * Restore README examples * Enable linting for example_test
27 lines
444 B
Go
27 lines
444 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
func main() {
|
|
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
|
|
resp, err := client.CreateCompletion(
|
|
context.Background(),
|
|
openai.CompletionRequest{
|
|
Model: openai.GPT3Ada,
|
|
MaxTokens: 5,
|
|
Prompt: "Lorem ipsum",
|
|
},
|
|
)
|
|
if err != nil {
|
|
fmt.Printf("Completion error: %v\n", err)
|
|
return
|
|
}
|
|
fmt.Println(resp.Choices[0].Text)
|
|
}
|