Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zzzzer91/chatgpt-go

An unofficial Go SDK for ChatGPT.
https://github.com/zzzzer91/chatgpt-go

Last synced: 4 days ago
JSON representation

An unofficial Go SDK for ChatGPT.

Awesome Lists containing this project

README

        

# ChatGPT go client

Usage:

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