Skip to content

Commit 8bec36e

Browse files
lint issue fix
1 parent 93e0530 commit 8bec36e

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

src/backend/app_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_ai_project_client(self):
165165
except Exception as exc:
166166
logging.error("Failed to create AIProjectClient: %s", exc)
167167
raise
168-
168+
169169
def get_user_local_browser_language(self) -> str:
170170
"""Get the user's local browser language from environment variables.
171171

src/backend/app_kernel.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@
8484
app.add_middleware(HealthCheckMiddleware, password="", checks={})
8585
logging.info("Added health check middleware")
8686

87+
8788
def format_dates_in_messages(messages, target_locale="en-US"):
8889
"""
8990
Format dates in agent messages according to the specified locale.
90-
91+
9192
Args:
9293
messages: List of message objects or string content
9394
target_locale: Target locale for date formatting (default: en-US)
94-
95+
9596
Returns:
9697
Formatted messages with dates converted to target locale format
9798
"""
@@ -100,19 +101,19 @@ def format_dates_in_messages(messages, target_locale="en-US"):
100101
"en-IN": "%d %b %Y", # 30 Jul 2025
101102
"en-US": "%b %d, %Y", # Jul 30, 2025
102103
}
103-
104+
104105
output_format = locale_date_formats.get(target_locale, "%d %b %Y")
105106
# Match both "Jul 30, 2025, 12:00:00 AM" and "30 Jul 2025"
106107
date_pattern = r'(\d{1,2} [A-Za-z]{3,9} \d{4}|[A-Za-z]{3,9} \d{1,2}, \d{4}(, \d{1,2}:\d{2}:\d{2} ?[APap][Mm])?)'
107-
108+
108109
def convert_date(match):
109110
date_str = match.group(0)
110111
try:
111112
dt = parser.parse(date_str)
112113
return dt.strftime(output_format)
113114
except Exception:
114115
return date_str # Leave it unchanged if parsing fails
115-
116+
116117
# Process messages
117118
if isinstance(messages, list):
118119
formatted_messages = []
@@ -131,6 +132,7 @@ def convert_date(match):
131132
else:
132133
return messages
133134

135+
134136
@app.post("/api/user_browser_language")
135137
async def user_browser_language_endpoint(
136138
user_language: UserLanguage,
@@ -165,6 +167,7 @@ async def user_browser_language_endpoint(
165167

166168
return {"status": "Language received successfully"}
167169

170+
168171
@app.post("/api/input_task")
169172
async def input_task_endpoint(input_task: InputTask, request: Request):
170173
"""
@@ -267,7 +270,7 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
267270
match = re.search(r"Rate limit is exceeded\. Try again in (\d+) seconds?\.", error_msg)
268271
if match:
269272
error_msg = f"Rate limit is exceeded. Try again in {match.group(1)} seconds."
270-
273+
271274
track_event_if_configured(
272275
"InputTaskError",
273276
{
@@ -729,10 +732,10 @@ async def get_plans(
729732

730733
plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps)
731734
plan_with_steps.update_step_counts()
732-
735+
733736
# Format dates in messages according to locale
734737
formatted_messages = format_dates_in_messages(messages, config.get_user_local_browser_language())
735-
738+
736739
return [plan_with_steps, formatted_messages]
737740

738741
all_plans = await memory_store.get_all_plans()

src/backend/kernel_tools/hr_tools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,25 @@
55
from models.messages_kernel import AgentType
66
import json
77
from typing import get_type_hints
8-
from utils_date import format_date_for_user
98
from app_config import config
109

1110

1211
class HrTools:
1312
# Define HR tools (functions)
14-
selecetd_language= config.get_user_local_browser_language()
13+
selecetd_language = config.get_user_local_browser_language()
1514
formatting_instructions = "Instructions: returning the output of this function call verbatim to the user in markdown. Then write AGENT SUMMARY: and then include a summary of what you did. Convert all date strings in the following text to short date format with 3-letter month (MMM) in the {selecetd_language} locale (e.g., en-US, en-IN), remove time, and replace original dates with the formatted ones"
1615
agent_name = AgentType.HR.value
1716

1817
@staticmethod
1918
@kernel_function(description="Schedule an orientation session for a new employee.")
2019
async def schedule_orientation_session(employee_name: str, date: str) -> str:
21-
#formatted_date = format_date_for_user(date)
2220

2321
return (
2422
f"##### Orientation Session Scheduled\n"
2523
f"**Employee Name:** {employee_name}\n"
2624
f"**Date:** {date}\n\n"
2725
f"Your orientation session has been successfully scheduled. "
2826
f"Please mark your calendar and be prepared for an informative session.\n"
29-
#f"AGENT SUMMARY: I scheduled the orientation session for {employee_name} on {formatted_date}, as part of her onboarding process.\n"
3027
f"{HrTools.formatting_instructions}"
3128
)
3229

src/backend/kernel_tools/product_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import json
1111
from typing import get_type_hints
1212
from utils_date import format_date_for_user
13-
from app_config import config
13+
from app_config import config
1414

1515

1616
class ProductTools:
@@ -19,6 +19,7 @@ class ProductTools:
1919
agent_name = AgentType.PRODUCT.value
2020
selecetd_language = config.get_user_local_browser_language()
2121
@staticmethod
22+
2223
@kernel_function(
2324
description="Add an extras pack/new product to the mobile plan for the customer. For example, adding a roaming plan to their service. Convert all date strings in the following text to short date format with 3-letter month (MMM) in the {selecetd_language} locale (e.g., en-US, en-IN), remove time, and replace original dates with the formatted ones"
2425
)

src/backend/test_utils_date_fixed.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from datetime import datetime
77
from utils_date import format_date_for_user
88

9+
910
def test_date_formatting():
1011
"""Test the date formatting function with various inputs"""
11-
12+
1213
# Set up different language environments
1314
test_cases = [
1415
('en-US', '2025-07-29', 'US English'),
@@ -17,36 +18,37 @@ def test_date_formatting():
1718
('fr-FR', '2025-07-29', 'French'),
1819
('de-DE', '2025-07-29', 'German'),
1920
]
20-
21+
2122
print("Testing date formatting with different locales:")
2223
print("=" * 50)
23-
24+
2425
for locale, date_str, description in test_cases:
2526
os.environ['USER_LOCAL_BROWSER_LANGUAGE'] = locale
2627
try:
2728
result = format_date_for_user(date_str)
2829
print(f"{description} ({locale}): {result}")
2930
except Exception as e:
3031
print(f"{description} ({locale}): ERROR - {e}")
31-
32+
3233
print("\n" + "=" * 50)
3334
print("Testing with datetime object:")
34-
35+
3536
# Test with datetime object
3637
os.environ['USER_LOCAL_BROWSER_LANGUAGE'] = 'en-US'
3738
dt = datetime(2025, 7, 29, 14, 30, 0)
3839
result = format_date_for_user(dt)
3940
print(f"Datetime object: {result}")
40-
41+
4142
print("\nTesting error handling:")
4243
print("=" * 30)
43-
44+
4445
# Test error handling
4546
try:
4647
result = format_date_for_user('invalid-date-string')
4748
print(f"Invalid date: {result}")
4849
except Exception as e:
4950
print(f"Invalid date: ERROR - {e}")
5051

52+
5153
if __name__ == "__main__":
5254
test_date_formatting()

src/backend/utils_date.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from typing import Optional
55

6+
67
def format_date_for_user(date_str: str, user_locale: Optional[str] = None) -> str:
78
"""
89
Format date based on user's desktop locale preference.

0 commit comments

Comments
 (0)