mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Create API endpoint to clear user's chat history
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user