Huanzhi Mao commited on
Commit
6767c79
β€’
1 Parent(s): 9918479

add app.py

Browse files
Files changed (2) hide show
  1. app.py +1277 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,1277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import webbrowser
4
+ import os
5
+ import re
6
+ import pandas as pd
7
+ # from anthropic import Anthropic
8
+ from openai import OpenAI
9
+ from mistralai.client import MistralClient
10
+ from mistralai.models.chat_completion import ChatMessage
11
+ import requests
12
+
13
+ mongoDBPassword = os.environ.get("MONGODB_PASSWORD")
14
+ openaiKey = os.environ.get("OPENAI_API_KEY")
15
+ mistralKey = os.environ.get("MISTRAL_API_KEY")
16
+ # anthropicKey = os.environ.get("ANTHROPIC_API_KEY")
17
+
18
+ EXAMPLES = [
19
+ {
20
+ "name": "requests.get",
21
+ "description": "Sends a GET request to the specified URL.",
22
+ "parameters": {
23
+ "type": "dict",
24
+ "properties": {
25
+ "url": {
26
+ "type": "string",
27
+ "description": "Geocoding API converting a a pair of latitude and longitude coordinates to human readable addresses",
28
+ "default": "https://geocode.maps.co/reverse",
29
+ },
30
+ "headers": {},
31
+ "timeout": {
32
+ "type": ["number", "tuple"],
33
+ "description": "How many seconds to wait for the server to send data before giving up.",
34
+ "required": False,
35
+ },
36
+ "params": {
37
+ "lat": {
38
+ "type": "number",
39
+ "description": "Latitude of the location to reverse geocode.",
40
+ "required": True,
41
+ },
42
+ "lon": {
43
+ "type": "number",
44
+ "description": "Longitude of the location to reverse geocode.",
45
+ "required": True,
46
+ },
47
+ "format": {
48
+ "type": "string",
49
+ "description": "The desired response format. Options include 'xml', 'json', 'jsonv2', 'geojson', 'geocodejson'. Default is 'json'.",
50
+ "required": False,
51
+ },
52
+ },
53
+ "allow_redirects": {
54
+ "type": "boolean",
55
+ "description": "A Boolean to enable/disable redirection.",
56
+ "default": True,
57
+ "required": False,
58
+ },
59
+ "auth": {
60
+ "type": "tuple",
61
+ "description": "A tuple to enable a certain HTTP authentication.",
62
+ "default": "None",
63
+ "required": False,
64
+ },
65
+ "cert": {
66
+ "type": ["string", "tuple"],
67
+ "description": "A String or Tuple specifying a cert file or key.",
68
+ "default": "None",
69
+ "required": False,
70
+ },
71
+ "cookies": {
72
+ "type": "dict",
73
+ "additionalProperties": {"type": "string"},
74
+ "description": "Dictionary of cookies to send with the request.",
75
+ "required": False,
76
+ },
77
+ "proxies": {
78
+ "type": "dict",
79
+ "additionalProperties": {"type": "string"},
80
+ "description": "Dictionary of the protocol to the proxy url.",
81
+ "required": False,
82
+ },
83
+ "stream": {
84
+ "type": "boolean",
85
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
86
+ "default": False,
87
+ "required": False,
88
+ },
89
+ "verify": {
90
+ "type": ["boolean", "string"],
91
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
92
+ "default": True,
93
+ "required": False,
94
+ },
95
+ },
96
+ },
97
+ },
98
+ {
99
+ "name": "requests.get",
100
+ "description": "Sends a GET request to the specified URL.",
101
+ "parameters": {
102
+ "type": "dict",
103
+ "properties": {
104
+ "url": {
105
+ "type": "string",
106
+ "description": "The Date Nager API provides access holiday information for over 100 countries, including the ability to query for long weekends. It leverages ISO 3166-1 alpha-2 country codes to tailor the search to your specific region of interest. More information can be found in https://date.nager.at/Api",
107
+ "default": "https://date.nager.at/api/v3/LongWeekend/{year}/{countryCode}",
108
+ },
109
+ "headers": {},
110
+ "timeout": {
111
+ "type": ["number", "tuple"],
112
+ "description": "How many seconds to wait for the server to send data before giving up.",
113
+ "required": False,
114
+ },
115
+ "params": {},
116
+ "auth": {
117
+ "type": "tuple",
118
+ "description": "A tuple to enable a certain HTTP authentication.",
119
+ "default": "None",
120
+ "required": False,
121
+ },
122
+ "cert": {
123
+ "type": ["string", "tuple"],
124
+ "description": "A String or Tuple specifying a cert file or key.",
125
+ "default": "None",
126
+ "required": False,
127
+ },
128
+ "cookies": {
129
+ "type": "dict",
130
+ "additionalProperties": {"type": "string"},
131
+ "description": "Dictionary of cookies to send with the request.",
132
+ "required": False,
133
+ },
134
+ "proxies": {
135
+ "type": "dict",
136
+ "additionalProperties": {"type": "string"},
137
+ "description": "Dictionary of the protocol to the proxy url.",
138
+ "required": False,
139
+ },
140
+ "stream": {
141
+ "type": "boolean",
142
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
143
+ "default": False,
144
+ "required": False,
145
+ },
146
+ "verify": {
147
+ "type": ["boolean", "string"],
148
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
149
+ "default": True,
150
+ "required": False,
151
+ },
152
+ },
153
+ },
154
+ },
155
+ {
156
+ "name": "requests.get",
157
+ "description": "Sends a GET request to the specified URL.",
158
+ "parameters": {
159
+ "type": "dict",
160
+ "properties": {
161
+ "url": {
162
+ "type": "string",
163
+ "description": "The Open-Meteo API provides detailed weather forecasts for any location worldwide. It offers forecasts up to 16 days in advance and also provide past data. The API's response gives weather variables on an hourly basis, such as temperature, humidity, precipitation, wind speed and direction, etc. More information can be found in https://open-meteo.com/en/docs/",
164
+ "default": "https://api.open-meteo.com/v1/forecast",
165
+ },
166
+ "headers": {},
167
+ "timeout": {
168
+ "type": ["number", "tuple"],
169
+ "description": "How many seconds to wait for the server to send data before giving up.",
170
+ "required": False,
171
+ },
172
+ "params": {
173
+ "latitude": {
174
+ "type": "string",
175
+ "description": "Geographical WGS84 coordinates of the location. Multiple coordinates can be comma separated. E.g., &latitude=52.52,48.85&longitude=13.41,2.35. To return data for multiple locations the JSON output changes to a list of structures. CSV and XLSX formats add a column location_id. N is positive, S is negative",
176
+ "required": True,
177
+ },
178
+ "longitude": {
179
+ "type": "string",
180
+ "description": "Geographical WGS84 coordinates of the location. Multiple coordinates can be comma separated. E is positive, W is negative",
181
+ "required": True,
182
+ },
183
+ "elevation": {
184
+ "type": "string",
185
+ "description": "The elevation used for statistical downscaling. Per default, a 90 meter digital elevation model is used. You can manually set the elevation to correctly match mountain peaks. If &elevation=nan is specified, downscaling will be disabled and the API uses the average grid-cell height. For multiple locations, elevation can also be comma separated.",
186
+ "required": False,
187
+ },
188
+ "hourly": {
189
+ "type": "string",
190
+ "description": "A list of weather variables which should be returned. Values can be comma separated, or multiple &hourly= parameters in the URL can be used. Support parameters: temperature_2m,relative_humidity_2m,dew_point_2m,apparent_temperature,pressure_msl,cloud_cover,cloud_cover_low,cloud_cover_mid,cloud_cover_high,wind_speed_10m,wind_speed_80m,wind_speed_120m,wind_speed_180m,wind_direction_10m,wind_direction_80m,wind_direction_120m,wind_direction_180m,wind_gusts_10m,shortwave_radiation,direct_radiation,direct_normal_irradiance,diffuse_radiation,global_tilted_irradiance,vapour_pressure_deficit,cape,evapotranspiration,et0_fao_evapotranspiration,precipitation,snowfall,precipitation_probability,rain,showers,weather_code,snow_depth,freezing_level_height,visibility,soil_temperature_0cm,soil_temperature_6cm,soil_temperature_18cm,soil_temperature_54cm,soil_moisture_0_to_1cm,soil_moisture_1_to_3cm,soil_moisture_3_to_9cm,soil_moisture_9_to_27cm,soil_moisture_27_to_81cm",
191
+ "required": False,
192
+ },
193
+ "daily": {
194
+ "type": "string",
195
+ "description": "A list of daily weather variable aggregations which should be returned. Values can be comma separated, or multiple &daily= parameters in the URL can be used. If daily weather variables are specified, parameter timezone is required. Possible values supported temperature_2m_max, temperature_2m_min, apparent_temperature_max, apparent_temperature_min, precipitation_sum, rain_sum, showers_sum, snowfall_sum, precipitation_hours, ,precipitation_probability_max, precipitation_probability_min, precipitation_probability_mean, weather_code,sunrise,sunset,sunshine_duration, daylight_duration, wind_speed_10m_max, wind_gusts_10m_max, wind_direction_10m_dominant,shortwave_radiation_sum,et0_fao_evapotranspiration,uv_index_maxuv_index_clear_sky_max",
196
+ "required": False,
197
+ },
198
+ "temperature_unit": {
199
+ "type": "string",
200
+ "description": "If fahrenheit is set, all temperature values are converted to Fahrenheit.",
201
+ "required": False,
202
+ "default": "celsius",
203
+ },
204
+ "wind_speed_unit": {
205
+ "type": "string",
206
+ "description": "Other wind speed units: ms, mph, and kn.",
207
+ "required": False,
208
+ "default": "kmh",
209
+ },
210
+ "precipitation_unit": {
211
+ "type": "string",
212
+ "description": "Other precipitation amount units: inch.",
213
+ "required": False,
214
+ "default": "mm",
215
+ },
216
+ "timeformat": {
217
+ "type": "string",
218
+ "description": "If format unixtime is selected, all time values are returned in UNIX epoch time in seconds. Please note that all timestamps are in GMT+0! For daily values with unix timestamps, please apply utc_offset_seconds again to get the correct date.",
219
+ "required": False,
220
+ "default": "iso8601",
221
+ },
222
+ "timezone": {
223
+ "type": "string",
224
+ "description": "If timezone is set, all timestamps are returned as local-time and data is returned starting at 00:00 local-time. Any time zone name from the time zone database is supported. If auto is set as a time zone, the coordinates will be automatically resolved to the local time zone. For multiple coordinates, a comma separated list of timezones can be specified.",
225
+ "required": False,
226
+ "default": "GMT",
227
+ },
228
+ "past_days": {
229
+ "type": "integer",
230
+ "description": "If past_days is set, yesterday or the day before yesterday data are also returned.",
231
+ "required": False,
232
+ "default": 0,
233
+ },
234
+ "forecast_days": {
235
+ "type": "integer",
236
+ "description": "Per default, only 7 days are returned. Up to 16 days of forecast are possible.",
237
+ "required": False,
238
+ "default": 7,
239
+ },
240
+ "forecast_hours": {
241
+ "type": "integer",
242
+ "description": "Similar to forecast_days, the number of timesteps of hourly data can be controlled.",
243
+ "required": False,
244
+ },
245
+ "forecast_minutely_15": {
246
+ "type": "integer",
247
+ "description": "The number of timesteps of 15-minutely data can be controlled.",
248
+ "required": False,
249
+ },
250
+ "past_hours": {
251
+ "type": "integer",
252
+ "description": "the number of timesteps of hourly data controlled",
253
+ "required": False,
254
+ },
255
+ "past_minutely_15": {
256
+ "type": "integer",
257
+ "description": "the number of timesteps of 15 minute data controlled",
258
+ "required": False,
259
+ },
260
+ "start_date": {
261
+ "type": "string",
262
+ "description": "The time interval to get weather data. A day must be specified as an ISO8601 date (e.g. 2022-06-30).",
263
+ "required": False,
264
+ },
265
+ "end_date": {
266
+ "type": "string",
267
+ "description": "",
268
+ "required": False,
269
+ },
270
+ "start_hour": {
271
+ "type": "string",
272
+ "description": "The time interval to get weather data for hourly data. Time must be specified as an ISO8601 date and time (e.g. 2022-06-30T12:00).",
273
+ "required": False,
274
+ },
275
+ "end_hour": {
276
+ "type": "string",
277
+ "description": "",
278
+ "required": False,
279
+ },
280
+ "start_minutely_15": {
281
+ "type": "string",
282
+ "description": "",
283
+ "required": False,
284
+ },
285
+ "end_minutely_15": {
286
+ "type": "string",
287
+ "description": "",
288
+ "required": False,
289
+ },
290
+ "models": {
291
+ "type": "list",
292
+ "items": {"type": "string"},
293
+ "description": "A list of string, manually select one or more weather models. Per default, the best suitable weather models will be combined.",
294
+ "required": False,
295
+ },
296
+ "cell_selection": {
297
+ "type": "string",
298
+ "description": "Set a preference how grid-cells are selected. The default land finds a suitable grid-cell on land with similar elevation to the requested coordinates using a 90-meter digital elevation model. sea prefers grid-cells on sea. nearest selects the nearest possible grid-cell.",
299
+ "required": False,
300
+ },
301
+ "apikey": {
302
+ "type": "string",
303
+ "description": "Only required to commercial use to access reserved API resources for customers. The server URL requires the prefix customer-. See pricing for more information.",
304
+ "required": False,
305
+ },
306
+ },
307
+ "allow_redirects": {
308
+ "type": "boolean",
309
+ "description": "A Boolean to enable/disable redirection.",
310
+ "default": True,
311
+ "required": False,
312
+ },
313
+ "auth": {
314
+ "type": "tuple",
315
+ "description": "A tuple to enable a certain HTTP authentication.",
316
+ "default": "None",
317
+ "required": False,
318
+ },
319
+ "cert": {
320
+ "type": ["string", "tuple"],
321
+ "description": "A String or Tuple specifying a cert file or key.",
322
+ "default": "None",
323
+ "required": False,
324
+ },
325
+ "cookies": {
326
+ "type": "dict",
327
+ "additionalProperties": {"type": "string"},
328
+ "description": "Dictionary of cookies to send with the request.",
329
+ "required": False,
330
+ },
331
+ "proxies": {
332
+ "type": "dict",
333
+ "additionalProperties": {"type": "string"},
334
+ "description": "Dictionary of the protocol to the proxy url.",
335
+ "required": False,
336
+ },
337
+ "stream": {
338
+ "type": "boolean",
339
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
340
+ "default": False,
341
+ "required": False,
342
+ },
343
+ "verify": {
344
+ "type": ["boolean", "string"],
345
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
346
+ "default": True,
347
+ "required": False,
348
+ },
349
+ },
350
+ },
351
+ },
352
+ ]
353
+
354
+ PROMPTS = [
355
+ "Can you provide address for latitude 37.4224764 and longitude -122.0842499 using the Geocoding API?",
356
+ "I'm planning a series of long weekend getaways for the upcoming year and I need to know when they'll occur in my country. Could you fetch me the list of long weekends for Canada in the year 2023? I'd like to integrate this information into my holiday planning app.",
357
+ "I'm planning a camping trip and I need to know the weather forecast. Can you fetch me the weather data for the campsite located at latitude 35.68 and longitude -121.34 for the next 10 days including daily temperature and precipitation forecasts? Also, I prefer the temperature 2 minute max in Fahrenheit and sum of precipitation in inches.",
358
+ ]
359
+
360
+ EXAMPLES = [
361
+ {
362
+ "name": "requests.get",
363
+ "description": "Sends a GET request to the specified URL.",
364
+ "parameters": {
365
+ "type": "object",
366
+ "properties": {
367
+ "url": {
368
+ "type": "string",
369
+ "description": "Get statistics for all countries about COVID-19",
370
+ "default": "https://covid-193.p.rapidapi.com/statistics",
371
+ },
372
+ "headers": {
373
+ "properties": {
374
+ "X-RapidAPI-Key": {
375
+ "type": "string",
376
+ "description": "The API key for authenticating requests to RapidAPI.",
377
+ },
378
+ "X-RapidAPI-Host": {
379
+ "type": "string",
380
+ "description": "The host domain for the RapidAPI service being accessed.",
381
+ },
382
+ },
383
+ "type": "object",
384
+ "required": ["X-RapidAPI-Key", "X-RapidAPI-Host"],
385
+ },
386
+ "timeout": {
387
+ "type": "string",
388
+ "description": "How many seconds to wait for the server to send data before giving up.",
389
+ },
390
+ "params": {
391
+ "properties": {
392
+ "country": {
393
+ "type": "string",
394
+ "description": "Name of the country to retrieve data for. Use '[All]' to indicate a global history request.",
395
+ }
396
+ },
397
+ "type": "object",
398
+ "required": [],
399
+ },
400
+ "allow_redirects": {
401
+ "type": "boolean",
402
+ "description": "A Boolean to enable/disable redirection.",
403
+ "default": True,
404
+ },
405
+ "auth": {
406
+ "type": "tuple",
407
+ "description": "A tuple to enable a certain HTTP authentication.",
408
+ "default": "None",
409
+ },
410
+ "cert": {
411
+ "type": "string",
412
+ "description": "A String or Tuple specifying a cert file or key.",
413
+ "default": "None",
414
+ },
415
+ "cookies": {
416
+ "type": "object",
417
+ "additionalProperties": {"type": "string"},
418
+ "description": "Dictionary of cookies to send with the request.",
419
+ },
420
+ "proxies": {
421
+ "type": "object",
422
+ "additionalProperties": {"type": "string"},
423
+ "description": "Dictionary of the protocol to the proxy url.",
424
+ },
425
+ "stream": {
426
+ "type": "boolean",
427
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
428
+ "default": False,
429
+ },
430
+ "verify": {
431
+ "type": "string",
432
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
433
+ "default": True,
434
+ },
435
+ },
436
+ },
437
+ "required": ["url"],
438
+ },
439
+ {
440
+ "name": "requests.get",
441
+ "description": "Sends a GET request to the specified URL.",
442
+ "parameters": {
443
+ "type": "object",
444
+ "properties": {
445
+ "url": {
446
+ "type": "string",
447
+ "description": "Geocoding API converting a human-readable address into a pair of latitude and longitude coordinates",
448
+ "default": "https://geocode.maps.co/search",
449
+ },
450
+ "headers": {"properties": {}, "type": "object", "required": []},
451
+ "timeout": {
452
+ "type": "string",
453
+ "description": "How many seconds to wait for the server to send data before giving up.",
454
+ },
455
+ "params": {
456
+ "properties": {
457
+ "lat": {
458
+ "type": "number",
459
+ "description": "Latitude of the location to reverse geocode.",
460
+ },
461
+ "lon": {
462
+ "type": "number",
463
+ "description": "Longitude of the location to reverse geocode.",
464
+ },
465
+ "api_key": {
466
+ "type": "string",
467
+ "description": "Your API key for authentication.",
468
+ },
469
+ "format": {
470
+ "type": "string",
471
+ "description": "The desired response format. Options include 'xml', 'json', 'jsonv2', 'geojson', 'geocodejson'. Default is 'json'.",
472
+ },
473
+ },
474
+ "type": "object",
475
+ "required": ["lat", "lon", "api_key"],
476
+ },
477
+ "allow_redirects": {
478
+ "type": "boolean",
479
+ "description": "A Boolean to enable/disable redirection.",
480
+ "default": True,
481
+ },
482
+ "auth": {
483
+ "type": "tuple",
484
+ "description": "A tuple to enable a certain HTTP authentication.",
485
+ "default": "None",
486
+ },
487
+ "cert": {
488
+ "type": "string",
489
+ "description": "A String or Tuple specifying a cert file or key.",
490
+ "default": "None",
491
+ },
492
+ "cookies": {
493
+ "type": "object",
494
+ "additionalProperties": {"type": "string"},
495
+ "description": "Dictionary of cookies to send with the request.",
496
+ },
497
+ "proxies": {
498
+ "type": "object",
499
+ "additionalProperties": {"type": "string"},
500
+ "description": "Dictionary of the protocol to the proxy url.",
501
+ },
502
+ "stream": {
503
+ "type": "boolean",
504
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
505
+ "default": False,
506
+ },
507
+ "verify": {
508
+ "type": "string",
509
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
510
+ "default": True,
511
+ },
512
+ },
513
+ },
514
+ "required": ["url"],
515
+ },
516
+ {
517
+ "name": "requests.get",
518
+ "description": "Sends a GET request to the specified URL.",
519
+ "parameters": {
520
+ "type": "object",
521
+ "properties": {
522
+ "url": {
523
+ "type": "string",
524
+ "description": "Fetches the age rating of a movie from the OMDB API.",
525
+ "default": "http://www.omdbapi.com/",
526
+ },
527
+ "headers": {"properties": {}, "type": "object", "required": []},
528
+ "timeout": {
529
+ "type": "string",
530
+ "description": "How many seconds to wait for the server to send data before giving up.",
531
+ },
532
+ "params": {
533
+ "properties": {
534
+ "i": {
535
+ "type": "string",
536
+ "description": "A valid IMDb ID (e.g., tt1285016).",
537
+ },
538
+ "t": {
539
+ "type": "string",
540
+ "description": "Movie title to search for.",
541
+ },
542
+ "type": {
543
+ "type": "string",
544
+ "description": "Type of result to return. Valid options are 'movie', 'series', and 'episode'.",
545
+ },
546
+ "y": {"type": "string", "description": "Year of release."},
547
+ "plot": {
548
+ "type": "string",
549
+ "description": "Return short or full plot. Default is 'short'.",
550
+ },
551
+ "r": {
552
+ "type": "string",
553
+ "description": "The data type to return. Default is 'json'.",
554
+ },
555
+ "callback": {
556
+ "type": "string",
557
+ "description": "JSONP callback name.",
558
+ },
559
+ "v": {
560
+ "type": "integer",
561
+ "description": "API version (reserved for future use). Default is 1.",
562
+ },
563
+ },
564
+ "type": "object",
565
+ "required": [],
566
+ },
567
+ "allow_redirects": {
568
+ "type": "boolean",
569
+ "description": "A Boolean to enable/disable redirection.",
570
+ "default": True,
571
+ },
572
+ "auth": {
573
+ "type": "tuple",
574
+ "description": "A tuple to enable a certain HTTP authentication.",
575
+ "default": "None",
576
+ },
577
+ "cert": {
578
+ "type": "string",
579
+ "description": "A String or Tuple specifying a cert file or key.",
580
+ "default": "None",
581
+ },
582
+ "cookies": {
583
+ "type": "object",
584
+ "additionalProperties": {"type": "string"},
585
+ "description": "Dictionary of cookies to send with the request.",
586
+ },
587
+ "proxies": {
588
+ "type": "object",
589
+ "additionalProperties": {"type": "string"},
590
+ "description": "Dictionary of the protocol to the proxy url.",
591
+ },
592
+ "stream": {
593
+ "type": "boolean",
594
+ "description": "A Boolean indication if the response should be immediately downloaded (False) or streamed (True).",
595
+ "default": False,
596
+ },
597
+ "verify": {
598
+ "type": "string",
599
+ "description": "A Boolean or a String indication to verify the servers TLS certificate or not.",
600
+ "default": True,
601
+ },
602
+ },
603
+ },
604
+ "required": ["url"],
605
+ },
606
+ ]
607
+
608
+ PROMPTS = [
609
+ "While I'm working on a dashboard to display real-time COVID-19 statistics for Uganda, including total cases, recoveries, and deaths, I realized I need to use the API Sports COVID-19 API for accurate data. Given that I have my API key as '123456' and the host as 'covid-193.p.rapidapi.com', how can I fetch the latest statistics ensuring the request times out if it takes longer than 10 seconds? Also, how can I make sure the response is not streamed?",
610
+ "Use my API key '123456', can you convert the address 'Soda Hall, Berkeley, CA' to latitude and longitude coordinates using our Geocoding API, and also make sure to return the results in GeoJSON format?",
611
+ "I'm looking to fetch the full plot details for the movie 'Gorilla' from the OMDB API. Can you provide me with the Python requests.get code to retrieve the information in JSON format? I can provide the API key, it's '123456'.",
612
+ ]
613
+
614
+ COLUMNS = [
615
+ "Rank",
616
+ "Overall Acc",
617
+ "Model",
618
+ "Organization",
619
+ "License",
620
+ "Simple Function AST",
621
+ "Multiple Functions AST",
622
+ "Parallel Functions AST",
623
+ "Parallel Multiple AST",
624
+ "Simple Function Exec",
625
+ "Multiple Functions Exec",
626
+ "Parallel Functions Exec",
627
+ "Parallel Multiple Exec",
628
+ "Relevance Detection",
629
+ ]
630
+ DATA = [
631
+ (
632
+ 1,
633
+ 83.80,
634
+ "GPT-4-0125-Preview",
635
+ "OpenAI",
636
+ "Proprietary",
637
+ 82.18,
638
+ 90.00,
639
+ 90.00,
640
+ 91.00,
641
+ 54.12,
642
+ 70.00,
643
+ 76.00,
644
+ 55.00,
645
+ 87.50,
646
+ ),
647
+ (
648
+ 2,
649
+ 83.55,
650
+ "GPT-4-1106-Preview",
651
+ "OpenAI",
652
+ "Proprietary",
653
+ 81.64,
654
+ 89.50,
655
+ 92.00,
656
+ 92.00,
657
+ 53.53,
658
+ 62.00,
659
+ 72.00,
660
+ 50.00,
661
+ 88.75,
662
+ ),
663
+ (
664
+ 3,
665
+ 83.55,
666
+ "Gorilla-OpenFunctions-v2",
667
+ "Gorilla LLM",
668
+ "Apache 2.0",
669
+ 88.73,
670
+ 89.50,
671
+ 79.50,
672
+ 78.00,
673
+ 78.82,
674
+ 74.00,
675
+ 76.00,
676
+ 60.00,
677
+ 71.67,
678
+ ),
679
+ (
680
+ 4,
681
+ 81.63,
682
+ "GPT-3.5-Turbo",
683
+ "OpenAI",
684
+ "Proprietary",
685
+ 81.27,
686
+ 88.00,
687
+ 87.50,
688
+ 88.00,
689
+ 74.12,
690
+ 74.00,
691
+ 70.00,
692
+ 47.50,
693
+ 68.33,
694
+ ),
695
+ (
696
+ 5,
697
+ 79.46,
698
+ "Mistral-Medium",
699
+ "Mistral AI",
700
+ "Proprietary",
701
+ 80.18,
702
+ 84.50,
703
+ 71.00,
704
+ 68.00,
705
+ 75.88,
706
+ 72.00,
707
+ 62.00,
708
+ 47.50,
709
+ 90.00,
710
+ ),
711
+ (
712
+ 6,
713
+ 75.78,
714
+ "Claude-2.1",
715
+ "Anthropic",
716
+ "Proprietary",
717
+ 85.64,
718
+ 83.00,
719
+ 72.00,
720
+ 56.50,
721
+ 61.18,
722
+ 48.00,
723
+ 60.00,
724
+ 45.00,
725
+ 78.33,
726
+ ),
727
+ (
728
+ 7,
729
+ 59.52,
730
+ "Mistral-tiny",
731
+ "Mistral AI",
732
+ "Proprietary",
733
+ 59.27,
734
+ 59.50,
735
+ 53.50,
736
+ 41.50,
737
+ 58.24,
738
+ 64.00,
739
+ 42.00,
740
+ 40.00,
741
+ 77.08,
742
+ ),
743
+ (
744
+ 8,
745
+ 59.22,
746
+ "Claude-instant",
747
+ "Anthropic",
748
+ "Proprietary",
749
+ 68.73,
750
+ 59.00,
751
+ 53.00,
752
+ 39.50,
753
+ 51.76,
754
+ 52.00,
755
+ 50.00,
756
+ 37.50,
757
+ 61.67,
758
+ ),
759
+ (
760
+ 9,
761
+ 55.84,
762
+ "Mistral-large",
763
+ "Mistral AI",
764
+ "Proprietary",
765
+ 71.82,
766
+ 90.50,
767
+ 4.00,
768
+ 0.00,
769
+ 61.76,
770
+ 66.00,
771
+ 0.00,
772
+ 5.00,
773
+ 84.58,
774
+ ),
775
+ (
776
+ 10,
777
+ 54.99,
778
+ "Gemini-1.0-Pro",
779
+ "Google",
780
+ "Proprietary",
781
+ 78.43,
782
+ 89.00,
783
+ 4.00,
784
+ 0.00,
785
+ 46.12,
786
+ 62.00,
787
+ 0.00,
788
+ 0.00,
789
+ 77.50,
790
+ ),
791
+ (
792
+ 11,
793
+ 54.46,
794
+ "Nexusflow-Raven-v2",
795
+ "Nexusflow",
796
+ "Apache 2.0",
797
+ 76.55,
798
+ 83.50,
799
+ 39.50,
800
+ 34.00,
801
+ 45.88,
802
+ 78.00,
803
+ 68.00,
804
+ 45.00,
805
+ 0.00,
806
+ ),
807
+ (
808
+ 12,
809
+ 53.95,
810
+ "FireFunction-v1",
811
+ "Fireworks",
812
+ "Apache 2.0",
813
+ 73.19,
814
+ 87.00,
815
+ 4.00,
816
+ 0.00,
817
+ 48.24,
818
+ 64.00,
819
+ 0.00,
820
+ 5.00,
821
+ 81.25,
822
+ ),
823
+ (
824
+ 13,
825
+ 53.86,
826
+ "Mistral-small",
827
+ "Mistral AI",
828
+ "Proprietary",
829
+ 46.55,
830
+ 68.00,
831
+ 48.50,
832
+ 58.00,
833
+ 14.12,
834
+ 30.00,
835
+ 40.00,
836
+ 37.50,
837
+ 89.58,
838
+ ),
839
+ (
840
+ 14,
841
+ 53.49,
842
+ "GPT-4-0613",
843
+ "OpenAI",
844
+ "Proprietary",
845
+ 74.55,
846
+ 86.00,
847
+ 4.00,
848
+ 0.00,
849
+ 37.65,
850
+ 50.00,
851
+ 0.00,
852
+ 0.00,
853
+ 87.08,
854
+ ),
855
+ (
856
+ 15,
857
+ 44.46,
858
+ "Gemma",
859
+ "Google",
860
+ "gemma-terms-of-use",
861
+ 61.45,
862
+ 60.00,
863
+ 41.00,
864
+ 32.00,
865
+ 45.88,
866
+ 46.00,
867
+ 44.00,
868
+ 25.00,
869
+ 0.42,
870
+ ),
871
+ (
872
+ 16,
873
+ 43.19,
874
+ "Deepseek-v1.5",
875
+ "Deepseek",
876
+ "Deepseek License",
877
+ 48.36,
878
+ 61.00,
879
+ 35.00,
880
+ 43.50,
881
+ 5.29,
882
+ 2.00,
883
+ 0.00,
884
+ 7.50,
885
+ 66.25,
886
+ ),
887
+ (
888
+ 17,
889
+ 33.61,
890
+ "Gorilla-OpenFunctions-v0",
891
+ "Gorilla LLM",
892
+ "Apache 2.0",
893
+ 60.00,
894
+ 56.00,
895
+ 1.00,
896
+ 2.50,
897
+ 39.41,
898
+ 62.00,
899
+ 0.00,
900
+ 0.00,
901
+ 4.58,
902
+ ),
903
+ (
904
+ 18,
905
+ 24.76,
906
+ "Glaive-v1",
907
+ "Glaive",
908
+ "cc-by-sa-4.0",
909
+ 34.55,
910
+ 26.00,
911
+ 2.00,
912
+ 0.00,
913
+ 21.18,
914
+ 34.00,
915
+ 0.00,
916
+ 2.50,
917
+ 46.25,
918
+ ),
919
+ ]
920
+
921
+ MODELS = [
922
+ "gorilla-openfunctions-v2",
923
+ "gpt-4-1106-preview-fc",
924
+ "gpt-4-0125-preview-fc",
925
+ "gpt-3.5-turbo-0125-fc",
926
+ "mistral-large-fc"
927
+ ]
928
+
929
+
930
+ def send_feedback(prompt, function, model, temperature, codeOutput, jsonOutput, vote):
931
+ # Login and get access token
932
+ print("Sending feedback")
933
+ login_url = 'https://us-west-2.aws.realm.mongodb.com/api/client/v2.0/app/data-onwzq/auth/providers/local-userpass/login'
934
+ headers = {'Content-Type': 'application/json'}
935
+ login_data = {
936
+ 'username': 'website',
937
+ 'password': 'mongoDBPassword'
938
+ }
939
+ response = requests.post(login_url, headers=headers, json=login_data)
940
+ access_token = response.json()['access_token']
941
+ # Prepare data for sending feedback
942
+ url = 'https://us-west-2.aws.data.mongodb-api.com/app/data-onwzq/endpoint/data/v1/action/insertOne'
943
+ headers = {
944
+ 'Content-Type': 'application/json',
945
+ 'Access-Control-Request-Headers': '*',
946
+ 'Authorization': f'Bearer {access_token}'
947
+ }
948
+
949
+
950
+ if not prompt or not function:
951
+ return
952
+
953
+ body = {
954
+ 'collection': "vote",
955
+ 'database': "gorilla-feedback",
956
+ 'dataSource': "gorilla",
957
+ 'document': {
958
+ 'prompt': prompt,
959
+ 'funcDef': function,
960
+ 'temperature': temperature,
961
+ 'model': model,
962
+ 'codeOutput': codeOutput,
963
+ 'jsonOutput': jsonOutput,
964
+ 'result': vote
965
+ }
966
+ }
967
+
968
+ # Send feedback
969
+ response = requests.post(url, headers=headers, json=body)
970
+ if response.ok:
971
+ print("Document inserted:", response.json())
972
+ else:
973
+ print('Error:', response.text)
974
+
975
+ def send_feedback_negative(prompt, function, model, temperature, codeOutput, jsonOutput):
976
+ return send_feedback(prompt, function, model, temperature, codeOutput, jsonOutput, "negative")
977
+
978
+ def send_feedback_positive(prompt, function, model, temperature, codeOutput, jsonOutput):
979
+ return send_feedback(prompt, function, model, temperature, codeOutput, jsonOutput, "positive")
980
+
981
+
982
+ def report_issue(prompt, model, temperature, codeOutput, jsonOutput):
983
+ print("Reporting issue")
984
+ issueTitle = "[bug] OpenFunctions-v2: "
985
+ issueBody = f"**Issue Description**\n\nPrompt: {prompt}\n\nModel: {model}\n\nTemperature: {temperature}\n\nOutput (or Error if request failed): {codeOutput} \n\n {jsonOutput}\n\n**Additional Information**\n"
986
+ webbrowser.open_new_tab(
987
+ f"https://github.com/ShishirPatil/gorilla/issues/new?assignees=&labels=hosted-openfunctions-v2&projects=&template=hosted-openfunctions-v2.md&title=${issueTitle}&body=${issueBody}"
988
+ )
989
+
990
+
991
+ def fill_example(index):
992
+ prompt = PROMPTS[index]
993
+ function = EXAMPLES[index]
994
+ model = "gorilla-openfunctions-v2"
995
+ return prompt, json.dumps(function, indent=2), model
996
+
997
+
998
+ def cast_multi_param_type(properties):
999
+ """
1000
+ OpenAI rejects parameters type other than JSON serializable type.
1001
+ Since our evaluation contains Python specific types, we need some casting
1002
+ """
1003
+ for key, value in properties.items():
1004
+ if "type" not in value:
1005
+ properties[key]["type"] = "string"
1006
+ else:
1007
+ value["type"] = value["type"].lower()
1008
+ if value["type"] not in [
1009
+ "object",
1010
+ "string",
1011
+ "number",
1012
+ "boolean",
1013
+ "array",
1014
+ "integer",
1015
+ ]:
1016
+ properties[key]["type"] = "string"
1017
+ elif value["type"] == "array" and "items" not in properties[key].keys():
1018
+ properties[key]["items"] = {"type": "object"}
1019
+ elif (
1020
+ value["type"] == "array"
1021
+ and "type" not in properties[key]["items"].keys()
1022
+ ):
1023
+ properties[key]["items"]["type"] = "object"
1024
+ elif value["type"] == "array" and properties[key]["items"]["type"] not in [
1025
+ "object",
1026
+ "string",
1027
+ "number",
1028
+ "boolean",
1029
+ "array",
1030
+ "integer",
1031
+ ]:
1032
+ properties[key]["items"]["type"] = "string"
1033
+ return properties
1034
+
1035
+
1036
+ def get_gorilla_response(prompt, function, model, temperature):
1037
+ requestData = {
1038
+ "model": model,
1039
+ "messages": [{"role": "user", "content": prompt}],
1040
+ "functions": [function],
1041
+ "temperature": temperature,
1042
+ }
1043
+ url = "https://luigi.millennium.berkeley.edu:443/v1/chat/completions"
1044
+ response = requests.post(
1045
+ url,
1046
+ headers={
1047
+ "Content-Type": "application/json",
1048
+ "Authorization": "EMPTY", # Hosted for free with ❀️ from UC Berkeley
1049
+ },
1050
+ data=json.dumps(requestData),
1051
+ )
1052
+ jsonResponse = response.json()
1053
+ directCode = jsonResponse["choices"][0]["message"]["content"]
1054
+ jsonCode = jsonResponse["choices"][0]["message"]["function_call"]
1055
+ jsonFormatted = json.dumps(jsonCode, indent=2)
1056
+ return directCode, jsonFormatted
1057
+
1058
+
1059
+ def get_openai_response(prompt, function, model, temperature):
1060
+ model = model[:-3]
1061
+ client = OpenAI(api_key=openaiKey)
1062
+ oai_tool = []
1063
+ function = json.loads(function)
1064
+ item = function # use item in the later code
1065
+ if "." in item["name"]:
1066
+ item["name"] = re.sub(
1067
+ r"\.", "_", item["name"]
1068
+ ) # OAI does not support "." in the function name so we replace it with "_". ^[a-zA-Z0-9_-]{1,64}$ is the regex for the name.
1069
+ item["parameters"][
1070
+ "type"
1071
+ ] = "object" # If typing is missing, we assume it is an object since OAI requires a type.
1072
+ if "properties" not in item["parameters"]:
1073
+ item["parameters"]["properties"] = item["parameters"].copy()
1074
+ item["parameters"]["type"] = "object"
1075
+ for key in list(item["parameters"].keys()).copy():
1076
+ if key != "properties" and key != "type" and key != "required":
1077
+ del item["parameters"][key]
1078
+ for key in list(item["parameters"]["properties"].keys()).copy():
1079
+ if key == "required" or key == "type":
1080
+ del item["parameters"]["properties"][key]
1081
+ item["parameters"]["properties"] = cast_multi_param_type(
1082
+ item["parameters"]["properties"]
1083
+ )
1084
+ oai_tool.append({"type": "function", "function": item})
1085
+ message = [{"role": "user", "content": "Questions: " + prompt}]
1086
+ if len(oai_tool) > 0:
1087
+ response = client.chat.completions.create(
1088
+ messages=message,
1089
+ model=model,
1090
+ temperature=temperature,
1091
+ tools=oai_tool,
1092
+ )
1093
+ else:
1094
+ response = client.chat.completions.create(
1095
+ messages=message,
1096
+ model=model,
1097
+ temperature=temperature,
1098
+ )
1099
+ try:
1100
+ func_call = response.choices[0].message.tool_calls[0]
1101
+ result = {func_call.function.name: func_call.function.arguments}
1102
+ try:
1103
+ key = list(result.keys())[0]
1104
+ result[key] = json.loads(result[key])
1105
+ result = json.dumps(result, indent=2)
1106
+ return "No direct code output for this model.", result
1107
+ except:
1108
+ return "No direct code output for this model.", result
1109
+ except:
1110
+ result = response.choices[0].message.content
1111
+ return result, "The model failed to return a JSON output."
1112
+
1113
+
1114
+ def get_mistral_response(prompt, function, model, temperature):
1115
+ client = MistralClient(api_key= mistralKey)
1116
+ oai_tool = []
1117
+ function = json.loads(function)
1118
+ item = function # use item in the later code
1119
+ if "." in item["name"]:
1120
+ item["name"] = re.sub(
1121
+ r"\.", "_", item["name"]
1122
+ ) # OAI does not support "." in the function name so we replace it with "_". ^[a-zA-Z0-9_-]{1,64}$ is the regex for the name.
1123
+ item["parameters"]["type"] = "object" # If typing is missing, we assume it is an object since OAI requires a type.
1124
+ if "properties" not in item["parameters"]:
1125
+ item["parameters"]["properties"] = item["parameters"].copy()
1126
+ item["parameters"]["type"] = "object"
1127
+ for key in list(item["parameters"].keys()).copy():
1128
+ if key != "properties" and key != "type" and key != "required":
1129
+ del item["parameters"][key]
1130
+ for key in list(item["parameters"]["properties"].keys()).copy():
1131
+ if key == "required" or key == "type":
1132
+ del item["parameters"]["properties"][key]
1133
+ item["parameters"]["properties"] = cast_multi_param_type(
1134
+ item["parameters"]["properties"]
1135
+ )
1136
+ oai_tool.append({"type": "function", "function": item})
1137
+ message = [
1138
+ ChatMessage(role="user", content=prompt),
1139
+ ]
1140
+ chat_response = client.chat(
1141
+ model="mistral-large-latest",
1142
+ messages=message,
1143
+ tools = oai_tool,
1144
+ temperature=temperature,
1145
+ )
1146
+ try:
1147
+ func_call = chat_response.choices[0].message.tool_calls[0]
1148
+ result = {func_call.function.name: func_call.function.arguments}
1149
+ try:
1150
+ key = list(result.keys())[0]
1151
+ result[key] = json.loads(result[key])
1152
+ result = json.dumps(result, indent=2)
1153
+ return "No direct code output for this model.", result
1154
+ except:
1155
+ return "No direct code output for this model.", result
1156
+ except:
1157
+ result = chat_response.choices[0].message.content
1158
+ return result, "The model failed to return a JSON output."
1159
+
1160
+
1161
+ def distribute_task(prompt, function, model, temperature):
1162
+ if "gpt" in model:
1163
+ return get_openai_response(prompt, function, model, temperature)
1164
+ elif "mistral" in model:
1165
+ return get_mistral_response(prompt, function, model, temperature)
1166
+ else:
1167
+ return get_gorilla_response(prompt, function, model, temperature)
1168
+ return "", ""
1169
+
1170
+
1171
+ def get_leaderboard():
1172
+ # Convert the leaderboard data to a pandas DataFrame for easier handling and display
1173
+ leaderboard_df = pd.DataFrame(DATA, columns=COLUMNS)
1174
+ return leaderboard_df
1175
+
1176
+
1177
+ # Initialize the leaderboard data so it's loaded when the page is opened
1178
+ initial_leaderboard_data = get_leaderboard()
1179
+
1180
+ prompt = gr.Textbox(label="Prompt", placeholder="Type your prompt here...", lines=4)
1181
+ funcDescription = gr.Textbox(
1182
+ label="Function Description", placeholder="Describe the function...", lines=20
1183
+ )
1184
+ model = gr.Dropdown(label="Model", choices=MODELS)
1185
+
1186
+
1187
+ with gr.Blocks() as demo:
1188
+ with gr.Tabs():
1189
+ with gr.TabItem("Leaderboard"):
1190
+ gr.Markdown("**This live leaderboard evaluates the LLM's ability to call functions (aka tools) accurately. This leaderboard consists of real-world data and will be updated periodically. For more information on the evaluation dataset and methodology, please refer to our [blog](https://gorilla.cs.berkeley.edu/blogs/8_berkeley_function_calling_leaderboard.html) and [code](https://github.com/ShishirPatil/gorilla).**")
1191
+ gr.Markdown(
1192
+ "**Note: AST means evaluation through Abstract Syntax Tree and Exec means evaluation through execution.**"
1193
+ )
1194
+ leaderboard_data = gr.Dataframe(
1195
+ value=get_leaderboard(), wrap=True
1196
+ )
1197
+
1198
+ with gr.TabItem("Try It Out"):
1199
+ with gr.Row():
1200
+ with gr.Column(scale=1):
1201
+ with gr.Row():
1202
+ example1 = gr.Button("Example 1").click(
1203
+ fn=lambda: fill_example(0),
1204
+ outputs=[prompt, funcDescription, model],
1205
+ )
1206
+ example2 = gr.Button("Example 2").click(
1207
+ fn=lambda: fill_example(1),
1208
+ outputs=[prompt, funcDescription, model],
1209
+ )
1210
+ example3 = gr.Button("Example 3").click(
1211
+ fn=lambda: fill_example(2),
1212
+ outputs=[prompt, funcDescription, model],
1213
+ )
1214
+
1215
+ with gr.Row():
1216
+ model.render()
1217
+ temperature = gr.Slider(
1218
+ label="Temperature",
1219
+ minimum=0.1,
1220
+ maximum=1.0,
1221
+ value=0.7,
1222
+ step=0.1,
1223
+ )
1224
+ prompt.render()
1225
+ funcDescription.render()
1226
+ submit_button = gr.Button("Submit")
1227
+ with gr.Column(scale=1):
1228
+ codeOutput = gr.Textbox(
1229
+ label="Code Output",
1230
+ placeholder="Code output will be displayed here...",
1231
+ lines=7,
1232
+ )
1233
+ jsonOutput = gr.Textbox(
1234
+ label="JSON Format (OpenAI compatible)",
1235
+ placeholder="JSON format will be displayed here...",
1236
+ lines=20,
1237
+ )
1238
+ with gr.Row():
1239
+ thumbs_up = gr.Button("πŸ‘")
1240
+ thumbs_down = gr.Button("πŸ‘Ž")
1241
+ regenerate_button = gr.Button("Regenerate")
1242
+ report_issue_button = gr.Button("Report Issue")
1243
+
1244
+
1245
+ # Actions
1246
+ submit_button.click(
1247
+ fn=distribute_task,
1248
+ inputs=[prompt, funcDescription, model, temperature],
1249
+ outputs=[codeOutput, jsonOutput],
1250
+ )
1251
+
1252
+ regenerate_button.click(
1253
+ fn=distribute_task,
1254
+ inputs=[prompt, funcDescription, model, temperature],
1255
+ outputs=[codeOutput, jsonOutput],
1256
+ )
1257
+
1258
+ report_issue_button.click(
1259
+ fn=None,
1260
+ inputs=[prompt, model, temperature, codeOutput, jsonOutput],
1261
+ outputs=[],
1262
+ js='(prompt, model, temperature, codeOutput, jsonOutput) => window.open(`https://github.com/ShishirPatil/gorilla/issues/new?assignees=&labels=hosted-openfunctions-v2&projects=&template=hosted-openfunctions-v2.md&title=[bug] OpenFunctions-v2: &body=**Issue Description**%0A%0APrompt: ${prompt}%0A%0AModel: ${model}%0A%0ATemperature: ${temperature}%0A%0AOutput (or Error if request failed): ${codeOutput} %0A%0A ${jsonOutput}%0A%0A**Additional Information**\n`, "_blank")'
1263
+ )
1264
+
1265
+ thumbs_up.click(
1266
+ fn=send_feedback_positive,
1267
+ inputs=[prompt, funcDescription, model, temperature, codeOutput, jsonOutput],
1268
+ outputs=[],
1269
+ )
1270
+
1271
+ thumbs_down.click(
1272
+ fn=send_feedback_negative,
1273
+ inputs=[prompt, funcDescription, model, temperature, codeOutput, jsonOutput],
1274
+ outputs=[],
1275
+ )
1276
+
1277
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai==1.11.1
2
+ pandas==2.2.1
3
+ mistralai==0.1.3