Skip to content
/ groq Public

A community maintained Go library for the groq.com API

License

Notifications You must be signed in to change notification settings

jpoz/groq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

groq.com golang library

Description

github.com/jpoz/groq is community maintained Go library for the groq.com API.

Installation

To install groq, run the following command in your terminal:

go get -u github.com/jpoz/groq

Features

  • Synchronous Chat completions
  • Streaming Chat completions
  • Zero dependencies

Examples

client := groq.NewClient() // will load API key from GROQ_API_KEY environment variable
client := groq.NewClient(WithAPIKey("YOUR_API_KEY"))

response, err := client.CreateChatCompletion(groq.CompletionCreateParams{
    Model: "llama3-8b-8192",
    Messages: []groq.Message{
        {
            Role:    "user",
            Content: "What is the meaning of life?",
        },
    },
})
if err != nil {
    panic(err)
}

println(response.Choices[0].Message.Content)

Streaming chat completions

client := groq.NewClient(WithAPIKey("YOUR_API_KEY"))

chatCompletion, err := client.CreateChatCompletion(groq.CompletionCreateParams{
    Model: "llama3-70b-8192",
    Messages: []groq.Message{
        {
            Role:    "user",
            Content: "What is the meaning of life?",
        },
    },
    Stream:      true,
})
if err != nil {
    panic(err)
}

for delta := range chatCompletion.Stream {
    fmt.Print(delta.Choices[0].Delta.Content)
}

fmt.Print("\n")

About

A community maintained Go library for the groq.com API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages