Fix retrieving image model by prefetching the openai config in the async method

This commit is contained in:
sabaimran 2024-07-04 11:58:33 +05:30
parent a129b017b9
commit d61bddf56c

View file

@ -904,7 +904,7 @@ class ConversationAdapters:
@staticmethod @staticmethod
async def aget_text_to_image_model_config(): async def aget_text_to_image_model_config():
return await TextToImageModelConfig.objects.filter().afirst() return await TextToImageModelConfig.objects.filter().prefetch_related("openai_config").afirst()
@staticmethod @staticmethod
def get_text_to_image_model_options(): def get_text_to_image_model_options():
@ -914,7 +914,10 @@ class ConversationAdapters:
def get_user_text_to_image_model_config(user: KhojUser): def get_user_text_to_image_model_config(user: KhojUser):
config = UserTextToImageModelConfig.objects.filter(user=user).first() config = UserTextToImageModelConfig.objects.filter(user=user).first()
if not config: if not config:
return None default_config = ConversationAdapters.get_text_to_image_model_config()
if not default_config:
return None
return default_config
return config.setting return config.setting
@staticmethod @staticmethod