mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Create API endpoint to clear user's chat history
This commit is contained in:
parent
5d9d50157e
commit
3096544cf2
2 changed files with 25 additions and 0 deletions
|
@ -232,6 +232,10 @@ class ConversationAdapters:
|
||||||
return await conversation.afirst()
|
return await conversation.afirst()
|
||||||
return await Conversation.objects.acreate(user=user)
|
return await Conversation.objects.acreate(user=user)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def adelete_conversation_by_user(user: KhojUser):
|
||||||
|
return await Conversation.objects.filter(user=user).adelete()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def has_any_conversation_config(user: KhojUser):
|
def has_any_conversation_config(user: KhojUser):
|
||||||
return ChatModelOptions.objects.filter(user=user).exists()
|
return ChatModelOptions.objects.filter(user=user).exists()
|
||||||
|
|
|
@ -534,6 +534,27 @@ def chat_history(
|
||||||
return {"status": "ok", "response": meta_log.get("chat", [])}
|
return {"status": "ok", "response": meta_log.get("chat", [])}
|
||||||
|
|
||||||
|
|
||||||
|
@api.delete("/chat/history")
|
||||||
|
@requires(["authenticated"])
|
||||||
|
async def clear_chat_history(
|
||||||
|
request: Request,
|
||||||
|
common: CommonQueryParams,
|
||||||
|
):
|
||||||
|
user = request.user.object
|
||||||
|
|
||||||
|
# Clear Conversation History
|
||||||
|
await ConversationAdapters.adelete_conversation_by_user(user)
|
||||||
|
|
||||||
|
update_telemetry_state(
|
||||||
|
request=request,
|
||||||
|
telemetry_type="api",
|
||||||
|
api="clear_chat_history",
|
||||||
|
**common.__dict__,
|
||||||
|
)
|
||||||
|
|
||||||
|
return {"status": "ok", "message": "Conversation history cleared"}
|
||||||
|
|
||||||
|
|
||||||
@api.get("/chat/options", response_class=Response)
|
@api.get("/chat/options", response_class=Response)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def chat_options(
|
async def chat_options(
|
||||||
|
|
Loading…
Reference in a new issue