Use base64 encoded image instead of source URL for persistence

The source URL returned by OpenAI would expire soon. This would make
the chat sessions contain non-accessible images/messages if using
OpenaI image URL

Get base64 encoded image from OpenAI and store directly in
conversation logs. This resolves the image link expiring issue
This commit is contained in:
Debanjum Singh Solanky
2023-12-04 22:55:22 -05:00
parent 52c5f4170a
commit 6e3f66c0f1
5 changed files with 18 additions and 36 deletions

View File

@@ -706,9 +706,9 @@ async def chat(
status_code=200,
)
elif conversation_command == ConversationCommand.Image:
image_url, status_code = await text_to_image(q)
await sync_to_async(save_to_conversation_log)(q, image_url, user, meta_log, intent_type="text-to-image")
content_obj = {"imageUrl": image_url, "intentType": "text-to-image"}
image, status_code = await text_to_image(q)
await sync_to_async(save_to_conversation_log)(q, image, user, meta_log, intent_type="text-to-image")
content_obj = {"image": image, "intentType": "text-to-image"}
return Response(content=json.dumps(content_obj), media_type="application/json", status_code=status_code)
# Get the (streamed) chat response from the LLM of choice.