mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Support getting latest N chat messages via chat history API
Get latest N if N > 0, else return all messages except latest N from the conversation
This commit is contained in:
parent
e5ff85f6fb
commit
9e5585776c
1 changed files with 8 additions and 0 deletions
|
@ -76,6 +76,7 @@ def chat_history(
|
|||
request: Request,
|
||||
common: CommonQueryParams,
|
||||
conversation_id: Optional[int] = None,
|
||||
n: Optional[int] = None,
|
||||
):
|
||||
user = request.user.object
|
||||
validate_conversation_config()
|
||||
|
@ -109,6 +110,13 @@ def chat_history(
|
|||
}
|
||||
)
|
||||
|
||||
# Get latest N messages if N > 0
|
||||
if n > 0:
|
||||
meta_log["chat"] = meta_log["chat"][-n:]
|
||||
# Else return all messages except latest N
|
||||
else:
|
||||
meta_log["chat"] = meta_log["chat"][:n]
|
||||
|
||||
update_telemetry_state(
|
||||
request=request,
|
||||
telemetry_type="api",
|
||||
|
|
Loading…
Add table
Reference in a new issue