GattoNero commited on
Commit
179a8d2
·
verified ·
1 Parent(s): 05ad09e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -79
app.py CHANGED
@@ -86,78 +86,6 @@ class BasicAgent:
86
  print_coso(f"Error instantiating agent: {e}")
87
  traceback.print_exc()
88
 
89
-
90
-
91
-
92
-
93
-
94
- '''
95
- tools = [
96
- {
97
- "type": "function",
98
- "function": {
99
- "name": "transcribe_audio",
100
- "description": "Transcribe an audio file (MP3 or similar) using Whisper.",
101
- "parameters": {
102
- "type": "object",
103
- "properties": {
104
- "file_name": {
105
- "type": "string",
106
- "description": "The filename of the audio file to transcribe (e.g. 'example.mp3')"
107
- }
108
- },
109
- "required": ["file_name"]
110
- }
111
- }
112
- }
113
- ]
114
-
115
- ingredient_tool = FunctionTool.from_defaults(
116
- name="extract_ingredients",
117
- fn=extract_ingredients,
118
- description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
119
- )
120
-
121
- Settings.tools = [ingredient_tool]
122
-
123
- # Crea un'istanza di OpenAI
124
- llm = OpenAI(
125
- model="gpt-4o-mini",
126
- temperature=0,
127
- api_key=openai_api_key,
128
- #tools=tools,
129
- #tool_choice="auto",
130
- verbose = True
131
- )
132
-
133
- # Imposta le impostazioni tramite Settings
134
- Settings.llm=llm
135
-
136
- logging.basicConfig(level=logging.DEBUG)
137
-
138
- self.client = OpenAIClient(api_key=openai_api_key)
139
-
140
-
141
- # Carica i documenti dalla cartella 'data'
142
- self.documents = SimpleDirectoryReader("data").load_data()
143
-
144
- # Crea l'indice con la configurazione
145
- self.index = VectorStoreIndex.from_documents(self.documents, settings=Settings)
146
-
147
- # Prepara il query engine
148
- self.query_engine = self.index.as_query_engine()
149
- print("coso Agent ready.")
150
-
151
- def __call__(self, question: str) -> str:
152
- print(f"Received question: {question[:50]}...")
153
- response = self.query_engine.query(question)
154
-
155
- # Stampa ragionamento interno
156
- print("Query response object:", response)
157
- print("Response text:", str(response))
158
-
159
- return str(response)
160
- '''
161
 
162
 
163
  def __call__(self, question: str, file_info: str = "") -> str:
@@ -386,7 +314,7 @@ def get_or_download_audio(file_name: str) -> bytes:
386
  full_url = f"{base_url}/{commit_hash}/2023/validation/{file_name}"
387
  '''
388
 
389
- DOMANDE_MOCKATE = False
390
  def create_mock_questions():
391
 
392
  '''
@@ -401,7 +329,12 @@ def create_mock_questions():
401
  'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',
402
  'Level': '1',
403
  'file_name': ''
404
- }
 
 
 
 
 
405
  '''
406
 
407
 
@@ -409,11 +342,18 @@ def create_mock_questions():
409
 
410
 
411
  return [
412
- {'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
413
- 'question': 'Hi, I\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\'t quite make out what she\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\'ve attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for "a pinch of salt" or "two cups of ripe strawberries" the ingredients on the list would be "salt" and "ripe strawberries".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.',
414
- 'Level': '1',
415
- 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'
416
- }
 
 
 
 
 
 
 
417
  ]
418
 
419
 
 
86
  print_coso(f"Error instantiating agent: {e}")
87
  traceback.print_exc()
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91
  def __call__(self, question: str, file_info: str = "") -> str:
 
314
  full_url = f"{base_url}/{commit_hash}/2023/validation/{file_name}"
315
  '''
316
 
317
+ DOMANDE_MOCKATE = True
318
  def create_mock_questions():
319
 
320
  '''
 
329
  'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',
330
  'Level': '1',
331
  'file_name': ''
332
+ },
333
+ {'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
334
+ 'question': 'Hi, I\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\'t quite make out what she\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\'ve attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for "a pinch of salt" or "two cups of ripe strawberries" the ingredients on the list would be "salt" and "ripe strawberries".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.',
335
+ 'Level': '1',
336
+ 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'
337
+ }
338
  '''
339
 
340
 
 
342
 
343
 
344
  return [
345
+ {
346
+ "task_id":"cca530fc-4052-43b2-b130-b30968d8aa44",
347
+ "question":"Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
348
+ "Level":"1",
349
+ "file_name":"cca530fc-4052-43b2-b130-b30968d8aa44.png"
350
+ },
351
+ {
352
+ "task_id": "5a0c1adf-205e-4841-a666-7c3ef95def9d",
353
+ "question": "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?",
354
+ "Level": "1",
355
+ "file_name": ""
356
+ }
357
  ]
358
 
359