File size: 831 Bytes
c27eaf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e506a23
 
c27eaf1
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
"""Groq LLM setup via LangChain."""

from __future__ import annotations

import os

from dotenv import load_dotenv
from langchain_groq import ChatGroq

# Load .env from project root
load_dotenv(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".env"))

_GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")

if not _GROQ_API_KEY or _GROQ_API_KEY == "your_groq_api_key_here":
    raise RuntimeError(
        "GROQ_API_KEY is not set. "
        "Please add your key to the .env file in the project root, "
        "or set it as a Secret in your Hugging Face Space settings."
    )

# Shared LLM instance – llama-3.3-70b-versatile on Groq for speed + quality
llm = ChatGroq(
    model="llama-3.3-70b-versatile",
    api_key=_GROQ_API_KEY,
    temperature=0.5,
    max_tokens=2048,
    request_timeout=30,
    max_retries=1,
)