Add Readme example to example_test.go (#298)
* 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
This commit is contained in:
28
examples/images/main.go
Normal file
28
examples/images/main.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
|
||||
|
||||
respUrl, err := client.CreateImage(
|
||||
context.Background(),
|
||||
openai.ImageRequest{
|
||||
Prompt: "Parrot on a skateboard performs a trick, cartoon style, natural light, high detail",
|
||||
Size: openai.CreateImageSize256x256,
|
||||
ResponseFormat: openai.CreateImageResponseFormatURL,
|
||||
N: 1,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("Image creation error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(respUrl.Data[0].URL)
|
||||
}
|
||||
Reference in New Issue
Block a user