zcfrank1st commited on
Commit
22b812e
·
1 Parent(s): 957778e

change code

Browse files
Files changed (2) hide show
  1. app.py +14 -8
  2. requirements.txt +10 -1
app.py CHANGED
@@ -4,7 +4,13 @@ import requests
4
  import inspect
5
  import pandas as pd
6
  import uuid
7
- from smolagents import OpenAIServerModel, ToolCallingAgent, DuckDuckGoSearchTool
 
 
 
 
 
 
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
@@ -15,16 +21,16 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  class BasicAgent:
16
  def __init__(self):
17
  print("BasicAgent initialized.")
18
- model = OpenAIServerModel(
19
- model_id=os.getenv("MODEL_ID"),
20
- api_key=os.getenv("API_KEY"),
21
- api_base=os.getenv("API_BASE"),
22
- )
23
- self.agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool()], model=model)
24
 
25
  def __call__(self, question: str) -> str:
26
  print(f"Agent received question (first 50 chars): {question[:50]}...")
27
- answer = self.agent(question)
28
  print(f"Agent returning answer: {answer}")
29
  return answer
30
 
 
4
  import inspect
5
  import pandas as pd
6
  import uuid
7
+
8
+ from langchain.chat_models import init_chat_model
9
+ from langgraph.prebuilt import create_react_agent
10
+ from langchain_community.tools import WikipediaQueryRun
11
+ from langchain_community.utilities import WikipediaAPIWrapper
12
+
13
+ from langchain_community.tools import DuckDuckGoSearchResults
14
 
15
  # (Keep Constants as is)
16
  # --- Constants ---
 
21
  class BasicAgent:
22
  def __init__(self):
23
  print("BasicAgent initialized.")
24
+ llm = init_chat_model(temperature=0, model=os.getenv("MODEL_ID"), api_key=os.getenv("API_KEY"), base_url=os.getenv("API_BASE"))
25
+
26
+ api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=100)
27
+ wiki = WikipediaQueryRun(api_wrapper=api_wrapper)
28
+
29
+ self.agent = create_react_agent(llm, tools=[wiki, DuckDuckGoSearchResults()])
30
 
31
  def __call__(self, question: str) -> str:
32
  print(f"Agent received question (first 50 chars): {question[:50]}...")
33
+ answer = self.agent.invoke(inputs = {"messages": [("user", question)]})
34
  print(f"Agent returning answer: {answer}")
35
  return answer
36
 
requirements.txt CHANGED
@@ -1,3 +1,12 @@
1
  gradio
2
  requests
3
- smolagents[openai]
 
 
 
 
 
 
 
 
 
 
1
  gradio
2
  requests
3
+ # smolagents[openai]
4
+
5
+ langgraph-cli[inmem]
6
+ langchain
7
+ openai
8
+ duckduckgo-search
9
+ langchain-community
10
+ langchain-openai
11
+ wikipedia
12
+