mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Get conversation by title when requested via chat API
This commit is contained in:
parent
cac26dafe3
commit
c9e05dc184
2 changed files with 12 additions and 7 deletions
|
@ -436,16 +436,16 @@ class ConversationAdapters:
|
|||
|
||||
@staticmethod
|
||||
async def aget_conversation_by_user(
|
||||
user: KhojUser, client_application: ClientApplication = None, conversation_id: int = None, slug: str = None
|
||||
user: KhojUser, client_application: ClientApplication = None, conversation_id: int = None, title: str = None
|
||||
):
|
||||
if conversation_id:
|
||||
return await Conversation.objects.filter(user=user, client=client_application, id=conversation_id).afirst()
|
||||
elif slug:
|
||||
return await Conversation.objects.filter(user=user, client=client_application, slug=slug).afirst()
|
||||
elif title:
|
||||
return await Conversation.objects.filter(user=user, client=client_application, title=title).afirst()
|
||||
else:
|
||||
return await (
|
||||
Conversation.objects.filter(user=user, client=client_application).order_by("-updated_at").afirst()
|
||||
) or Conversation.objects.acreate(user=user, client=client_application, slug=slug)
|
||||
) or Conversation.objects.acreate(user=user, client=client_application)
|
||||
|
||||
@staticmethod
|
||||
async def adelete_conversation_by_user(
|
||||
|
|
|
@ -224,7 +224,7 @@ async def chat(
|
|||
n: Optional[int] = 5,
|
||||
d: Optional[float] = 0.18,
|
||||
stream: Optional[bool] = False,
|
||||
slug: Optional[str] = None,
|
||||
title: Optional[str] = None,
|
||||
conversation_id: Optional[int] = None,
|
||||
city: Optional[str] = None,
|
||||
region: Optional[str] = None,
|
||||
|
@ -251,9 +251,14 @@ async def chat(
|
|||
return StreamingResponse(iter([formatted_help]), media_type="text/event-stream", status_code=200)
|
||||
|
||||
conversation = await ConversationAdapters.aget_conversation_by_user(
|
||||
user, request.user.client_app, conversation_id, slug
|
||||
user, request.user.client_app, conversation_id, title
|
||||
)
|
||||
meta_log = conversation.conversation_log if conversation else {}
|
||||
if not conversation:
|
||||
return Response(
|
||||
content=f"No conversation found with requested id, title", media_type="text/plain", status_code=400
|
||||
)
|
||||
else:
|
||||
meta_log = conversation.conversation_log
|
||||
|
||||
if conversation_commands == [ConversationCommand.Default]:
|
||||
conversation_commands = await aget_relevant_information_sources(q, meta_log)
|
||||
|
|
Loading…
Reference in a new issue