Spaces:
Sleeping
Sleeping
Harshana
commited on
Commit
·
efa9c6c
1
Parent(s):
372720a
some update
Browse files- agent.py +3 -6
- app.py +8 -3
- playground.ipynb +0 -0
- prompt/system_prompt.py +9 -0
agent.py
CHANGED
|
@@ -5,12 +5,9 @@ from retrievers import custom_retriever
|
|
| 5 |
from langgraph.graph import START, StateGraph, MessagesState
|
| 6 |
from langgraph.prebuilt import tools_condition, ToolNode
|
| 7 |
from langchain_core.messages import SystemMessage, HumanMessage
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
with open(settings.system_prompt_path, "r", encoding="utf-8") as f:
|
| 11 |
-
system_prompt = f.read()
|
| 12 |
-
|
| 13 |
-
sys_msg = SystemMessage(content=system_prompt)
|
| 14 |
|
| 15 |
def build_graph():
|
| 16 |
llm = get_llm(settings.llm_provider)
|
|
@@ -41,4 +38,4 @@ if __name__ == "__main__":
|
|
| 41 |
messages = [HumanMessage(content=question)]
|
| 42 |
results = graph.invoke({"messages": messages})
|
| 43 |
for m in results["messages"]:
|
| 44 |
-
print(m.content)
|
|
|
|
| 5 |
from langgraph.graph import START, StateGraph, MessagesState
|
| 6 |
from langgraph.prebuilt import tools_condition, ToolNode
|
| 7 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 8 |
+
from prompt.system_prompt import SYSTEM_PROMPT
|
| 9 |
|
| 10 |
+
sys_msg = SystemMessage(content=SYSTEM_PROMPT)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def build_graph():
|
| 13 |
llm = get_llm(settings.llm_provider)
|
|
|
|
| 38 |
messages = [HumanMessage(content=question)]
|
| 39 |
results = graph.invoke({"messages": messages})
|
| 40 |
for m in results["messages"]:
|
| 41 |
+
print(m.content)
|
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -13,11 +15,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from langchain_core.messages import HumanMessage
|
| 7 |
+
from agent import build_graph
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
+
self.graph = build_graph()
|
| 19 |
+
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
+
messages = [HumanMessage(content=question)]
|
| 23 |
+
messages = self.graph.invoke({"messages": messages})
|
| 24 |
+
answer = messages['messages'][-1].content
|
| 25 |
+
return answer[14:]
|
| 26 |
|
| 27 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 28 |
"""
|
playground.ipynb
ADDED
|
File without changes
|
prompt/system_prompt.py
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# prompt/system_prompt.py
|
| 2 |
+
|
| 3 |
+
SYSTEM_PROMPT = """
|
| 4 |
+
You are a helpful assistant tasked with answering questions using a set of tools.
|
| 5 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 6 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 7 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 8 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|
| 9 |
+
"""
|