go sdk https://github.com/sashabaranov/go-openai

天问 24df687c48 Update 'README.md' 1 year ago
README.md 24df687c48 Update 'README.md' 1 year ago

README.md

go-openai

go sdk, 支持gpt3,4,dall-e, whisper 所有openai服务

Usage

go get github.com/sashabaranov/go-openai 


package main

import (
	"context"
	"fmt"
	openai "github.com/sashabaranov/go-openai"
)

func main() {
	client := openai.NewClient("your token")
	resp, err := client.CreateChatCompletion(
		context.Background(),
		openai.ChatCompletionRequest{
			Model: openai.GPT3Dot5Turbo,
			Messages: []openai.ChatCompletionMessage{
				{
					Role:    openai.ChatMessageRoleUser,
					Content: "Hello!",
				},
			},
		},
	)

	if err != nil {
		fmt.Printf("ChatCompletion error: %v\n", err)
		return
	}

	fmt.Println(resp.Choices[0].Message.Content)
}