Fix default chat model to use user model if no server chat model set

- Advanced chat model should also fallback to user chat model if set
- Get conversation config should falback to user chat model if set

These assume no server chat model settings is configured
This commit is contained in:
Debanjum Singh Solanky 2024-10-13 03:02:29 -07:00
parent 81aa1b5589
commit 263eee4351
3 changed files with 9 additions and 11 deletions

View file

@ -939,21 +939,21 @@ class ConversationAdapters:
def get_conversation_config(user: KhojUser):
subscribed = is_user_subscribed(user)
if not subscribed:
return ConversationAdapters.get_default_conversation_config()
return ConversationAdapters.get_default_conversation_config(user)
config = UserConversationConfig.objects.filter(user=user).first()
if config:
return config.setting
return ConversationAdapters.get_advanced_conversation_config()
return ConversationAdapters.get_advanced_conversation_config(user)
@staticmethod
async def aget_conversation_config(user: KhojUser):
subscribed = await ais_user_subscribed(user)
if not subscribed:
return await ConversationAdapters.aget_default_conversation_config()
return await ConversationAdapters.aget_default_conversation_config(user)
config = await UserConversationConfig.objects.filter(user=user).prefetch_related("setting").afirst()
if config:
return config.setting
return ConversationAdapters.aget_advanced_conversation_config()
return ConversationAdapters.aget_advanced_conversation_config(user)
@staticmethod
async def aget_voice_model_config(user: KhojUser) -> Optional[VoiceModelOption]:
@ -1014,22 +1014,22 @@ class ConversationAdapters:
return await ChatModelOptions.objects.filter().prefetch_related("openai_config").afirst()
@staticmethod
def get_advanced_conversation_config():
def get_advanced_conversation_config(user: KhojUser):
server_chat_settings = ServerChatSettings.objects.first()
if server_chat_settings is not None and server_chat_settings.chat_advanced is not None:
return server_chat_settings.chat_advanced
return ConversationAdapters.get_default_conversation_config()
return ConversationAdapters.get_default_conversation_config(user)
@staticmethod
async def aget_advanced_conversation_config():
async def aget_advanced_conversation_config(user: KhojUser = None):
server_chat_settings: ServerChatSettings = (
await ServerChatSettings.objects.filter()
.prefetch_related("chat_advanced", "chat_advanced__openai_config")
.afirst()
)
if server_chat_settings is not None or server_chat_settings.chat_advanced is not None:
if server_chat_settings is not None and server_chat_settings.chat_advanced is not None:
return server_chat_settings.chat_advanced
return await ConversationAdapters.aget_default_conversation_config()
return await ConversationAdapters.aget_default_conversation_config(user)
@staticmethod
def create_conversation_from_public_conversation(

View file

@ -141,7 +141,6 @@ async def read_webpages(
conversation_history: dict,
location: LocationData,
user: KhojUser,
subscribed: bool = False,
send_status_func: Optional[Callable] = None,
uploaded_image_url: str = None,
agent: Agent = None,

View file

@ -910,7 +910,6 @@ async def chat(
meta_log,
location,
user,
subscribed,
partial(send_event, ChatEvent.STATUS),
uploaded_image_url=uploaded_image_url,
agent=agent,