mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Add chat_model data for logging selected models to telemetry
This commit is contained in:
@@ -606,7 +606,7 @@ async def chat(
|
|||||||
return StreamingResponse(iter([formatted_help]), media_type="text/event-stream", status_code=200)
|
return StreamingResponse(iter([formatted_help]), media_type="text/event-stream", status_code=200)
|
||||||
|
|
||||||
# Get the (streamed) chat response from the LLM of choice.
|
# Get the (streamed) chat response from the LLM of choice.
|
||||||
llm_response = await agenerate_chat_response(
|
llm_response, chat_metadata = await agenerate_chat_response(
|
||||||
defiltered_query,
|
defiltered_query,
|
||||||
meta_log,
|
meta_log,
|
||||||
compiled_references,
|
compiled_references,
|
||||||
@@ -615,6 +615,19 @@ async def chat(
|
|||||||
user,
|
user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
chat_metadata.update({"conversation_command": conversation_command.value})
|
||||||
|
|
||||||
|
update_telemetry_state(
|
||||||
|
request=request,
|
||||||
|
telemetry_type="api",
|
||||||
|
api="chat",
|
||||||
|
client=client,
|
||||||
|
user_agent=user_agent,
|
||||||
|
referer=referer,
|
||||||
|
host=host,
|
||||||
|
metadata=chat_metadata,
|
||||||
|
)
|
||||||
|
|
||||||
if llm_response is None:
|
if llm_response is None:
|
||||||
return Response(content=llm_response, media_type="text/plain", status_code=500)
|
return Response(content=llm_response, media_type="text/plain", status_code=500)
|
||||||
|
|
||||||
@@ -634,16 +647,6 @@ async def chat(
|
|||||||
|
|
||||||
response_obj = {"response": actual_response, "context": compiled_references}
|
response_obj = {"response": actual_response, "context": compiled_references}
|
||||||
|
|
||||||
update_telemetry_state(
|
|
||||||
request=request,
|
|
||||||
telemetry_type="api",
|
|
||||||
api="chat",
|
|
||||||
client=client,
|
|
||||||
user_agent=user_agent,
|
|
||||||
referer=referer,
|
|
||||||
host=host,
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(content=json.dumps(response_obj), media_type="application/json", status_code=200)
|
return Response(content=json.dumps(response_obj), media_type="application/json", status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ def generate_chat_response(
|
|||||||
chat_response = None
|
chat_response = None
|
||||||
logger.debug(f"Conversation Type: {conversation_command.name}")
|
logger.debug(f"Conversation Type: {conversation_command.name}")
|
||||||
|
|
||||||
|
metadata = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
partial_completion = partial(
|
partial_completion = partial(
|
||||||
_save_to_conversation_log,
|
_save_to_conversation_log,
|
||||||
@@ -179,8 +181,10 @@ def generate_chat_response(
|
|||||||
tokenizer_name=conversation_config.tokenizer,
|
tokenizer_name=conversation_config.tokenizer,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
metadata.update({"chat_model": conversation_config.chat_model})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e, exc_info=True)
|
logger.error(e, exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
return chat_response
|
return chat_response, metadata
|
||||||
|
|||||||
Reference in New Issue
Block a user