beitemian commited on
Commit
1b66ea9
·
1 Parent(s): 3a496d9

updated tools and req

Browse files
Files changed (3) hide show
  1. agent.py +28 -4
  2. requirements.txt +3 -1
  3. tools.py +27 -2
agent.py CHANGED
@@ -13,9 +13,10 @@ project_root = str(Path(__file__).parent)
13
  if project_root not in sys.path:
14
  sys.path.insert(0, project_root)
15
  import os
16
- from tools import web_search, math_tools
17
  #from memory import set_memory
18
  from llama_index.core.agent.workflow import FunctionAgent, AgentWorkflow, ToolCall, ToolCallResult, ReActAgent
 
19
  #from llama_index.core.memory import Memory
20
  import asyncio
21
  from datetime import datetime
@@ -39,6 +40,26 @@ llm_deepseek_r1 = DeepSeek(
39
  #test the llm
40
  #answerr = llm_deepseek_r1.complete("What is the capital of France?")
41
  #print(answerr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  researcher_agent = FunctionAgent(
44
  llm=llm_deepseek_r1,
@@ -85,7 +106,8 @@ Response Guidelines:
85
  - STRICT!!! Only answer the question directly, concisely. For example, if the question is "What is the capital of France?", the answer should be "Paris".
86
  - No elaboration or explanation, only straight answer to the question.
87
  - Plain text response formatting.
88
- """,
 
89
  tools = [
90
  web_search,
91
  math_tools.add,
@@ -93,8 +115,10 @@ Response Guidelines:
93
  math_tools.multiply,
94
  math_tools.divide,
95
  math_tools.modulus
96
- ]
 
 
97
  )
98
 
99
- workflow_agent = AgentWorkflow(agents = [researcher_agent], root_agent=researcher_agent.name, verbose=True)
100
 
 
13
  if project_root not in sys.path:
14
  sys.path.insert(0, project_root)
15
  import os
16
+ from tools import web_search, math_tools, file_management_tools
17
  #from memory import set_memory
18
  from llama_index.core.agent.workflow import FunctionAgent, AgentWorkflow, ToolCall, ToolCallResult, ReActAgent
19
+ from llama_index.llms.openai import OpenAI
20
  #from llama_index.core.memory import Memory
21
  import asyncio
22
  from datetime import datetime
 
40
  #test the llm
41
  #answerr = llm_deepseek_r1.complete("What is the capital of France?")
42
  #print(answerr)
43
+ gpt_4o = OpenAI(
44
+ model="gpt-4o",
45
+ api_key=os.getenv("OPENAI_API_KEY"),
46
+ temperature=0.2,
47
+ max_retries=5,
48
+ timeout=100
49
+ )
50
+ # Image and video understanding agent
51
+ # TODO: Add tools for video, audio analysis.
52
+ media_agent = FunctionAgent(
53
+ llm=gpt_4o,
54
+ name="Luna",
55
+ description="An agent that analyzes videos, audio, and images to provide a summary of the content.",
56
+ system_prompt=f"""Luna is an expert at analyzing videos, images, audio. Luna concisely leverages tools to analyze these modalities.
57
+ TOOLS:
58
+ PLAN:
59
+ OUTPUT FORMATTING: """,
60
+ tools = [file_management_tools.read_youtube_video],
61
+ allow_parallel_tool_calls=True
62
+ )
63
 
64
  researcher_agent = FunctionAgent(
65
  llm=llm_deepseek_r1,
 
106
  - STRICT!!! Only answer the question directly, concisely. For example, if the question is "What is the capital of France?", the answer should be "Paris".
107
  - No elaboration or explanation, only straight answer to the question.
108
  - Plain text response formatting.
109
+ """,
110
+ #TODO: Add tools for wikipedia, and document processing (csv, code, pdf, etc.)
111
  tools = [
112
  web_search,
113
  math_tools.add,
 
115
  math_tools.multiply,
116
  math_tools.divide,
117
  math_tools.modulus
118
+ ],
119
+ allow_parallel_tool_calls=True,
120
+ can_handoff_to=media_agent
121
  )
122
 
123
+ workflow_agent = AgentWorkflow(agents = [researcher_agent, media_agent], root_agent=researcher_agent.name, verbose=True, handoff_prompt="Please handoff to the media agent to analyze videos, audio, images.")
124
 
requirements.txt CHANGED
@@ -6,4 +6,6 @@ llama-index-core
6
  linkup-sdk
7
  python-dotenv
8
  requests
9
- pandas
 
 
 
6
  linkup-sdk
7
  python-dotenv
8
  requests
9
+ pandas
10
+ llama-index-readers-youtube-transcript
11
+ llama-hub-youtube-transcript
tools.py CHANGED
@@ -1,5 +1,8 @@
1
  from linkup import LinkupClient
2
  from dotenv import load_dotenv
 
 
 
3
  import os
4
  load_dotenv()
5
  linkup_client = LinkupClient(api_key=os.getenv("LINKUP_API_KEY"))
@@ -85,5 +88,27 @@ class MathTools:
85
  # Create an instance for easy importing
86
  math_tools = MathTools()
87
 
88
-
89
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from linkup import LinkupClient
2
  from dotenv import load_dotenv
3
+ from llama_index.readers.youtube_transcript import YoutubeTranscriptReader
4
+ from llama_index.readers.youtube_transcript.utils import is_youtube_video
5
+ from llama_index.core import Document
6
  import os
7
  load_dotenv()
8
  linkup_client = LinkupClient(api_key=os.getenv("LINKUP_API_KEY"))
 
88
  # Create an instance for easy importing
89
  math_tools = MathTools()
90
 
91
+ #File management tools
92
+ class FileManagementTools:
93
+ """A class for interacting with files (csv, jpeg, png, pdf, etc.)"""
94
+ def __init__(self): #TODO: Add proper init
95
+ self.file_path = None
96
+ self.file_type = None
97
+ self.file_name = None
98
+ self.file_size = None
99
+ self.file_content = None
100
+ #TODO: Finish the class with proper source handling and additional file type reading.
101
+ def read_youtube_video(self,urls: list[str]) -> list[Document]:
102
+ """Read a youtube video and return the transcript."""
103
+ valid_urls = [url for url in urls if is_youtube_video(url)]
104
+
105
+ if not valid_urls:
106
+ raise ValueError("No valid YouTube URLs provided")
107
+ # Load transcripts for valid URLs
108
+ try:
109
+ loader = YoutubeTranscriptReader()
110
+ documents = loader.load_data(ytlinks=valid_urls)
111
+ return documents
112
+ except Exception as e:
113
+ raise ValueError(f"Error loading YouTube transcripts: {e}")
114
+ file_management_tools = FileManagementTools()