Skip to content

Commit 596153f

Browse files
committed
Port frontend to be more Responses like, remove unused session state and follow-up Qs
1 parent cfa570d commit 596153f

16 files changed

Lines changed: 122 additions & 246 deletions

File tree

src/backend/fastapi_app/api_models.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
from pydantic import BaseModel, Field
66

77

8-
class AIChatRoles(str, Enum):
9-
USER = "user"
10-
ASSISTANT = "assistant"
11-
SYSTEM = "system"
12-
13-
14-
class Message(BaseModel):
15-
content: str
16-
role: AIChatRoles = AIChatRoles.USER
17-
18-
198
class RetrievalMode(str, Enum):
209
TEXT = "text"
2110
VECTORS = "vectors"
@@ -35,9 +24,8 @@ class ChatRequestContext(BaseModel):
3524

3625

3726
class ChatRequest(BaseModel):
38-
messages: list[ResponseInputItemParam]
27+
input: list[ResponseInputItemParam]
3928
context: ChatRequestContext
40-
sessionState: Optional[Any] = None
4129

4230

4331
class ItemPublic(BaseModel):
@@ -69,23 +57,21 @@ class ThoughtStep(BaseModel):
6957
class RAGContext(BaseModel):
7058
data_points: dict[int, ItemPublic]
7159
thoughts: list[ThoughtStep]
72-
followup_questions: Optional[list[str]] = None
7360

7461

7562
class ErrorResponse(BaseModel):
7663
error: str
7764

7865

7966
class RetrievalResponse(BaseModel):
80-
message: Message
67+
output_text: str
8168
context: RAGContext
82-
sessionState: Optional[Any] = None
8369

8470

8571
class RetrievalResponseDelta(BaseModel):
86-
delta: Optional[Message] = None
72+
type: str
73+
delta: Optional[str] = None
8774
context: Optional[RAGContext] = None
88-
sessionState: Optional[Any] = None
8975

9076

9177
class ChatParams(ChatRequestOverrides):

src/backend/fastapi_app/rag_advanced.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
from openai.types.responses import EasyInputMessageParam, ResponseInputItemParam, ResponseTextDeltaEvent
1717

1818
from fastapi_app.api_models import (
19-
AIChatRoles,
2019
BrandFilter,
2120
ChatRequestOverrides,
2221
Filter,
2322
ItemPublic,
24-
Message,
2523
PriceFilter,
2624
RAGContext,
2725
RetrievalResponse,
@@ -124,7 +122,7 @@ async def prepare_context(self) -> tuple[list[ItemPublic], list[ThoughtStep]]:
124122
thoughts = [
125123
ThoughtStep(
126124
title="Prompt to generate search arguments",
127-
description=[{"content": self.query_prompt_template}]
125+
description=[{"role": "system", "content": self.query_prompt_template}]
128126
+ ItemHelpers.input_to_new_input_list(run_results.input),
129127
props=self.model_for_thoughts,
130128
),
@@ -157,14 +155,14 @@ async def answer(
157155
)
158156

159157
return RetrievalResponse(
160-
message=Message(content=str(run_results.final_output), role=AIChatRoles.ASSISTANT),
158+
output_text=str(run_results.final_output),
161159
context=RAGContext(
162160
data_points={item.id: item for item in items},
163161
thoughts=earlier_thoughts
164162
+ [
165163
ThoughtStep(
166164
title="Prompt to generate answer",
167-
description=[{"content": self.answer_prompt_template}]
165+
description=[{"role": "system", "content": self.answer_prompt_template}]
168166
+ ItemHelpers.input_to_new_input_list(run_results.input),
169167
props=self.model_for_thoughts,
170168
),
@@ -184,13 +182,14 @@ async def answer_stream(
184182
)
185183

186184
yield RetrievalResponseDelta(
185+
type="response.context",
187186
context=RAGContext(
188187
data_points={item.id: item for item in items},
189188
thoughts=earlier_thoughts
190189
+ [
191190
ThoughtStep(
192191
title="Prompt to generate answer",
193-
description=[{"content": self.answer_prompt_template}]
192+
description=[{"role": "system", "content": self.answer_prompt_template}]
194193
+ ItemHelpers.input_to_new_input_list(run_results.input),
195194
props=self.model_for_thoughts,
196195
),
@@ -200,5 +199,5 @@ async def answer_stream(
200199

201200
async for event in run_results.stream_events():
202201
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
203-
yield RetrievalResponseDelta(delta=Message(content=str(event.data.delta), role=AIChatRoles.ASSISTANT))
202+
yield RetrievalResponseDelta(type="response.output_text.delta", delta=str(event.data.delta))
204203
return

src/backend/fastapi_app/rag_simple.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from openai.types.responses import ResponseInputItemParam, ResponseTextDeltaEvent
77

88
from fastapi_app.api_models import (
9-
AIChatRoles,
109
ChatRequestOverrides,
1110
ItemPublic,
12-
Message,
1311
RAGContext,
1412
RetrievalResponse,
1513
RetrievalResponseDelta,
@@ -90,14 +88,14 @@ async def answer(
9088
)
9189

9290
return RetrievalResponse(
93-
message=Message(content=str(run_results.final_output), role=AIChatRoles.ASSISTANT),
91+
output_text=str(run_results.final_output),
9492
context=RAGContext(
9593
data_points={item.id: item for item in items},
9694
thoughts=earlier_thoughts
9795
+ [
9896
ThoughtStep(
9997
title="Prompt to generate answer",
100-
description=[{"content": self.answer_prompt_template}]
98+
description=[{"role": "system", "content": self.answer_prompt_template}]
10199
+ ItemHelpers.input_to_new_input_list(run_results.input),
102100
props=self.model_for_thoughts,
103101
),
@@ -117,13 +115,14 @@ async def answer_stream(
117115
)
118116

119117
yield RetrievalResponseDelta(
118+
type="response.context",
120119
context=RAGContext(
121120
data_points={item.id: item for item in items},
122121
thoughts=earlier_thoughts
123122
+ [
124123
ThoughtStep(
125124
title="Prompt to generate answer",
126-
description=[{"content": self.answer_agent.instructions}]
125+
description=[{"role": "system", "content": self.answer_agent.instructions}]
127126
+ ItemHelpers.input_to_new_input_list(run_results.input),
128127
props=self.model_for_thoughts,
129128
),
@@ -133,5 +132,5 @@ async def answer_stream(
133132

134133
async for event in run_results.stream_events():
135134
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
136-
yield RetrievalResponseDelta(delta=Message(content=str(event.data.delta), role=AIChatRoles.ASSISTANT))
135+
yield RetrievalResponseDelta(type="response.output_text.delta", delta=str(event.data.delta))
137136
return

src/backend/fastapi_app/routes/api_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def chat_handler(
121121
rag_flow: Union[SimpleRAGChat, AdvancedRAGChat]
122122
if chat_request.context.overrides.use_advanced_flow:
123123
rag_flow = AdvancedRAGChat(
124-
messages=chat_request.messages,
124+
messages=chat_request.input,
125125
overrides=chat_request.context.overrides,
126126
searcher=searcher,
127127
openai_chat_client=openai_chat.client,
@@ -130,7 +130,7 @@ async def chat_handler(
130130
)
131131
else:
132132
rag_flow = SimpleRAGChat(
133-
messages=chat_request.messages,
133+
messages=chat_request.input,
134134
overrides=chat_request.context.overrides,
135135
searcher=searcher,
136136
openai_chat_client=openai_chat.client,
@@ -169,7 +169,7 @@ async def chat_stream_handler(
169169
rag_flow: Union[SimpleRAGChat, AdvancedRAGChat]
170170
if chat_request.context.overrides.use_advanced_flow:
171171
rag_flow = AdvancedRAGChat(
172-
messages=chat_request.messages,
172+
messages=chat_request.input,
173173
overrides=chat_request.context.overrides,
174174
searcher=searcher,
175175
openai_chat_client=openai_chat.client,
@@ -178,7 +178,7 @@ async def chat_stream_handler(
178178
)
179179
else:
180180
rag_flow = SimpleRAGChat(
181-
messages=chat_request.messages,
181+
messages=chat_request.input,
182182
overrides=chat_request.context.overrides,
183183
searcher=searcher,
184184
openai_chat_client=openai_chat.client,

0 commit comments

Comments
 (0)