Skip to content

Commit d06b48c

Browse files
authored
Merge pull request #150 from apkostka/fix/type-failures
Fix/type failures
2 parents d781b75 + 4ad4951 commit d06b48c

File tree

11 files changed

+103
-2715
lines changed

11 files changed

+103
-2715
lines changed

.github/pull_request_template.md

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

backend/scripts/README.md

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

backend/scripts/create_vector_store.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@
4444
subdir.split(os.sep) + [None] * 2
4545
) # Ensure we have at least two subdirs
4646

47-
attributes = {}
47+
# some type coercion to match OpenAI's expectations
48+
attributes: dict[str, bool | float | str] = {}
4849
# Openai doesn't allow querying by empty attributes, so we set them to "null"
4950
if subdirs[1]:
50-
attributes["city"] = subdirs[1]
51+
attributes["city"] = str(subdirs[1])
5152
else:
5253
attributes["city"] = "null"
5354
if subdirs[0]:
54-
attributes["state"] = subdirs[0]
55+
attributes["state"] = str(subdirs[0])
5556

5657
file_ids = []
5758
for filename in filenames:

backend/scripts/eval.csv

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

backend/scripts/eval.py

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

backend/scripts/eval_results_o4-mini_high.json

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

backend/scripts/generate_conversation/chat.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
# "python-dotenv",
77
# ]
88
# ///
9+
from openai.types.responses.response_input_param import ResponseInputParam
10+
from openai._client import OpenAI
911
import os
1012
import ast
1113
import argparse
1214
from pathlib import Path
1315
import pandas as pd
14-
from typing import Self
15-
from openai.types.responses.response_input_param import Message
16+
from openai.types.responses.easy_input_message_param import EasyInputMessageParam
1617

1718
from tenantfirstaid.chat import DEFAULT_INSTRUCTIONS, ChatManager
1819

@@ -36,16 +37,16 @@
3637

3738

3839
class ChatView:
39-
client: Self
40+
client: OpenAI
4041

4142
def __init__(self, starting_message, user_facts, city, state):
4243
self.chat_manager = ChatManager()
4344
self.client = self.chat_manager.get_client()
4445
self.city = city
4546
self.state = state
4647

47-
self.input_messages: list[Message] = [
48-
Message(role="user", content=starting_message)
48+
self.input_messages: ResponseInputParam = [
49+
EasyInputMessageParam(role="user", content=starting_message)
4950
]
5051
self.starting_message = starting_message # Store the starting message
5152

@@ -62,11 +63,11 @@ def _reverse_message_roles(self, messages):
6263
for message in messages:
6364
if message["role"] == "user":
6465
reversed_messages.append(
65-
Message(role="assistant", content=message["content"])
66+
EasyInputMessageParam(role="system", content=message["content"])
6667
)
6768
elif message["role"] == "assistant":
6869
reversed_messages.append(
69-
Message(role="user", content=message["content"])
70+
EasyInputMessageParam(role="user", content=message["content"])
7071
)
7172
else:
7273
reversed_messages.append(message)
@@ -85,7 +86,9 @@ def bot_response(self):
8586
stream=False,
8687
)
8788
self.input_messages.append(
88-
Message(role="assistant", content=response.output_text)
89+
EasyInputMessageParam(
90+
role="assistant", content=response.output_text
91+
)
8992
)
9093
self.input_messages = self._reverse_message_roles(self.input_messages)
9194
return response.output_text
@@ -94,7 +97,9 @@ def bot_response(self):
9497
tries += 1
9598
# If all attempts fail, return a failure message
9699
failure_message = "I'm sorry, I am unable to generate a response at this time. Please try again later."
97-
self.input_messages.append(Message(role="assistant", content=failure_message))
100+
self.input_messages.append(
101+
EasyInputMessageParam(role="assistant", content=failure_message)
102+
)
98103
return failure_message
99104

100105
def user_response(self):
@@ -110,15 +115,17 @@ def user_response(self):
110115
stream=False,
111116
)
112117
self.input_messages.append(
113-
Message(role="user", content=response.output_text)
118+
EasyInputMessageParam(role="user", content=response.output_text)
114119
)
115120
return response.output_text
116121
except Exception as e:
117122
print(f"Error generating user response: {e}")
118123
tries += 1
119124
# If all attempts fail, return a failure message
120125
failure_message = "I'm sorry, I am unable to generate a user response at this time. Please try again later."
121-
self.input_messages.append(Message(role="user", content=failure_message))
126+
self.input_messages.append(
127+
EasyInputMessageParam(role="user", content=failure_message)
128+
)
122129
return failure_message
123130

124131
def generate_conversation(self, num_turns=5):
@@ -134,8 +141,8 @@ def generate_conversation(self, num_turns=5):
134141
user_response = self.user_response()
135142
chat_history += f"USER: {user_response}\n"
136143
print(f"USER: {user_response}")
137-
self.input_messages = self.input_messages[
138-
0
144+
self.input_messages = [
145+
self.input_messages[0]
139146
] # Reset input messages to the first message only
140147
return chat_history
141148

backend/scripts/simple_eval.py

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

0 commit comments

Comments
 (0)