Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 555 Bytes

README.md

File metadata and controls

28 lines (24 loc) · 555 Bytes

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)
	}
}