Skip to content

Commit aed4313

Browse files
committed
Fix updating specific conversation by id from the chat API endpoint
- Use the conversation id of the retrieved conversation rather than the potentially unset conversation id passed via API - await creating new chat when no chat id provided and no existing conversations exist
1 parent ec6dc0d commit aed4313

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/khoj/database/adapters/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class ConversationAdapters:
395395
@staticmethod
396396
def get_conversation_by_user(
397397
user: KhojUser, client_application: ClientApplication = None, conversation_id: int = None
398-
):
398+
) -> Optional[Conversation]:
399399
if conversation_id:
400400
conversation = (
401401
Conversation.objects.filter(user=user, client=client_application, id=conversation_id)
@@ -437,15 +437,15 @@ async def acreate_conversation_session(user: KhojUser, client_application: Clien
437437
@staticmethod
438438
async def aget_conversation_by_user(
439439
user: KhojUser, client_application: ClientApplication = None, conversation_id: int = None, title: str = None
440-
):
440+
) -> Optional[Conversation]:
441441
if conversation_id:
442442
return await Conversation.objects.filter(user=user, client=client_application, id=conversation_id).afirst()
443443
elif title:
444444
return await Conversation.objects.filter(user=user, client=client_application, title=title).afirst()
445445
else:
446446
return await (
447447
Conversation.objects.filter(user=user, client=client_application).order_by("-updated_at").afirst()
448-
) or Conversation.objects.acreate(user=user, client=client_application)
448+
) or await Conversation.objects.acreate(user=user, client=client_application)
449449

450450
@staticmethod
451451
async def adelete_conversation_by_user(

src/khoj/routers/api_chat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ async def chat(
330330
intent_type=intent_type,
331331
inferred_queries=[improved_image_prompt],
332332
client_application=request.user.client_app,
333-
conversation_id=conversation_id,
333+
conversation_id=conversation.id,
334334
compiled_references=compiled_references,
335335
online_results=online_results,
336336
)
@@ -347,7 +347,7 @@ async def chat(
347347
conversation_commands,
348348
user,
349349
request.user.client_app,
350-
conversation_id,
350+
conversation.id,
351351
location,
352352
user_name,
353353
)

0 commit comments

Comments
 (0)