GattoNero commited on
Commit
845d9e9
·
verified ·
1 Parent(s): 90f98c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -36,16 +36,43 @@ class BasicAgent:
36
  if not openai_api_key:
37
  raise ValueError("OPENAI_API_KEY not set!")
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Crea un'istanza di OpenAI
40
  llm = OpenAI(
41
  model="gpt-4o-mini",
42
  temperature=0,
43
  api_key=openai_api_key,
 
 
44
  verbose = True
45
  )
46
 
47
  # Imposta le impostazioni tramite Settings
48
  Settings.llm=llm
 
 
49
 
50
  self.client = OpenAIClient(api_key=openai_api_key)
51
 
@@ -229,6 +256,22 @@ def create_mock_questions():
229
 
230
 
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  def print_coso(scritta: str):
233
  print(f"coso {scritta}")
234
 
 
36
  if not openai_api_key:
37
  raise ValueError("OPENAI_API_KEY not set!")
38
 
39
+
40
+
41
+ tools = [
42
+ {
43
+ "type": "function",
44
+ "function": {
45
+ "name": "transcribe_audio",
46
+ "description": "Transcribe an audio file (MP3 or similar) using Whisper.",
47
+ "parameters": {
48
+ "type": "object",
49
+ "properties": {
50
+ "file_name": {
51
+ "type": "string",
52
+ "description": "The filename of the audio file to transcribe (e.g. 'example.mp3')"
53
+ }
54
+ },
55
+ "required": ["file_name"]
56
+ }
57
+ }
58
+ }
59
+ ]
60
+
61
+
62
  # Crea un'istanza di OpenAI
63
  llm = OpenAI(
64
  model="gpt-4o-mini",
65
  temperature=0,
66
  api_key=openai_api_key,
67
+ tools=tools,
68
+ tool_choice="auto",
69
  verbose = True
70
  )
71
 
72
  # Imposta le impostazioni tramite Settings
73
  Settings.llm=llm
74
+
75
+ Settings.too
76
 
77
  self.client = OpenAIClient(api_key=openai_api_key)
78
 
 
256
 
257
 
258
 
259
+
260
+ #Tools
261
+
262
+ def transcribe_audio(file_name: str) -> str:
263
+ file_path = os.path.join("/data", file_name)
264
+ if not os.path.isfile(file_path):
265
+ return f"File not found: {file_path}"
266
+
267
+ model = whisper.load_model("base")
268
+ result = model.transcribe(file_path)
269
+ return result["text"]
270
+
271
+
272
+
273
+
274
+
275
  def print_coso(scritta: str):
276
  print(f"coso {scritta}")
277