CoralLeiCN commited on
Commit
9283c68
·
1 Parent(s): 0b4ed3e

Enhance BaseballQATool: update description for clarity and add grounding tool configuration

Browse files
Files changed (1) hide show
  1. agent/tools.py +20 -7
agent/tools.py CHANGED
@@ -11,9 +11,7 @@ from smolagents import Tool
11
 
12
  class BaseballQATool(Tool):
13
  name = "baseball_qa"
14
- description = (
15
- """This tool can answer questions about baseball players information."""
16
- )
17
  inputs = {
18
  "player_name": {
19
  "type": "string",
@@ -32,12 +30,15 @@ class BaseballQATool(Tool):
32
  output_type = "string"
33
 
34
  def forward(self, player_name: str, question: str, team_name: str = ""):
 
 
 
35
  config = types.GenerateContentConfig(
36
  temperature=0,
37
  candidate_count=1,
38
- response_mime_type="application/json",
39
  top_p=0.95,
40
  seed=42,
 
41
  )
42
  client = genai.Client()
43
  response = client.models.generate_content(
@@ -45,7 +46,7 @@ class BaseballQATool(Tool):
45
  contents=types.Content(
46
  parts=[
47
  types.Part(
48
- text=f"Pay attention to the details. Make corrections if needed. Player: {player_name}\nTeam: {team_name}\nQuestion: {question}"
49
  )
50
  ],
51
  ),
@@ -179,7 +180,12 @@ class UnderstandImageBytes(Tool):
179
  client = genai.Client()
180
  image = Image.open(io.BytesIO(image_bytes))
181
  prompt = "Analyze this image and provide a description of its content."
182
-
 
 
 
 
 
183
  response = client.models.generate_content(
184
  model="gemini-2.5-pro",
185
  contents=[
@@ -189,6 +195,7 @@ class UnderstandImageBytes(Tool):
189
  mime_type=f"image/{image.format}",
190
  ),
191
  ],
 
192
  )
193
 
194
  return response.text
@@ -220,7 +227,6 @@ class TranscribeAudioBytes(Tool):
220
  config = types.GenerateContentConfig(
221
  temperature=0,
222
  candidate_count=1,
223
- response_mime_type="application/json",
224
  top_p=0.95,
225
  seed=42,
226
  )
@@ -261,6 +267,12 @@ class TranscribeYoutubeVideo(Tool):
261
  output_type = "string"
262
 
263
  def forward(self, youtube_uri: str, question: str = ""):
 
 
 
 
 
 
264
  client = genai.Client()
265
  prompt = "Transcribe the audio from this video, giving timestamps for salient events in the video. Also provide visual descriptions."
266
  response = client.models.generate_content(
@@ -273,6 +285,7 @@ class TranscribeYoutubeVideo(Tool):
273
  ),
274
  ]
275
  ),
 
276
  )
277
  transcript = response.text
278
 
 
11
 
12
  class BaseballQATool(Tool):
13
  name = "baseball_qa"
14
+ description = """This tool can answer questions about baseball players information. You must provide the accurate player name, team name and question."""
 
 
15
  inputs = {
16
  "player_name": {
17
  "type": "string",
 
30
  output_type = "string"
31
 
32
  def forward(self, player_name: str, question: str, team_name: str = ""):
33
+ # Define the grounding tool
34
+ grounding_tool = types.Tool(google_search=types.GoogleSearch())
35
+
36
  config = types.GenerateContentConfig(
37
  temperature=0,
38
  candidate_count=1,
 
39
  top_p=0.95,
40
  seed=42,
41
+ tools=[grounding_tool],
42
  )
43
  client = genai.Client()
44
  response = client.models.generate_content(
 
46
  contents=types.Content(
47
  parts=[
48
  types.Part(
49
+ text=f"Player: {player_name}\nTeam: {team_name}\nQuestion: {question}"
50
  )
51
  ],
52
  ),
 
180
  client = genai.Client()
181
  image = Image.open(io.BytesIO(image_bytes))
182
  prompt = "Analyze this image and provide a description of its content."
183
+ config = types.GenerateContentConfig(
184
+ temperature=0,
185
+ candidate_count=1,
186
+ top_p=0.95,
187
+ seed=42,
188
+ )
189
  response = client.models.generate_content(
190
  model="gemini-2.5-pro",
191
  contents=[
 
195
  mime_type=f"image/{image.format}",
196
  ),
197
  ],
198
+ config=config,
199
  )
200
 
201
  return response.text
 
227
  config = types.GenerateContentConfig(
228
  temperature=0,
229
  candidate_count=1,
 
230
  top_p=0.95,
231
  seed=42,
232
  )
 
267
  output_type = "string"
268
 
269
  def forward(self, youtube_uri: str, question: str = ""):
270
+ config = types.GenerateContentConfig(
271
+ temperature=0,
272
+ candidate_count=1,
273
+ top_p=0.95,
274
+ seed=42,
275
+ )
276
  client = genai.Client()
277
  prompt = "Transcribe the audio from this video, giving timestamps for salient events in the video. Also provide visual descriptions."
278
  response = client.models.generate_content(
 
285
  ),
286
  ]
287
  ),
288
+ config=config,
289
  )
290
  transcript = response.text
291