File size: 1,723 Bytes
cb47347 63ec258 cb47347 63ec258 cb47347 63ec258 60a0b19 247bc50 cc1b4c0 247bc50 187a965 |
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 60 61 62 63 |
import re
from typing import Union
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import BaseModel
import skills
class Settings(BaseSettings):
WEATHER_API_KEY: str
TOMTOM_API_KEY: str
model_config = SettingsConfigDict(env_file=".env")
class VehicleStatus(BaseModel):
location: str
location_coordinates: tuple[float, float] # (latitude, longitude)
date: str
time: str
destination: str
def execute_function_call(text: str, dry_run=False) -> str:
function_name_match = re.search(r"Call: (\w+)", text)
function_name = function_name_match.group(1) if function_name_match else None
arguments = eval(f"dict{text.split(function_name)[1].strip()}")
function = getattr(skills, function_name) if function_name else None
if dry_run:
print(f"{function_name}(**{arguments})")
return "Dry run successful"
if function:
out = function(**arguments)
try:
if function:
out = function(**arguments)
except Exception as e:
out = str(e)
return out
def extract_func_args(text: str) -> tuple[str, dict]:
function_name_match = re.search(r"Call: (\w+)", text)
function_name = function_name_match.group(1) if function_name_match else None
if not function_name:
raise ValueError("No function name found in text")
arguments = eval(f"dict{text.split(function_name)[1].strip()}")
return function_name, arguments
config = Settings() # type: ignore
vehicle = VehicleStatus(
location="Rue Alphonse Weicker, Luxembourg",
location_coordinates=(49.505, 6.28111),
date="2025-05-06",
time="08:00:00",
destination="Rue Alphonse Weicker, Luxembourg"
)
|