repositorypackage
0.0.5
Repository: https://github.com/akadotsh/groq-go-sdk.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
IMPORTANT: This is an unofficial, community-developed Groq client library for Go. It is not affiliated with, officially maintained, or endorsed by Groq Inc.
Groq Go SDK
Go client library for interacting with the Groq API.
Installation
go get github.com/akadotsh/groq-go-sdk
Usage
- Get an API key from https://console.groq.com/keys
- Set the API key as an environment variable named
groq_api_key
.
package main
import (
"fmt"
"log"
"os"
"github.com/akadotsh/groq-go-sdk"
"github.com/joho/godotenv"
)
func main() {
// Load environment variables from .env file
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
// Get the API key from environment variables
groqAPIKey := os.Getenv("GROQ_API_KEY")
if groqAPIKey == "" {
log.Fatal("GROQ_API_KEY not set in environment variables")
}
// Initialize the Groq client
client := groq.New(groqAPIKey)
if client == nil {
log.Fatal("Failed to create Groq client")
}
// Prepare the chat request
chat := groq.Chat{
Messages: []groq.Message{
{
Role: groq.User,
Content: "Explain the importance of fast language models",
},
},
Model: groq.Mixtral_8x7b_32768,
}
// Send a chat request
response, err := client.Chat(chat)
if err != nil {
log.Fatalf("Error calling Chat: %v", err)
}
// Print the response
fmt.Println(response)
}