Merge pull request #585 from khoj-ai/fix/image-generation-and-csrf-cookie

Fix image generation setup bug and CSRF cookie for admin login
This commit is contained in:
sabaimran 2023-12-17 16:55:45 +05:30 committed by GitHub
commit e9ea0195b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -33,6 +33,9 @@ ALLOWED_HOSTS = [f".{KHOJ_DOMAIN}", "localhost", "127.0.0.1", "[::1]"]
CSRF_TRUSTED_ORIGINS = [
f"https://*.{KHOJ_DOMAIN}",
f"https://{KHOJ_DOMAIN}",
f"http://*.{KHOJ_DOMAIN}",
f"http://{KHOJ_DOMAIN}",
f"https://app.{KHOJ_DOMAIN}",
]
COOKIE_SAMESITE = "None"
@ -42,6 +45,7 @@ if DEBUG or os.getenv("KHOJ_DOMAIN") == None:
else:
SESSION_COOKIE_DOMAIN = KHOJ_DOMAIN
CSRF_COOKIE_DOMAIN = KHOJ_DOMAIN
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTOCOL", "https")
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

View file

@ -12,6 +12,7 @@ from khoj.database.models import (
SpeechToTextModelOptions,
Subscription,
ReflectiveQuestion,
TextToImageModelConfig,
)
admin.site.register(KhojUser, UserAdmin)
@ -23,3 +24,4 @@ admin.site.register(OfflineChatProcessorConversationConfig)
admin.site.register(SearchModelConfig)
admin.site.register(Subscription)
admin.site.register(ReflectiveQuestion)
admin.site.register(TextToImageModelConfig)

View file

@ -715,6 +715,13 @@ async def chat(
)
elif conversation_command == ConversationCommand.Image:
image, status_code = await text_to_image(q)
if image is None:
content_obj = {
"image": image,
"intentType": "text-to-image",
"detail": "Failed to generate image. Make sure your image generation configuration is set.",
}
return Response(content=json.dumps(content_obj), media_type="application/json", status_code=status_code)
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)