Naman Gupta commited on
Commit
f778bee
·
1 Parent(s): ab90fa0

add Groq client setup — one place to rule all API calls

Browse files

Pulled the API connection out into its own file so every module
imports from the same source. Change the model or swap providers?
Edit one file, done.

Files changed (1) hide show
  1. llm/client.py +20 -0
llm/client.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # client.py
2
+ # ---------
3
+ # This is the single place where we set up our connection to Groq's API.
4
+ # Every other file in llm/ imports `groq` and `model` from here — so if
5
+ # you ever want to swap to a different model or provider, just change it here.
6
+
7
+ import os
8
+ from openai import OpenAI
9
+
10
+ # Pull credentials from environment variables (.env file).
11
+ # Never hardcode keys in source code.
12
+ groq_api_key = os.environ.get("GROQ_API_KEY", "")
13
+ model = os.environ.get("MODEL_NAME", "llama-3.1-8b-instant")
14
+
15
+ # Groq's API is fully compatible with the OpenAI SDK — we just point it
16
+ # at Groq's base URL instead of OpenAI's.
17
+ groq = OpenAI(
18
+ base_url="https://api.groq.com/openai/v1",
19
+ api_key=groq_api_key,
20
+ )