From e0eee85d67b3cf8d885d472980b03b3e819ef8c3 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Mon, 3 Jun 2024 14:53:48 -0700 Subject: [PATCH] update what i have for function calling Signed-off-by: Matt Williams --- 2024-02-15-functioncalling/fc.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 2024-02-15-functioncalling/fc.py diff --git a/2024-02-15-functioncalling/fc.py b/2024-02-15-functioncalling/fc.py new file mode 100644 index 0000000..115bcb8 --- /dev/null +++ b/2024-02-15-functioncalling/fc.py @@ -0,0 +1,46 @@ +import requests +import json +import sys +from haversine import haversine + +country = sys.argv[1] +mylat = 47.60621 +mylon = -122.33207 + +schema = { + "city": { + "type": "string", + "description": "Name of the city" + }, + "lat": { + "type": "float", + "description": "Decimal Latitude of the city" + }, + "lon": { + "type": "float", + "description": "Decimal longitude of the city" + } +} + +payload = { + "model": "llama2", + "messages": [ + {"role": "system", "content": f"You are a helpful AI assistant. The user will enter a country name and the assistant will return the decimal latitude and decimal longitude of the capital of the country. Output in JSON using the schema defined here: {schema}."}, + {"role": "user", "content": "France"}, + {"role": "assistant", "content": "{\"city\": \"Paris\", \"lat\": 48.8566, \"lon\": 2.3522}"}, + {"role": "user", "content": country} + ], + "options": { + "temperature": 0.0 + }, + "format": "json", + "stream": False +} + +response = requests.post("http://localhost:11434/api/chat", json=payload) + +cityinfo = json.loads(response.json()["message"]["content"]) + +distance = haversine((mylat, mylon), (cityinfo['lat'], cityinfo['lon']), unit='mi') + +print(f"Bainbridge Island is about {int(round(distance, -1))} miles away from {cityinfo['city']}") \ No newline at end of file