1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You will be provided with csv data. Convert this into json. "},
{
"role": "user",
"content": "The following is csv: Year,'Number of deaths','Vehicles (millions)','Vehicle miles (billions)','Drivers (millions)','Death rates Per 10,000 motor vehicles','Death rates Per 100,000,000 vehicle miles','Death rates Per 100,000 population'\n1970,'54,633',111.2,'1,120',111.5,4.92,4.88,26.8 \n1971,'54,381',116.3,'1,186',114.4,4.68,4.57,26.3 \n1972,'56,278',122.3,'1,268',118.4,4.60,4.43,26.9 \n1973,'55,511',129.8,'1,309',121.6,4.28,4.24,26.3 \n1974,'46,402',134.9,'1,290',125.6,3.44,3.59,21.8 \n1975,'45,853',137.9,'1,330',129.8,3.33,3.45,21.3 \n1976,'47,038',143.5,'1,412',133.9,3.28,3.33,21.6 \n1977,'49,510',148.8,'1,477',138.1,3.33,3.35,22.5 \n1978,'52,411',153.6,'1,548',140.8,3.41,3.39,23.6 \n1979,'53,524',159.6,'1,529',143.3,3.35,3.50,23.8 \n1980,'53,172',161.6,'1,521',145.3,3.29,3.50,23.4 \n1981,'51,385',164.1,'1,556',147.1,3.13,3.30,22.4 \n1982,'45,779',165.2,'1,592',150.3,2.77,2.88,19.8 \n1983,'44,452',169.4,'1,657',154.2,2.62,2.68,19.0 \n1984,'46,263',171.8,'1,718',155.4,2.69,2.69,19.6 \n1985,'45,901',177.1,'1,774',156.9,2.59,2.59,19.3 \n1986,'47,865',181.4,'1,835',159.5,2.63,2.60,19.9 \n1987,'48,290',183.9,'1,924',161.8,2.63,2.51,19.9 \n1988,'49,078',189.0,'2,026',162.9,2.60,2.42,20.1 \n1989,'47,575',191.7,'2,107',165.6,2.48,2.26,19.3 \n1990,'46,814',192.9,'2,148',167.0,2.43,2.18,18.8 \n1991,'43,536',192.5,'2,172',169.0,2.26,2.00,17.3 \n1992,'40,982',194.4,'2,240',173.1,2.11,1.83,16.1 \n1993,'41,893',198.0,'2,297',173.1,2.12,1.82,16.3 \n1994,'42,524',201.8,'2,360',175.4,2.11,1.80,16.3 \n1995,'43,363',205.3,'2,423',176.6,2.11,1.79,16.5 \n1996,'43,649',210.4,'2,486',179.5,2.07,1.76,16.5 \n1997,'43,458',211.5,'2,562',182.7,2.05,1.70,16.2 \n1998,'43,501',215.0,'2,632',185.2,2.02,1.65,16.1 \n1999,'42,401',220.5,'2,691',187.2,1.92,1.58,15.5 \n2000,'43,354',225.8,'2,747',190.6,1.92,1.58,15.8 \n2001,'43,788',235.3,'2,797',191.3,1.86,1.57,15.4 \n2002,'45,380',234.6,'2,856',194.3,1.93,1.59,15.8 \n2003,'44,757',236.8,'2,890',196.2,1.89,1.55,15.4 \n2004,'44,933',243.0,'2,965',199.0,1.85,1.52,15.3 \n2005,'45,343',247.4,'2,989',200.5,1.83,1.52,15.3 \n2006,'45,316',250.8,'3,014',202.8,1.81,1.50,15.2 \n2007,'43,945',254.4,'3,032',205.7,1.73,1.45,14.6 \n2008,'39,790',255.9,'2,976',208.3,1.55,1.34,13.1 \n2009,'36,216',254.2,'2,957',209.6,1.42,1.22,11.8 \n2010,'35,332',250.3,'2,967',210.1,1.41,1.19,11.4 \n2011,'35,303',253.2,'2,950',211.9,1.39,1.20,11.3 \n2012,'36,415',253.6,'2,969',211.8,1.44,1.23,11.6 \n2013,'35,369',255.9,'2,988',212.2,1.38,1.18,11.2 \n2014,'35,398',260.3,'3,026',214.1,1.36,1.17,11.1 \n2015,'37,757',263.6,'3,095',218.1,1.43,1.22,11.8 \n2016,'40,327',268.8,'3,174',221.7,1.50,1.27,12.5 \n2017,'40,231',272.5,'3,212',225.3,1.48,1.25,12.4 \n2018,'39,404',276.6,'3,240',227.6,1.42,1.22,12.0 \n2019,'39,107',276.5,'3,262',228.7,1.41,1.20,11.9 \n2020,'42,338',275.9,'2,904',228.2,1.53,1.46,12.9 \n2021,'46,980',282.4,'3,140',232.8,1.53,1.38,14.2 \n2022,'46,027',283.4,'3,196',235.1,1.50,1.33,13.8 \n"
}
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "highway_taffic_safety_schema",
"schema": {
"type": "object",
"properties": {
"year": {
"description": "Year",
"type": "integer"
},
"num_of_deaths": {
"description": "Number of deaths",
"type": "number"
},
"vehicle_count": {
"description": "Vehicles (millions)",
"type": "number"
},
"venhicle_miles": {
"description": "Vehicle miles (billions)",
"type": "number"
},
"driver_count": {
"description": "Drivers (millions)",
"type": "number"
},
"death_rate_vehicles": {
"description": "Death rates Per 10,000 motor vehicles",
"type": "number"
},
"death_rate_vehicle_miles": {
"description": "Death rates Per 100,000,000 vehicle miles",
"type": "number"
},
"death_rate_population": {
"description": "Death rates Per 100,000 population",
"type": "number"
}
},
"additionalProperties": False
}
}
}
)
print(completion.choices[0].message.content)
|