Skip to content

Commit f0f8226

Browse files
committed
refactor: remove references to feedback and training, move session logic into session class, remove shared module
1 parent 0bc977d commit f0f8226

File tree

9 files changed

+57
-113
lines changed

9 files changed

+57
-113
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ jobs:
8383
cat > /etc/tenantfirstaid/env <<EOF
8484
ENV=prod
8585
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
86-
FEEDBACK_PASSWORD=${{ secrets.FEEDBACK_PASSWORD }}
8786
DB_HOST=${{secrets.DB_HOST}}
8887
DB_PASSWORD=${{secrets.DB_PASSWORD}}
8988
DB_PORT=${{secrets.DB_PORT}}

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,4 @@ We currently have regular project meetups: https://www.meetup.com/codepdx/ . Als
7979
On DO, we:
8080
1. added our ssh public keys
8181
2. install nginx
82-
3. Kent got the tls cert (just ask chatgpt?)
83-
84-
## Additional features
85-
86-
go to the route `/feedback` for extra features. You will need to provide the password defined in your `.env` file.
82+
3. Kent got the tls cert (just ask chatgpt?)

backend/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
FEEDBACK_PASSWORD=password
21
OPENAI_API_KEY=openai_api_key
32
# If you want to use Github Models instead, omit OPENAI_API_KEY and use
43
# GITHUB_API_KEY and MODEL_ENDPOINT

backend/PERSISTENT_DATA_README.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

backend/scripts/simple_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from openai import OpenAI
66

7-
from tenantfirstaid.shared import DEFAULT_INSTRUCTIONS
7+
from tenantfirstaid.chat import DEFAULT_INSTRUCTIONS
88

99
API_KEY = os.getenv("OPENAI_API_KEY", os.getenv("GITHUB_API_KEY"))
1010
BASE_URL = os.getenv("MODEL_ENDPOINT", "https://api.openai.com/v1")

backend/tenantfirstaid/chat.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
import uuid
2-
31
from openai import OpenAI
4-
from flask import request, stream_with_context, Response, session, after_this_request
2+
from flask import request, stream_with_context, Response
53
from flask.views import View
64
import os
75

8-
from .shared import DEFAULT_INSTRUCTIONS, DATA_DIR
9-
10-
DATA_FILE = DATA_DIR / "chatlog.jsonl"
11-
126
API_KEY = os.getenv("OPENAI_API_KEY", os.getenv("GITHUB_API_KEY"))
137
BASE_URL = os.getenv("MODEL_ENDPOINT", "https://api.openai.com/v1")
148
MODEL = os.getenv("MODEL_NAME", "o3")
159
MODEL_REASONING_EFFORT = os.getenv("MODEL_REASONING_EFFORT", "medium")
1610

11+
DEFAULT_INSTRUCTIONS = """Pretend you're a legal expert who giving advice about eviction notices in Oregon.
12+
Please give shorter answers.
13+
Please only ask one question at a time so that the user isn't confused.
14+
If the user is being evicted for non-payment of rent and they are too poor to pay the rent and you have confirmed in various ways that the notice is valid and there is a valid court hearing date, then tell them to call Oregon Law Center at 5131234567.
15+
Focus on finding technicalities that would legally prevent someone getting evicted, such as deficiencies in notice.
16+
Assume the user is on a month-to-month lease unless they specify otherwise.
17+
18+
Use only the information from the file search results to answer the question.
19+
City codes will override the state codes if there is a conflict.
20+
21+
Make sure to include a citation to the relevant law in your answer, with a link to the actual web page the law is on using HTML.
22+
Use the following websites for citation links:
23+
https://oregon.public.law/statutes
24+
https://www.portland.gov/code/30/01
25+
https://eugene.municipal.codes/EC/8.425
26+
Include the links inline in your answer, with the attribute target="_blank" so that they open in a new tab, likethis:
27+
<a href="https://oregon.public.law/statutes/ORS_90.427" target="_blank">ORS 90.427</a>.
28+
"""
29+
30+
31+
class ChatManager:
32+
def __init__(self):
33+
self.client = OpenAI(
34+
api_key=API_KEY,
35+
base_url=BASE_URL,
36+
)
37+
38+
def get_client(self):
39+
return self.client
1740

18-
class ChatView(View):
19-
DATA_FILE = DATA_DIR / "chatlog.jsonl"
2041

42+
class ChatView(View):
2143
client = OpenAI(
2244
api_key=API_KEY,
2345
base_url=BASE_URL,
@@ -26,23 +48,12 @@ class ChatView(View):
2648
def __init__(self, tenant_session):
2749
self.tenant_session = tenant_session
2850

29-
# Prompt iteration idea
30-
# If the user starts off by saying something unclear, start off by asking me \"What are you here for?\"
31-
3251
def dispatch_request(self):
3352
data = request.json
3453
user_msg = data["message"]
3554

3655
# Get or create session ID using Flask sessions
37-
session_id = session.get("session_id")
38-
if not session_id:
39-
session_id = str(uuid.uuid4())
40-
session["session_id"] = session_id
41-
42-
@after_this_request
43-
def save_session(response):
44-
session.modified = True
45-
return response
56+
session_id = self.tenant_session.get_flask_session_id()
4657

4758
current_session = self.tenant_session.get()
4859

backend/tenantfirstaid/session.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
import uuid
3-
from flask import Response, request, session
3+
from flask import Response, after_this_request, request, session
44
from flask.views import View
55
from valkey import Valkey
66
import simplejson as json
77

88

9+
# The class to manage tenant sessions using Valkey and Flask sessions
910
class TenantSession:
1011
def __init__(self):
1112
print(
@@ -28,6 +29,20 @@ def __init__(self):
2829
except Exception as e:
2930
print(e)
3031

32+
# Retrieves the session ID from Flask session or creates a new one
33+
def get_flask_session_id(self):
34+
session_id = session.get("session_id")
35+
if not session_id:
36+
session_id = str(uuid.uuid4())
37+
session["session_id"] = session_id
38+
39+
@after_this_request
40+
def save_session(response):
41+
session.modified = True
42+
return response
43+
44+
return session_id
45+
3146
def get(self):
3247
session_id = session.get("session_id")
3348
if not session_id:
@@ -50,22 +65,21 @@ def getNewSessionData(self):
5065
}
5166

5267

68+
# The Flask view to initialize a session
5369
class InitSessionView(View):
54-
def __init__(self, session: TenantSession):
55-
self.session = session
70+
def __init__(self, tenant_session: TenantSession):
71+
self.tenant_session = tenant_session
5672

5773
def dispatch_request(self):
5874
data = request.json
59-
session_id = session.get("session_id")
60-
if not session_id:
61-
session_id = str(uuid.uuid4())
62-
session["session_id"] = session_id
75+
session_id = self.tenant_session.get_flask_session_id()
76+
6377
city = data["city"] or "null"
6478
state = data["state"]
6579

6680
# Initialize the session with city and state
6781
initial_data = {"city": city, "state": state, "messages": []}
68-
self.session.set(session_id, initial_data)
82+
self.tenant_session.set(session_id, initial_data)
6983

7084
return Response(
7185
status=200,

backend/tenantfirstaid/shared.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

frontend/src/pages/Chat/components/CitySelectField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface Props {
3030

3131
export default function CitySelectField({ setMessages }: Props) {
3232
const [city, setCity] = useState<string | null>(null);
33-
let [invalidCity, setInvalidCity] = useState<boolean>(false);
33+
const [invalidCity, setInvalidCity] = useState<boolean>(false);
3434
const { initChat } = useMessages();
3535

3636
const handleCityChange = async (key: string | null) => {

0 commit comments

Comments
 (0)