mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 13:26:13 +00:00
Time chat actor responses & chat api request start for perf analysis
This commit is contained in:
@@ -242,6 +242,7 @@ async def chat(
|
||||
) -> Response:
|
||||
user: KhojUser = request.user.object
|
||||
q = unquote(q)
|
||||
logger.info("Chat request by {user.username}: {q}")
|
||||
|
||||
await is_ready_to_chat(user)
|
||||
conversation_commands = [get_conversation_command(query=q, any_references=True)]
|
||||
|
||||
@@ -168,6 +168,7 @@ async def aget_relevant_information_sources(query: str, conversation_history: di
|
||||
chat_history=chat_history,
|
||||
)
|
||||
|
||||
with timer("Chat actor: Infer information sources to refer", logger):
|
||||
response = await send_message_to_model_wrapper(relevant_tools_prompt, response_type="json_object")
|
||||
|
||||
try:
|
||||
@@ -212,6 +213,7 @@ async def aget_relevant_output_modes(query: str, conversation_history: dict):
|
||||
chat_history=chat_history,
|
||||
)
|
||||
|
||||
with timer("Chat actor: Infer output mode for chat response", logger):
|
||||
response = await send_message_to_model_wrapper(relevant_mode_prompt)
|
||||
|
||||
try:
|
||||
@@ -245,6 +247,7 @@ async def infer_webpage_urls(q: str, conversation_history: dict, location_data:
|
||||
location=location,
|
||||
)
|
||||
|
||||
with timer("Chat actor: Infer webpage urls to read", logger):
|
||||
response = await send_message_to_model_wrapper(online_queries_prompt, response_type="json_object")
|
||||
|
||||
# Validate that the response is a non-empty, JSON-serializable list of URLs
|
||||
@@ -274,6 +277,7 @@ async def generate_online_subqueries(q: str, conversation_history: dict, locatio
|
||||
location=location,
|
||||
)
|
||||
|
||||
with timer("Chat actor: Generate online search subqueries", logger):
|
||||
response = await send_message_to_model_wrapper(online_queries_prompt, response_type="json_object")
|
||||
|
||||
# Validate that the response is a non-empty, JSON-serializable list
|
||||
@@ -303,6 +307,7 @@ async def extract_relevant_info(q: str, corpus: str) -> Union[str, None]:
|
||||
corpus=corpus.strip(),
|
||||
)
|
||||
|
||||
with timer("Chat actor: Extract relevant information from data", logger):
|
||||
response = await send_message_to_model_wrapper(
|
||||
extract_relevant_information, prompts.system_prompt_extract_relevant_information
|
||||
)
|
||||
@@ -346,6 +351,7 @@ async def generate_better_image_prompt(
|
||||
online_results=simplified_online_results,
|
||||
)
|
||||
|
||||
with timer("Chat actor: Generate contextual image prompt", logger):
|
||||
response = await send_message_to_model_wrapper(image_prompt)
|
||||
|
||||
return response.strip()
|
||||
|
||||
Reference in New Issue
Block a user