anupamdas commited on
Commit
d352829
·
verified ·
1 Parent(s): ba77dc0

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +37 -25
agents.py CHANGED
@@ -1,26 +1,38 @@
1
- from phi.assistant import Assistant
2
- from phi.llm.google import Gemini
3
- from phi.tools.wikipedia import WikipediaTools
4
-
5
- def get_content_enhancer_agent(knowledge_base=None):
6
- """Factory function to create the content enhancement agent."""
7
- return Assistant(
8
- llm=Gemini(model="gemini-1.5-flash-latest"),
9
- tools=[WikipediaTools()],
10
- knowledge_base=knowledge_base,
11
- search_knowledge=True,
12
- description="You are an expert multimedia content creator and writer.",
13
- instructions=[
14
- "You will receive a summary from a video analysis.",
15
- "Your primary goal is to enrich this summary by:",
16
- " 1. Using your knowledge base and Wikipedia to find more details, facts, and context about the key topics mentioned.",
17
- " 2. Weaving all information (video summary, knowledge base, Wikipedia) into a single, cohesive, and engaging narrative.",
18
- " 3. Identifying the most visually compelling moments or concepts in the narrative.",
19
- "At these points, you MUST insert a placeholder in the exact format: [IMAGE: caption=\"A detailed, vivid prompt for an AI image generator\"]",
20
- "The caption prompt should be descriptive: think about subject, action, style, lighting, and composition.",
21
- "Prioritize the information from the video summary, then augment it with external knowledge.",
22
- "Return only the final, complete text with the placeholders."
23
- ],
24
- # shows the LLM thinking process
25
- show_tool_calls=True,
 
 
 
 
 
 
 
 
 
 
 
 
26
  )
 
1
+ from phi.assistant import Assistant
2
+ from phi.tools.wikipedia import WikipediaTools
3
+ from google import genai
4
+ import os
5
+
6
+ client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
7
+
8
+ class GeminiWrapper:
9
+ """Custom wrapper to use new Gemini SDK inside phi"""
10
+
11
+ def __init__(self, model="gemini-2.0-flash"):
12
+ self.model = model
13
+
14
+ def __call__(self, prompt, **kwargs):
15
+ response = client.models.generate_content(
16
+ model=self.model,
17
+ contents=prompt
18
+ )
19
+ return response.text
20
+
21
+
22
+ def get_content_enhancer_agent(knowledge_base=None):
23
+ return Assistant(
24
+ llm=GeminiWrapper(),
25
+ tools=[WikipediaTools()],
26
+ knowledge_base=knowledge_base,
27
+ search_knowledge=True,
28
+ description="You are an expert multimedia content creator and writer.",
29
+ instructions=[
30
+ "You will receive a summary from a video analysis.",
31
+ "Enhance it using knowledge + Wikipedia.",
32
+ "Create a cohesive narrative.",
33
+ "Insert [IMAGE: caption=\"...\"] placeholders.",
34
+ "Make prompts vivid and visual.",
35
+ "Return only final text."
36
+ ],
37
+ show_tool_calls=True,
38
  )