Go SDK
Chat Completion
package main
import (
"context"
"fmt"
"os"
"github.com/joho/godotenv"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
apiKey := os.Getenv("API_KEY")
apiUrl := os.Getenv("API_URL")
client := openai.NewClient(
option.WithBaseURL(apiUrl),
option.WithAPIKey(apiKey),
)
response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Model: "gpt-3.5-turbo",
Messages: []openai.ChatCompletionMessageParamUnion{
openai.UserMessage("how many letters 'r' in the word 'strawberry'"),
},
})
if err != nil {
panic(err)
}
fmt.Println(response.Choices[0].Message.Content)
}Audio Generation
Audio Transcription
Audio Translation
Image Generation
Last updated

