Skip to content

Commit b22b2c1

Browse files
committed
fix: review changes from @yangm2
1 parent 1b2e6b3 commit b22b2c1

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

backend/scripts/generate_conversation/chat.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# dependencies = [
44
# "openai",
55
# "pandas",
6+
# "python-dotenv",
67
# ]
78
# ///
89
import os
@@ -11,15 +12,16 @@
1112
from pathlib import Path
1213
import pandas as pd
1314
from typing import Self
14-
1515
from openai.types.responses.response_input_param import Message
1616

17-
if Path("../../.env").exists():
18-
from dotenv import load_dotenv
17+
from tenantfirstaid.chat import DEFAULT_INSTRUCTIONS, ChatManager
1918

20-
load_dotenv(override=True)
19+
dot_env_path = Path(__file__).parent.parent.parent / ".env"
20+
print(f"Loading environment variables from {dot_env_path}")
21+
if dot_env_path.exists():
22+
from dotenv import load_dotenv
2123

22-
from tenantfirstaid.chat import DEFAULT_INSTRUCTIONS, ChatManager
24+
load_dotenv(dotenv_path=dot_env_path, override=True)
2325

2426
BOT_INSTRUCTIONS = DEFAULT_INSTRUCTIONS
2527

backend/tenantfirstaid/chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from openai.types.shared import Reasoning
33
from openai.types.responses import (
44
FileSearchToolParam,
5+
Response as ResponseEvent,
56
ResponseStreamEvent,
67
)
78
from openai.types.responses.response_input_param import Message
@@ -126,7 +127,7 @@ def prepare_openai_tools(self, city: str, state: str):
126127

127128
def generate_chat_response(
128129
self, messages: list[Message], city: str, state: str, stream=False
129-
) -> ResponseStreamEvent:
130+
) -> ResponseStreamEvent | ResponseEvent:
130131
instructions = self.prepare_developer_instructions(city, state)
131132
tools = self.prepare_openai_tools(city, state)
132133

backend/tenantfirstaid/session.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ class TenantSessionData(TypedDict):
1515
messages: list[Message] # List of messages with role and content
1616

1717

18-
new_session_data = {
19-
"city": "null",
20-
"state": "or",
21-
"messages": [],
22-
}
18+
NEW_SESSION_DATA = TenantSessionData(city="null", state="or", messages=[])
2319

2420

2521
# The class to manage tenant sessions using Valkey and Flask sessions
@@ -73,7 +69,7 @@ def set(self, value: TenantSessionData):
7369
self.db_con.set(session_id, json.dumps(value))
7470

7571
def getNewSessionData(self) -> TenantSessionData:
76-
return TenantSessionData(new_session_data)
72+
return TenantSessionData(NEW_SESSION_DATA.copy())
7773

7874

7975
# The Flask view to initialize a session

0 commit comments

Comments
 (0)