File size: 1,900 Bytes
5dbfb3f
fea02f6
5dbfb3f
 
 
 
 
 
fea02f6
5dbfb3f
 
 
 
fea02f6
5dbfb3f
 
 
 
fea02f6
 
 
 
 
5dbfb3f
 
 
 
 
 
fea02f6
 
5dbfb3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
import re
from typing import Union, Optional


from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import BaseModel

from .. import skills
from enum import Enum

class Settings(BaseSettings):
    WEATHER_API_KEY: str
    TOMTOM_API_KEY: str
    REPLICATE_API_KEY: Optional[str]

    model_config = SettingsConfigDict(env_file=".env")


class Speed(Enum):
        SLOW = "slow"
        FAST = "fast"


class VehicleStatus(BaseModel):
    location: str
    location_coordinates: tuple[float, float] # (latitude, longitude)
    date: str
    time: str
    destination: str
    speed: Speed = Speed.SLOW
    


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"
)