File size: 949 Bytes
f778bee
 
 
 
 
 
 
 
f61eeae
 
 
 
 
 
f778bee
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# client.py
# ---------
# This is the single place where we set up our connection to Groq's API.
# Every other file in llm/ imports `groq` and `model` from here — so if
# you ever want to swap to a different model or provider, just change it here.

import os
from openai import OpenAI
from dotenv import load_dotenv

# Load .env into os.environ so os.environ.get() picks up the keys.
# pydantic-settings reads .env into the Settings object only —
# it does NOT set os.environ, so we need this explicit call.
load_dotenv()

# Pull credentials from environment variables (.env file).
# Never hardcode keys in source code.
groq_api_key = os.environ.get("GROQ_API_KEY", "")
model        = os.environ.get("MODEL_NAME", "llama-3.1-8b-instant")

# Groq's API is fully compatible with the OpenAI SDK — we just point it
# at Groq's base URL instead of OpenAI's.
groq = OpenAI(
    base_url="https://api.groq.com/openai/v1",
    api_key=groq_api_key,
)