Skip to content

Commit

Permalink
examples: Correct API key usage for Groq integration (#893)
Browse files Browse the repository at this point in the history
Correct API key usage for Groq integration
  • Loading branch information
Ashad001 authored Jun 16, 2024
1 parent 6a285bf commit e380482
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/groq-completion-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ require github.com/tmc/langchaingo v0.1.10
require (
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
)
2 changes: 2 additions & 0 deletions examples/groq-completion-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAcUsw=
github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
10 changes: 10 additions & 0 deletions examples/groq-completion-example/groq_completion_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ import (
"context"
"fmt"
"log"
"os"

"github.com/joho/godotenv"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)

func main() {
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}

apiKey := os.Getenv("GROQ_API_KEY")

llm, err := openai.New(
openai.WithModel("llama3-8b-8192"),
openai.WithBaseURL("https://api.groq.com/openai/v1"),
openai.WithToken(apiKey),
)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit e380482

Please sign in to comment.