Spaces:
Sleeping
Sleeping
commit
Browse filesFiles changed (2)
- app.py+13-42
- requirements.txt+1-2
4 unmodified lines5678910111226 unmodified lines394041424344454647484923 unmodified lines737475767778798081828384858687888990919293947 unmodified lines1021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401414 unmodified linesimport pandas as pdfrom typing import TypedDictfrom langgraph.graph import StateGraph, START, ENDfrom langchain_core.messages import HumanMessagefrom langchain_openai import ChatOpenAI# (Keep Constants as is)# --- Constants ---26 unmodified lines- Agent ์ ์ฒด์์ ๋์ผํ "๋๋"๋ฅผ ๊ณต์ ํ๋ ๊ฐ๋ """llm = ChatOpenAI(model="Qwen/Qwen3-4B-Instruct",base_url="https://api-inference.huggingface.co/v1",api_key=os.getenv("HF_TOKEN"),temperature=0)23 unmodified lines- LangGraph ๊ตฌ์กฐ ์๊ฑด ์ถฉ์กฑ- GAIA Level 1 ์ ์ถ ๊ฐ๋ฅ"""# ํ์ฌ ์ํ์์ ์ง๋ฌธ ์ถ์ถquestion = state["question"]# ํ๋กฌํํธ ์ค๊ณ"""ํ๋กฌํํธ์์ ๊ฐ์ฅ ์ค์ํ ํฌ์ธํธ- "ONLY the final answer"๋ฅผ ๋ช ์์ ์ผ๋ก ๊ฐ์ - ์ค๋ช /ํ์/๋ถํ์ํ ํ ์คํธ ๊ธ์ง- ๋ชจ๋ธ์ด '์น์ ํ๊ฒ ์ค๋ช ํ๋ ค๋ ์ต๊ด'์ ์ฐจ๋จ์ด ๋ถ๋ถ์ด ์ฝํ๋ฉด์ ๋ต์ ๋ง์๋ ํ์ ์ค๋ฅ๋ก 0์ """prompt = f"""You are solving a GAIA benchmark question.7 unmodified lines{question}""".strip()# LLM ํธ์ถ"""LangChain์์๋ LLM์ ๋ฉ์์ง ๋ฆฌ์คํธ๋ก ํธ์ถํ๋ค.์ฌ๊ธฐ์๋ ๊ฐ์ฅ ๋จ์ํ HumanMessage 1๊ฐ๋ง ์ฌ์ฉ."""response = llm.invoke([HumanMessage(content=prompt)])# ๋ต๋ณ ํ์ฒ๋ฆฌanswer = response.content.strip()# ํํ ์ ๋์ด ์ ๊ฑฐanswer = answer.replace("Answer:", "").replace("Final answer:", "").strip()# ์ฌ๋ฌ ์ค ์ถ๋ ฅ ๋ฐฉ์ง (์ฒซ ์ค๋ง ์ฌ์ฉ)answer = answer.splitlines()[0].strip()# ๋ถํ์ํ ๋ฐ์ดํ ์ ๊ฑฐ ("Paris" โ Paris)answer = answer.strip('"\'')# State ์ ๋ฐ์ดํธ ๋ฐํ"""LangGraph์ ๊ท์น:- Node๋ "State ์ ์ฒด"๋ฅผ ๋ฐํํ์ง ์๋๋ค- ์์ ํ ํ๋๋ง dict๋ก ๋ฐํ- LangGraph๊ฐ ์๋์ผ๋ก ๋ณํฉ"""return {# strip()์ EXACT MATCH๋ฅผ ์ํ ์์ ์ฅ์น"answer": answer}# 5. LangGraph ๊ทธ๋ํ ๊ตฌ์ฑ"""Agent์ ์ฌ๊ณ ํ๋ฆ์ ๊ทธ๋ํ๋ก ์ ์ํ๋ค.4 unmodified lines56789101126 unmodified lines38394041424344454647484923 unmodified lines73747576777879807 unmodified lines8889909192939495969798991001011021031041051061071081091101111124 unmodified linesimport pandas as pdfrom typing import TypedDictfrom langgraph.graph import StateGraph, START, ENDfrom langchain_huggingface import HuggingFaceEndpoint# (Keep Constants as is)# --- Constants ---26 unmodified lines- Agent ์ ์ฒด์์ ๋์ผํ "๋๋"๋ฅผ ๊ณต์ ํ๋ ๊ฐ๋ """llm = HuggingFaceEndpoint(repo_id="Qwen/Qwen3-4B",huggingfacehub_api_token=os.getenv("HF_TOKEN"),temperature=0,max_new_tokens=64,stop=["\n"])23 unmodified lines- LangGraph ๊ตฌ์กฐ ์๊ฑด ์ถฉ์กฑ- GAIA Level 1 ์ ์ถ ๊ฐ๋ฅ"""question = state["question"]prompt = f"""You are solving a GAIA benchmark question.7 unmodified lines{question}""".strip()# HF Endpoint๋ ๋ฌธ์์ด prompt๋ง ๋ฐ์response = llm.invoke(prompt)# HF Endpoint๋ ๋ฌธ์์ด์ ๋ฐํanswer = response.strip()# ํํ ์ ๋์ด ์ ๊ฑฐanswer = answer.replace("Answer:", "").replace("Final answer:", "").strip()# ์ฌ๋ฌ ์ค ์ถ๋ ฅ ๋ฐฉ์ง (์ฒซ ์ค๋ง ์ฌ์ฉ)answer = answer.splitlines()[0].strip()# ๋ถํ์ํ ๋ฐ์ดํ ์ ๊ฑฐanswer = answer.strip('"\'')return {"answer": answer}# 5. LangGraph ๊ทธ๋ํ ๊ตฌ์ฑ"""Agent์ ์ฌ๊ณ ํ๋ฆ์ ๊ทธ๋ํ๋ก ์ ์ํ๋ค.
12345gradiorequestslanggraphlangchain_openailangchain_core1234gradiorequestslanggraphlangchain_huggingface
app.py+13-42
requirements.txt+1-2