mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-10 05:39:11 +00:00
Use conversation specific chat model to respond to free tier users
Recent changes enabled free tier users to switch free tier chat models per conversation or the default. This change enables free tier users to generate responses with their conversation specific chat model. Related: #725, #1151
This commit is contained in:
@@ -1454,12 +1454,12 @@ class ConversationAdapters:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def aget_valid_chat_model(user: KhojUser, conversation: Conversation, is_subscribed: bool):
|
async def aget_valid_chat_model(user: KhojUser, conversation: Conversation, is_subscribed: bool):
|
||||||
agent: Agent = (
|
"""
|
||||||
conversation.agent
|
For paid users: Prefer any custom agent chat model > user default chat model > server default chat model.
|
||||||
if is_subscribed and await AgentAdapters.aget_default_agent() != conversation.agent
|
For free users: Prefer conversation specific agent's chat model > user default chat model > server default chat model.
|
||||||
else None
|
"""
|
||||||
)
|
agent: Agent = conversation.agent if await AgentAdapters.aget_default_agent() != conversation.agent else None
|
||||||
if agent and agent.chat_model:
|
if agent and agent.chat_model and (agent.is_hidden or is_subscribed):
|
||||||
chat_model = await ChatModel.objects.select_related("ai_model_api").aget(
|
chat_model = await ChatModel.objects.select_related("ai_model_api").aget(
|
||||||
pk=conversation.agent.chat_model.pk
|
pk=conversation.agent.chat_model.pk
|
||||||
)
|
)
|
||||||
@@ -1488,7 +1488,7 @@ class ConversationAdapters:
|
|||||||
return chat_model
|
return chat_model
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid conversation config - either configure offline chat or openai chat")
|
raise ValueError("Invalid conversation settings. Configure some chat model on server.")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def aget_text_to_image_model_config():
|
async def aget_text_to_image_model_config():
|
||||||
|
|||||||
Reference in New Issue
Block a user