Skip to content

Commit f9444c8

Browse files
committed
refactor: Remove SimpleRAGChat and related codes, use AdvancedRAGChat for chat handling
1 parent a9388d6 commit f9444c8

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/fastapi_app/api_routes.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from fastapi_app.postgres_models import Package
88
from fastapi_app.postgres_searcher import PostgresSearcher
99
from fastapi_app.rag_advanced import AdvancedRAGChat
10-
from fastapi_app.rag_simple import SimpleRAGChat
1110
from fastapi_app.utils import update_urls_with_utm
1211

1312
router = fastapi.APIRouter()
@@ -24,26 +23,19 @@ async def package_handler(url: str):
2423

2524
@router.post("/chat")
2625
async def chat_handler(chat_request: ChatRequest):
26+
"""API to chat with the RAG model."""
2727
messages = [message.model_dump() for message in chat_request.messages]
28-
overrides = chat_request.context.get("overrides", {})
2928

3029
searcher = PostgresSearcher(global_storage.engine)
31-
if overrides.get("use_advanced_flow"):
32-
ragchat = AdvancedRAGChat(
33-
searcher=searcher,
34-
openai_chat_client=global_storage.openai_chat_client,
35-
chat_model=global_storage.openai_chat_model,
36-
chat_deployment=global_storage.openai_chat_deployment,
37-
)
38-
else:
39-
ragchat = SimpleRAGChat(
40-
searcher=searcher,
41-
openai_chat_client=global_storage.openai_chat_client,
42-
chat_model=global_storage.openai_chat_model,
43-
chat_deployment=global_storage.openai_chat_deployment,
44-
)
45-
46-
chat_resp = await ragchat.run(messages, overrides=overrides)
30+
31+
ragchat = AdvancedRAGChat(
32+
searcher=searcher,
33+
openai_chat_client=global_storage.openai_chat_client,
34+
chat_model=global_storage.openai_chat_model,
35+
chat_deployment=global_storage.openai_chat_deployment,
36+
)
37+
38+
chat_resp = await ragchat.run(messages)
4739
chat_resp_content = chat_resp["choices"][0]["message"]["content"]
4840

4941
# Update URLs with UTM parameters

src/fastapi_app/rag_advanced.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def google_search(self, messages):
8181
return sources_content, thought_steps
8282

8383
async def run(
84-
self, messages: list[dict], overrides: dict[str, Any] = {}
84+
self, messages: list[dict]
8585
) -> dict[str, Any] | AsyncGenerator[dict[str, Any], None]:
8686
# Normalize the message format
8787
for message in messages:
@@ -144,7 +144,7 @@ async def run(
144144
chat_completion_response = await self.openai_chat_completion(
145145
model=self.chat_deployment if self.chat_deployment else self.chat_model,
146146
messages=messages,
147-
temperature=overrides.get("temperature", 0.3),
147+
temperature=0,
148148
max_tokens=response_token_limit,
149149
n=1,
150150
stream=False,

0 commit comments

Comments
 (0)