Spaces:
Sleeping
Sleeping
Miguel Figueiredo Marques commited on
Commit ·
453c536
1
Parent(s): 92272e4
tryfix2
Browse files
app.py
CHANGED
|
@@ -22,8 +22,7 @@ load_dotenv()
|
|
| 22 |
# --- Constants ---
|
| 23 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 24 |
# Main reasoning + tool-calling model (Groq free tier). Swap if a model is retired.
|
| 25 |
-
|
| 26 |
-
MODEL_NAME = os.getenv("GROQ_MODEL", "llama-3.1-70b-versatile")
|
| 27 |
# Vision model for image questions (best-effort; update id if Groq retires it).
|
| 28 |
VISION_MODEL = os.getenv("GROQ_VISION_MODEL", "meta-llama/llama-4-scout-17b-16e-instruct")
|
| 29 |
# Seconds to pause between questions to stay under Groq free-tier rate limits.
|
|
@@ -212,8 +211,8 @@ TOOLS = [
|
|
| 212 |
|
| 213 |
def build_graph():
|
| 214 |
"""Build a simple assistant <-> tools LangGraph agent."""
|
| 215 |
-
llm = ChatGroq(model=MODEL_NAME, temperature=0)
|
| 216 |
-
llm_with_tools = llm.bind_tools(TOOLS)
|
| 217 |
|
| 218 |
def assistant(state: MessagesState):
|
| 219 |
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
|
@@ -269,7 +268,7 @@ class BasicAgent:
|
|
| 269 |
# Retries exhausted — fall back to a direct no-tools LLM call
|
| 270 |
print("Tool calls keep failing; falling back to direct LLM (no tools).")
|
| 271 |
try:
|
| 272 |
-
llm = ChatGroq(model=MODEL_NAME, temperature=0)
|
| 273 |
direct = llm.invoke(messages)
|
| 274 |
answer = extract_final_answer(direct.content)
|
| 275 |
print(f"Fallback returning: {answer[:120]}")
|
|
|
|
| 22 |
# --- Constants ---
|
| 23 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 24 |
# Main reasoning + tool-calling model (Groq free tier). Swap if a model is retired.
|
| 25 |
+
MODEL_NAME = os.getenv("GROQ_MODEL", "llama-3.3-70b-versatile")
|
|
|
|
| 26 |
# Vision model for image questions (best-effort; update id if Groq retires it).
|
| 27 |
VISION_MODEL = os.getenv("GROQ_VISION_MODEL", "meta-llama/llama-4-scout-17b-16e-instruct")
|
| 28 |
# Seconds to pause between questions to stay under Groq free-tier rate limits.
|
|
|
|
| 211 |
|
| 212 |
def build_graph():
|
| 213 |
"""Build a simple assistant <-> tools LangGraph agent."""
|
| 214 |
+
llm = ChatGroq(model=MODEL_NAME, temperature=0, max_tokens=4096)
|
| 215 |
+
llm_with_tools = llm.bind_tools(TOOLS, tool_choice="auto")
|
| 216 |
|
| 217 |
def assistant(state: MessagesState):
|
| 218 |
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
|
|
|
| 268 |
# Retries exhausted — fall back to a direct no-tools LLM call
|
| 269 |
print("Tool calls keep failing; falling back to direct LLM (no tools).")
|
| 270 |
try:
|
| 271 |
+
llm = ChatGroq(model=MODEL_NAME, temperature=0, max_tokens=4096)
|
| 272 |
direct = llm.invoke(messages)
|
| 273 |
answer = extract_final_answer(direct.content)
|
| 274 |
print(f"Fallback returning: {answer[:120]}")
|