Update app.py
Browse files
app.py
CHANGED
|
@@ -13,12 +13,11 @@ import requests
|
|
| 13 |
import inspect
|
| 14 |
import pandas as pd
|
| 15 |
import markdownify
|
| 16 |
-
from yaml import safe_load
|
| 17 |
-
from pathlib import Path
|
| 18 |
from typing import Literal, TypedDict, get_args
|
| 19 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 20 |
from langchain_openai import ChatOpenAI
|
| 21 |
from langgraph.graph import END, StateGraph
|
|
|
|
| 22 |
from tools import (
|
| 23 |
web_search,
|
| 24 |
wikipedia_search,
|
|
@@ -29,16 +28,6 @@ from tools import (
|
|
| 29 |
read_task_file
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 34 |
-
OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
| 35 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 36 |
-
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 37 |
-
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 38 |
-
|
| 39 |
-
CURRENT_DIR = Path(__file__).parent
|
| 40 |
-
_PROMPTS = safe_load(CURRENT_DIR.joinpath("prompts.yaml").read_text())
|
| 41 |
-
|
| 42 |
# ---------------------------------------------------------------------------
|
| 43 |
# Model fallback chain (primary → backup → last-resort)
|
| 44 |
# ---------------------------------------------------------------------------
|
|
@@ -85,10 +74,6 @@ def _download_task_file(task_id: str, api_url: str = DEFAULT_API_URL) -> tuple[b
|
|
| 85 |
return b"", ""
|
| 86 |
return resp.content, resp.headers.get("content-type", "").lower()
|
| 87 |
|
| 88 |
-
def get_prompt(prompt_key: str, **kwargs: str) -> str:
|
| 89 |
-
"""Get a prompt by key and fill in placeholders via `.format(**kwargs)`"""
|
| 90 |
-
return _PROMPTS[prompt_key].format(**kwargs)
|
| 91 |
-
|
| 92 |
class AgentState(TypedDict):
|
| 93 |
question: str
|
| 94 |
label: str
|
|
|
|
| 13 |
import inspect
|
| 14 |
import pandas as pd
|
| 15 |
import markdownify
|
|
|
|
|
|
|
| 16 |
from typing import Literal, TypedDict, get_args
|
| 17 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 18 |
from langchain_openai import ChatOpenAI
|
| 19 |
from langgraph.graph import END, StateGraph
|
| 20 |
+
from config import DEFAULT_API_URL, HF_TOKEN, GROQ_API_KEY, OPENROUTER_API_KEY, get_prompt
|
| 21 |
from tools import (
|
| 22 |
web_search,
|
| 23 |
wikipedia_search,
|
|
|
|
| 28 |
read_task_file
|
| 29 |
)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# ---------------------------------------------------------------------------
|
| 32 |
# Model fallback chain (primary → backup → last-resort)
|
| 33 |
# ---------------------------------------------------------------------------
|
|
|
|
| 74 |
return b"", ""
|
| 75 |
return resp.content, resp.headers.get("content-type", "").lower()
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
class AgentState(TypedDict):
|
| 78 |
question: str
|
| 79 |
label: str
|