Skip to content

Commit

Permalink
select assistant by name, check functions
Browse files Browse the repository at this point in the history
  • Loading branch information
corpulent committed Apr 8, 2024
1 parent ccd79ec commit 63674f9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
7 changes: 5 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def parse_args() -> argparse.Namespace:

init_answers = llmt.init_prompt()
selected_assistant = llmt.find_assistant(init_answers["assistant"])
llmt.init_assistant(selected_assistant["assistant_name"])
llmt.init_functions(selected_assistant["functions"])
llmt.init_assistant(selected_assistant["name"])

if functions := selected_assistant.get("functions"):
llmt.init_functions(selected_assistant["functions"])

llmt.init_chat(init_answers["chat_name"])

for response in llmt.run_forever():
Expand Down
83 changes: 38 additions & 45 deletions udfs/udfs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import enum
import json
import logging


Expand All @@ -15,54 +13,49 @@
logger = logging.getLogger()


def add_decimal_values(value1: int, value2: int) -> int:
"""Add two decimal values together.
def fetch_customers() -> list[dict[str, str | int]]:
"""Fetches a list of customers from a database.
Args:
value1 (int): The first value.
value2 (int): The second value.
Returns:
int: The sum of the two values.
"""
return value1 + value2


def add_hexadecimal_values(value1: str, value2: str) -> str:
"""Add two hexadecimal values together.
Args:
value1 (str): The first value.
value2 (str): The second value.
format (str): The format to return the data in. Defaults to "json".
Returns:
str: The sum of the two values.
list: A list of dictionaries, each containing customer information.
"""
decimal1 = int(value1, 16)
decimal2 = int(value2, 16)
return hex(decimal1 + decimal2)[2:]


class Unit(str, enum.Enum):
FAHRENHEIT = "fahrenheit"
CELSIUS = "celsius"


def get_current_weather(location: str, unit: Unit = Unit.FAHRENHEIT):
"""Get the current weather in a given location.
return [
{"name": "Alice", "age": 25, "city": "New York"},
{"name": "Bob", "age": 30, "city": "San Francisco"},
{"name": "Charlie", "age": 35, "city": "Chicago"},
{"name": "David", "age": 40, "city": "New York"},
{"name": "Eve", "age": 45, "city": "San Francisco"},
{"name": "Frank", "age": 50, "city": "New York"},
{"name": "Grace", "age": 55, "city": "Chicago"},
]


def fetch_products_sold_by_city(city: str) -> list[dict[str, str | float | int] | None]:
"""Fetches a list of products sold in a city.
Args:
location (str): The location to get the weather for
unit (Unit, optional): The unit to return the temperature in. Defaults to Unit.FAHRENHEIT.
city (str): The city to fetch products for.
Returns:
str: The current weather in the location
list: A list of dictionaries, each containing product information.
"""
if "tokyo" in location.lower():
return json.dumps({"location": "Tokyo", "temperature": "10", "unit": unit})
elif "san francisco" in location.lower():
return json.dumps({"location": "San Francisco", "temperature": "72", "unit": unit})
elif "paris" in location.lower():
return json.dumps({"location": "Paris", "temperature": "22", "unit": unit})
else:
return json.dumps({"location": location, "temperature": "unknown"})
if city == "New York":
return [
{"name": "Apple", "price": 1.0, "quantity": 10},
{"name": "Banana", "price": 2.0, "quantity": 20},
]

if city == "San Francisco":
return [
{"name": "Orange", "price": 3.0, "quantity": 30},
{"name": "Pear", "price": 4.0, "quantity": 40},
]

if city == "Chicago":
return [
{"name": "Grape", "price": 5.0, "quantity": 50},
{"name": "Kiwi", "price": 6.0, "quantity": 60},
]

0 comments on commit 63674f9

Please sign in to comment.