Skip to content

zzzzer91/chatgpt-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatGPT go client

Usage:

func main() {
	secretKey := ""
	cli := chatgpt.NewService(secretKey, chatgpt.WithHost("api.openai.com"), chatgpt.WithTimeout(15*time.Second))
	msgs := []*Message{
		{Role: RoleTypeUser, Content: "who are you"},
	}

	ctx := context.Background()
	resp, err := cli.Chat(ctx, msgs)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Choices[0].Message.Content)

	err = s.ChatStream(ctx, msgs, func(resp *ChatResponse) error {
		fmt.Print(resp.Choices[0].Delta.Content)
		return nil
	})
	if err != nil {
		panic(err)
	}
}

About

An unofficial Go SDK for ChatGPT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages