cowrycode commited on
Commit
98508a8
·
verified ·
1 Parent(s): 5f3ee04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -50
app.py CHANGED
@@ -11,20 +11,12 @@ from llama_index.core.agent import ReActAgent
11
  from llama_index.core.agent.workflow import AgentWorkflow
12
  from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
13
  from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
14
- from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool
 
15
  from agent import smart_agent
16
  from llama_index.llms.openai import OpenAI
17
  #-----------------------------------------------------------------
18
- from langgraph_impl.my_agent import create_langchain_agent
19
- #from langchain_community.llms import OpenAI
20
- from langchain.tools import Tool
21
- from langgraph_impl.my_agent import create_langchain_agent
22
 
23
- from langgraph_impl.wikipedia_tool import wiki_search
24
- from langgraph_impl.youtube_tool import get_youtube_transcript
25
- from langgraph_impl.audio_transcriber import transcribe_audio
26
- from langgraph_impl.image_chess_solver import solve_chess_image
27
- from langgraph_impl.file_parser import parse_file_and_summarize
28
 
29
  # (Keep Constants as is)
30
  # --- Constants ---
@@ -33,49 +25,40 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
33
  # --- Basic Agent Definition ---
34
 
35
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
36
- # class BasicAgent:
37
- # def __init__(self):
38
- # print("BasicAgent initialized. . . .")
39
- # # self.agent = smart_agent()
40
- # # self.api_key = os.getenv("HF_TOKEN")
41
- # OpenAI_key = os.getenv("OPEN_AI_TOKEN")
42
- # self.llm = OpenAI(model="gpt-4o-mini", temperature=0.2, api_key=OpenAI_key)
43
- # self.agent = AgentWorkflow.from_tools_or_functions(
44
- # [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
45
- # llm=self.llm,
46
- # )
47
-
48
- # async def run(self, question: str) -> str:
49
- # print(f"Agent received question (first 50 chars): {question[:50]}...")
50
- # # answer = await self.agent.run(question)
51
- # answer = await self.agent.run(
52
- # f"{question}\n\nIf you have enough information, respond with a concise final answer.",
53
- # max_iterations=50
54
- # )
55
- # if hasattr(answer, "output"):
56
- # print(f"Agent returning answer: {answer}")
57
- # return str(answer.output)
58
- # else:
59
- # print(f"Agent returning answer: {answer}")
60
- # return str(answer)
61
-
62
- # def __call__(self, question: str) -> str:
63
- # return asyncio.run(self.run(question))
64
-
65
-
66
  class BasicAgent:
67
  def __init__(self):
68
- print("Initializing LangChain Agent...")
69
- self.agent = create_langchain_agent()
70
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  def __call__(self, question: str) -> str:
72
- try:
73
- result = self.agent.invoke({"input": question})
74
- if isinstance(result, dict) and "output" in result:
75
- return result["output"]
76
- return result
77
- except Exception as e:
78
- return f"Agent error: {e}"
79
 
80
 
81
 
 
11
  from llama_index.core.agent.workflow import AgentWorkflow
12
  from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
13
  from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
14
+ #from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool
15
+ from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool, transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
16
  from agent import smart_agent
17
  from llama_index.llms.openai import OpenAI
18
  #-----------------------------------------------------------------
 
 
 
 
19
 
 
 
 
 
 
20
 
21
  # (Keep Constants as is)
22
  # --- Constants ---
 
25
  # --- Basic Agent Definition ---
26
 
27
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  class BasicAgent:
29
  def __init__(self):
30
+ print("BasicAgent initialized. . . .")
31
+ # self.agent = smart_agent()
32
+ # self.api_key = os.getenv("HF_TOKEN")
33
+ OpenAI_key = os.getenv("OPEN_AI_TOKEN")
34
+ self.llm = OpenAI(model="gpt-4o-mini", temperature=0.2, api_key=OpenAI_key)
35
+ # self.agent = AgentWorkflow.from_tools_or_functions(
36
+ # [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
37
+ # llm=self.llm,
38
+ # )
39
+ self.agent = AgentWorkflow.from_tools_or_functions(
40
+ [
41
+ wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool,transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
42
+ ],
43
+ llm=self.llm
44
+ )
45
+ async def run(self, question: str) -> str:
46
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
47
+ # answer = await self.agent.run(question)
48
+ answer = await self.agent.run(
49
+ f"{question}\n\nIf you have enough information, respond with a concise final answer.",
50
+ max_iterations=50
51
+ )
52
+ if hasattr(answer, "output"):
53
+ print(f"Agent returning answer: {answer}")
54
+ return str(answer.output)
55
+ else:
56
+ print(f"Agent returning answer: {answer}")
57
+ return str(answer)
58
+
59
  def __call__(self, question: str) -> str:
60
+ return asyncio.run(self.run(question))
61
+
 
 
 
 
 
62
 
63
 
64