Luigi D'Addona commited on
Commit
e47bd31
·
1 Parent(s): 1ae2c4e

corretto formato del message per l'LLM nel tool analyze_mp3_file

Browse files
Files changed (1) hide show
  1. tools.py +9 -5
tools.py CHANGED
@@ -213,11 +213,14 @@ def get_analyze_mp3_tool(llm):
213
  all_text = ""
214
  try:
215
  # Read audio and encode as base64
216
- with open(audio_path, "rb") as image_file:
217
- audio_bytes = image_file.read()
218
 
219
  audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
220
 
 
 
 
221
  # Prepare the prompt including the base64 image data
222
  message = [
223
  HumanMessage(
@@ -230,9 +233,10 @@ def get_analyze_mp3_tool(llm):
230
  ),
231
  },
232
  {
233
- "type": "audio_url",
234
- "audio_url": {"url": audio_base64},
235
- },
 
236
  ]
237
  )
238
  ]
 
213
  all_text = ""
214
  try:
215
  # Read audio and encode as base64
216
+ with open(audio_path, "rb") as audio_file:
217
+ audio_bytes = audio_file.read()
218
 
219
  audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
220
 
221
+ # Determine the MIME type for MP3
222
+ audio_mime_type = "audio/mpeg" # Or "audio/mp3", "audio/wav" etc. for other formats
223
+
224
  # Prepare the prompt including the base64 image data
225
  message = [
226
  HumanMessage(
 
233
  ),
234
  },
235
  {
236
+ "type": "media", # <--- CORRECTED: Use 'media' type
237
+ "data": audio_base64, # <--- Use 'data' for the base64 content
238
+ "mime_type": audio_mime_type, # <--- Specify the MIME type
239
+ }
240
  ]
241
  )
242
  ]