Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions functions_to_format/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get_number_by_receiver_name,
send_money_to_someone_via_card,
pay_for_home_utility,
get_home_utility_suppliers,
)
from .contact import build_contact_widget, get_contact
from .news import build_news_widget, get_news
Expand Down Expand Up @@ -54,4 +55,5 @@
"get_home_balances": get_home_balances,
"build_contacts_list": build_contacts_list,
"pay_for_home_utility": pay_for_home_utility,
"get_home_utility_suppliers": get_home_utility_suppliers,
}
39 changes: 2 additions & 37 deletions functions_to_format/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ def chatbot_answer(context: Context) -> BuildOutput:
return output


def unauthorized_response(context):
# Janis Rubins: logic unchanged, just returns text_widget schema and llm_output as data
from models.context import Context

def unauthorized_response(context: Context):
# Extract values from context
llm_output = context.llm_output
backend_output = context.backend_output
Expand Down Expand Up @@ -151,9 +148,7 @@ def build_contacts_list_widget(contacts: list[Contact]) -> Dict[str, Any]:
return container


def build_contacts_list(context) -> BuildOutput:
from models.context import Context

def build_contacts_list(context: Context) -> BuildOutput:
# Extract values from context
llm_output = context.llm_output
backend_output = context.backend_output
Expand Down Expand Up @@ -217,33 +212,3 @@ def build_contacts_list(context) -> BuildOutput:
)
save_builder_output(context, output)
return output


########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
########################################################
######### LEGACY UNUSED CODE #########
1 change: 1 addition & 0 deletions functions_to_format/functions/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def add_ui_to_widget(
widget_args = widget_input.args
widget_input.widget.build_ui(sdui_function, **widget_args)
except Exception as e:
logger.error("Error building widget", error=e)
logger.exception("Error building widget", error=e)
continue
widgets: List[Widget] = []
Expand Down
5 changes: 4 additions & 1 deletion functions_to_format/functions/general/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ async def upload_usages_async() -> None:
config.mongo.database_name # pyright: ignore[reportOptionalMemberAccess]
).get_collection(config.mongo.collection_name) # pyright: ignore[reportOptionalMemberAccess]
tasks = []
for file in os.listdir("logs/usage"):
files = os.listdir("logs/usage")
for file in files:
tasks.append(load_usages_async(collection, f"logs/usage/{file}"))

await asyncio.gather(*tasks)
for file in files:
os.remove(f"logs/usage/{file}")
except Exception as e:
logger.error(f"Error uploading usages: {e}")
finally:
Expand Down
68 changes: 42 additions & 26 deletions functions_to_format/functions/payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from functions_to_format.functions.functions import chatbot_answer

from .general import (
add_ui_to_widget,
Widget,
Expand Down Expand Up @@ -304,36 +306,46 @@ def pay_for_home_utility(context: Context) -> BuildOutput:
api_key = context.api_key
logger = context.logger_context.logger

backend_output = PaymentManagerPaymentResponse.model_validate(backend_output)
inp = {}

logger.info("pay_for_home_utility")
try:
backend_output = PaymentManagerPaymentResponse.model_validate(backend_output)
payment_status_widget = Widget(
order=2,
type="payment_status_widget",
name="payment_status_widget",
layout="vertical",
fields=["payment_status"],
values=[backend_output.model_dump()],
)
inp[build_pay_for_home_utility_ui] = WidgetInput(
widget=payment_status_widget,
args={"payment_response": backend_output},
)

text_widget = TextWidget(
order=1,
values=[{"text": llm_output}],
)
payment_status_widget = Widget(
order=2,
type="payment_status_widget",
name="payment_status_widget",
layout="vertical",
fields=["payment_status"],
values=[backend_output.model_dump()],
)
logger.info("pay_for_home_utility")

text_widget = TextWidget(
order=1,
values=[{"text": llm_output}],
)
inp[build_text_widget] = WidgetInput(
widget=text_widget,
args={
"text": llm_output,
},
)

except Exception as e:
inp[build_text_widget] = WidgetInput(
widget=text_widget,
args={
"text": llm_output,
},
)

widgets = add_ui_to_widget(
{
build_text_widget: WidgetInput(
widget=text_widget,
args={
"text": llm_output,
},
),
build_pay_for_home_utility_ui: WidgetInput(
widget=payment_status_widget,
args={"payment_response": backend_output},
),
},
inp,
version,
)
output = BuildOutput(
Expand Down Expand Up @@ -1103,6 +1115,10 @@ def get_fields_of_supplier_ui(fields: List[Field]):
return div


def get_home_utility_suppliers(context) -> BuildOutput:
return chatbot_answer(context)


if __name__ == "__main__":
# check get_contacts with action first
# output = get_receiver_id_by_receiver_phone_number(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ui-server"
version = "1.001"
version = "1.01"
description = "UI Server to generate UI json representations using Yandex Divkit"
readme = "README.md"
requires-python = ">=3.13"
Expand Down
6 changes: 5 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
)

try:
version = open("version.txt", "r").read()
import tomllib

with open("pyproject.toml", "rb") as f:
pyproject_data = tomllib.load(f)
version = pyproject_data.get("project", {}).get("version", "0")
except Exception as e:
version = "0"
finally:
Expand Down
30 changes: 0 additions & 30 deletions src/ui_router.py

This file was deleted.

Loading