CheeYung commited on
Commit
3a0914e
·
1 Parent(s): 2b4b9c0

Using groq for summary

Browse files
Files changed (4) hide show
  1. agent.py +11 -8
  2. app.py +4 -1
  3. prompt.txt +5 -49
  4. requirements.txt +1 -0
agent.py CHANGED
@@ -13,7 +13,8 @@ from langchain_community.tools.tavily_search import TavilySearchResults
13
  from langchain_community.document_loaders import WikipediaLoader
14
  from langchain_community.document_loaders import ArxivLoader
15
 
16
- from langchain_google_genai import ChatGoogleGenerativeAI
 
17
 
18
  from langchain_huggingface import HuggingFaceEmbeddings
19
 
@@ -23,16 +24,17 @@ from supabase import create_client, Client
23
 
24
  load_dotenv()
25
 
26
- # os.environ["TAVILY_API_KEY"] = os.environ.get("TAVILY_API_KEY")
27
- # os.environ["GOOGLE_API_KEY"] = os.environ.get("GOOGLE_API_KEY")
 
28
 
29
  __embeddings = HuggingFaceEmbeddings(
30
  model_name="sentence-transformers/all-mpnet-base-v2",
31
  model_kwargs= { 'device': 'cpu' })
32
 
33
  # connect to supabase
34
- url: str = os.environ.get("SUPABASE_URL")
35
- key: str = os.environ.get("SUPABASE_SECRET_KEY")
36
  __supabase: Client = create_client(url, key)
37
 
38
  # build retriever
@@ -173,7 +175,8 @@ class AgentState(TypedDict):
173
 
174
 
175
  def build_graph():
176
- llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
 
177
  llm_with_tools = llm.bind_tools(tools)
178
 
179
  # Node
@@ -207,8 +210,8 @@ def build_graph():
207
 
208
  # Test
209
  if __name__ == "__main__":
210
- question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
211
- # question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
212
  graph = build_graph()
213
  messages = [HumanMessage(content=question)]
214
  messages = graph.invoke({ "messages": messages })
 
13
  from langchain_community.document_loaders import WikipediaLoader
14
  from langchain_community.document_loaders import ArxivLoader
15
 
16
+ # from langchain_google_genai import ChatGoogleGenerativeAI
17
+ from langchain_groq import ChatGroq
18
 
19
  from langchain_huggingface import HuggingFaceEmbeddings
20
 
 
24
 
25
  load_dotenv()
26
 
27
+ #os.environ["TAVILY_API_KEY"] = os.environ.get("TAVILY_API_KEY")
28
+ #os.environ["GOOGLE_API_KEY"] = os.environ.get("GOOGLE_API_KEY")
29
+ #os.environ["GROQ_API_KEY"] = os.environ.get("GROQ_API_KEY")
30
 
31
  __embeddings = HuggingFaceEmbeddings(
32
  model_name="sentence-transformers/all-mpnet-base-v2",
33
  model_kwargs= { 'device': 'cpu' })
34
 
35
  # connect to supabase
36
+ url: str = os.getenv("SUPABASE_URL")
37
+ key: str = os.getenv("SUPABASE_SECRET_KEY")
38
  __supabase: Client = create_client(url, key)
39
 
40
  # build retriever
 
175
 
176
 
177
  def build_graph():
178
+ # llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
179
+ llm = ChatGroq(model="qwen-qwq-32b", temperature=0)
180
  llm_with_tools = llm.bind_tools(tools)
181
 
182
  # Node
 
210
 
211
  # Test
212
  if __name__ == "__main__":
213
+ # question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
214
+ question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
215
  graph = build_graph()
216
  messages = [HumanMessage(content=question)]
217
  messages = graph.invoke({ "messages": messages })
app.py CHANGED
@@ -10,6 +10,9 @@ from agent import build_graph
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
 
 
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
@@ -24,7 +27,7 @@ class BasicAgent:
24
  # print(f"Agent received question (first 50 chars): {question[:50]}...")
25
  # fixed_answer = "This is a default answer."
26
  # print(f"Agent returning fixed answer: {fixed_answer}")
27
- return answer
28
 
29
  def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  """
 
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
+ os.environ["TAVILY_API_KEY"] = os.getenv("TAVILY_API_KEY")
14
+ os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
15
+
16
  # --- Basic Agent Definition ---
17
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
18
  class BasicAgent:
 
27
  # print(f"Agent received question (first 50 chars): {question[:50]}...")
28
  # fixed_answer = "This is a default answer."
29
  # print(f"Agent returning fixed answer: {fixed_answer}")
30
+ return answer[:14]
31
 
32
  def run_and_submit_all( profile: gr.OAuthProfile | None):
33
  """
prompt.txt CHANGED
@@ -1,49 +1,5 @@
1
- You are a helpful agent responsible for answering questions using a set of tools provided.
2
- If the tool(s) not available, you can try to search and find the solution or information online.
3
- You can also use your own knowledge to answer the question.
4
- ==========================
5
- Here is a few examples showing you how to answer the question step by step.
6
-
7
- Question 1: In terms of geographical distance between capital cities, which 2 countries are the furthest from each other within the ASEAN bloc according to wikipedia? Answer using a comma separated list, ordering the countries by alphabetical order.
8
- Steps:
9
- 1. Search the web for "ASEAN bloc".
10
- 2. Click the Wikipedia result for the ASEAN Free Trade Area.
11
- 3. Scroll down to find the list of member states.
12
- 4. Click into the Wikipedia pages for each member state, and note its capital.
13
- 5. Search the web for the distance between the first two capitals. The results give travel distance, not geographic distance, which might affect the answer.
14
- 6. Thinking it might be faster to judge the distance by looking at a map, search the web for "ASEAN bloc" and click into the images tab.
15
- 7. View a map of the member countries. Since they're clustered together in an arrangement that's not very linear, it's difficult to judge distances by eye.
16
- 8. Return to the Wikipedia page for each country. Click the GPS coordinates for each capital to get the coordinates in decimal notation.
17
- 9. Place all these coordinates into a spreadsheet.
18
- 10. Write formulas to calculate the distance between each capital.
19
- 11. Write formula to get the largest distance value in the spreadsheet.
20
- 12. Note which two capitals that value corresponds to: Jakarta and Naypyidaw.
21
- 13. Return to the Wikipedia pages to see which countries those respective capitals belong to: Indonesia, Myanmar.
22
- Tools:
23
- 1. Search engine
24
- 2. Web browser
25
- 3. Microsoft Excel / Google Sheets
26
- Final Answer: Indonesia, Myanmar
27
-
28
- Question 2: Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.
29
- Steps:
30
- Step 1: Evaluate the position of the pieces in the chess position
31
- Step 2: Report the best move available for black: "Rd5"
32
- Tools:
33
- 1. Image recognition tools
34
- Final Answer: Rd5
35
-
36
- Question 3: Solve the equation x^2 + 5x = -6
37
- Steps:
38
- Step 1: Moving all terms to left-hand side until the right-hand side become zero.
39
- Step 2: Identify the highest power of polynomial in left-hand side. In this case the highest power is 2, this equation is a quadratic equation.
40
- Step 3: Identify the coefficients of each term in this quadratic equation.
41
- Step 3: Write quadratic formula and calculate the possible solutions.
42
- Tools:
43
- 1. Search engine
44
- 2. Web browser
45
- 3. Calculator
46
- Final Answer: x=-2, x=-3
47
-
48
- ==========================
49
- Now, please answer the following question step by step.
 
1
+ You are a helpful assistant tasked with answering questions using a set of tools.
2
+ Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
3
+ FINAL ANSWER: [YOUR FINAL ANSWER].
4
+ 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.
5
+ Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -7,6 +7,7 @@ langchain-google-genai
7
  langchain-huggingface
8
  langchain-tavily
9
  langchain-chroma
 
10
  langgraph
11
  huggingface_hub
12
  supabase
 
7
  langchain-huggingface
8
  langchain-tavily
9
  langchain-chroma
10
+ langchain-groq
11
  langgraph
12
  huggingface_hub
13
  supabase