mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Add backend support for hidden agents (not yet enabled)
This commit is contained in:
@@ -714,9 +714,12 @@ class AgentAdapters:
|
|||||||
public_query = Q(privacy_level=Agent.PrivacyLevel.PUBLIC)
|
public_query = Q(privacy_level=Agent.PrivacyLevel.PUBLIC)
|
||||||
# TODO Update this to allow any public agent that's officially approved once that experience is launched
|
# TODO Update this to allow any public agent that's officially approved once that experience is launched
|
||||||
public_query &= Q(managed_by_admin=True)
|
public_query &= Q(managed_by_admin=True)
|
||||||
|
|
||||||
|
user_query = Q(creator=user)
|
||||||
|
user_query &= Q(is_hidden=False)
|
||||||
if user:
|
if user:
|
||||||
return (
|
return (
|
||||||
Agent.objects.filter(public_query | Q(creator=user))
|
Agent.objects.filter(public_query | user_query)
|
||||||
.distinct()
|
.distinct()
|
||||||
.order_by("created_at")
|
.order_by("created_at")
|
||||||
.prefetch_related("creator", "chat_model", "fileobject_set")
|
.prefetch_related("creator", "chat_model", "fileobject_set")
|
||||||
@@ -808,6 +811,7 @@ class AgentAdapters:
|
|||||||
input_tools: List[str],
|
input_tools: List[str],
|
||||||
output_modes: List[str],
|
output_modes: List[str],
|
||||||
slug: Optional[str] = None,
|
slug: Optional[str] = None,
|
||||||
|
is_hidden: Optional[bool] = False,
|
||||||
):
|
):
|
||||||
chat_model_option = await ChatModel.objects.filter(name=chat_model).afirst()
|
chat_model_option = await ChatModel.objects.filter(name=chat_model).afirst()
|
||||||
|
|
||||||
@@ -823,6 +827,7 @@ class AgentAdapters:
|
|||||||
"chat_model": chat_model_option,
|
"chat_model": chat_model_option,
|
||||||
"input_tools": input_tools,
|
"input_tools": input_tools,
|
||||||
"output_modes": output_modes,
|
"output_modes": output_modes,
|
||||||
|
"is_hidden": is_hidden,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Generated by Django 5.0.10 on 2025-01-16 23:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("database", "0080_speechtotextmodeloptions_ai_model_api"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="agent",
|
||||||
|
name="is_hidden",
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="chatmodel",
|
||||||
|
name="description",
|
||||||
|
field=models.TextField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="chatmodel",
|
||||||
|
name="strengths",
|
||||||
|
field=models.TextField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -209,6 +209,8 @@ class ChatModel(DbBaseModel):
|
|||||||
model_type = models.CharField(max_length=200, choices=ModelType.choices, default=ModelType.OFFLINE)
|
model_type = models.CharField(max_length=200, choices=ModelType.choices, default=ModelType.OFFLINE)
|
||||||
vision_enabled = models.BooleanField(default=False)
|
vision_enabled = models.BooleanField(default=False)
|
||||||
ai_model_api = models.ForeignKey(AiModelApi, on_delete=models.CASCADE, default=None, null=True, blank=True)
|
ai_model_api = models.ForeignKey(AiModelApi, on_delete=models.CASCADE, default=None, null=True, blank=True)
|
||||||
|
description = models.TextField(default=None, null=True, blank=True)
|
||||||
|
strengths = models.TextField(default=None, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -286,6 +288,7 @@ class Agent(DbBaseModel):
|
|||||||
TEXT = "text"
|
TEXT = "text"
|
||||||
IMAGE = "image"
|
IMAGE = "image"
|
||||||
AUTOMATION = "automation"
|
AUTOMATION = "automation"
|
||||||
|
DIAGRAM = "diagram"
|
||||||
|
|
||||||
creator = models.ForeignKey(
|
creator = models.ForeignKey(
|
||||||
KhojUser, on_delete=models.CASCADE, default=None, null=True, blank=True
|
KhojUser, on_delete=models.CASCADE, default=None, null=True, blank=True
|
||||||
@@ -304,6 +307,7 @@ class Agent(DbBaseModel):
|
|||||||
style_color = models.CharField(max_length=200, choices=StyleColorTypes.choices, default=StyleColorTypes.BLUE)
|
style_color = models.CharField(max_length=200, choices=StyleColorTypes.choices, default=StyleColorTypes.BLUE)
|
||||||
style_icon = models.CharField(max_length=200, choices=StyleIconTypes.choices, default=StyleIconTypes.LIGHTBULB)
|
style_icon = models.CharField(max_length=200, choices=StyleIconTypes.choices, default=StyleIconTypes.LIGHTBULB)
|
||||||
privacy_level = models.CharField(max_length=30, choices=PrivacyLevel.choices, default=PrivacyLevel.PRIVATE)
|
privacy_level = models.CharField(max_length=30, choices=PrivacyLevel.choices, default=PrivacyLevel.PRIVATE)
|
||||||
|
is_hidden = models.BooleanField(default=False)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
is_new = self._state.adding
|
is_new = self._state.adding
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class ModifyAgentBody(BaseModel):
|
|||||||
input_tools: Optional[List[str]] = []
|
input_tools: Optional[List[str]] = []
|
||||||
output_modes: Optional[List[str]] = []
|
output_modes: Optional[List[str]] = []
|
||||||
slug: Optional[str] = None
|
slug: Optional[str] = None
|
||||||
|
is_hidden: Optional[bool] = False
|
||||||
|
|
||||||
|
|
||||||
@api_agents.get("", response_class=Response)
|
@api_agents.get("", response_class=Response)
|
||||||
@@ -214,6 +215,7 @@ async def create_agent(
|
|||||||
body.input_tools,
|
body.input_tools,
|
||||||
body.output_modes,
|
body.output_modes,
|
||||||
body.slug,
|
body.slug,
|
||||||
|
body.is_hidden,
|
||||||
)
|
)
|
||||||
|
|
||||||
agents_packet = {
|
agents_packet = {
|
||||||
@@ -229,6 +231,7 @@ async def create_agent(
|
|||||||
"files": body.files,
|
"files": body.files,
|
||||||
"input_tools": agent.input_tools,
|
"input_tools": agent.input_tools,
|
||||||
"output_modes": agent.output_modes,
|
"output_modes": agent.output_modes,
|
||||||
|
"is_hidden": agent.is_hidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response(content=json.dumps(agents_packet), media_type="application/json", status_code=200)
|
return Response(content=json.dumps(agents_packet), media_type="application/json", status_code=200)
|
||||||
|
|||||||
@@ -474,6 +474,7 @@ async def create_chat_session(
|
|||||||
request: Request,
|
request: Request,
|
||||||
common: CommonQueryParams,
|
common: CommonQueryParams,
|
||||||
agent_slug: Optional[str] = None,
|
agent_slug: Optional[str] = None,
|
||||||
|
# Add parameters here to create a custom hidden agent on the fly
|
||||||
):
|
):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
|
|
||||||
@@ -865,7 +866,7 @@ async def chat(
|
|||||||
# and not triggered via slash command
|
# and not triggered via slash command
|
||||||
and not used_slash_summarize
|
and not used_slash_summarize
|
||||||
# but we can't actually summarize
|
# but we can't actually summarize
|
||||||
and len(file_filters) != 1
|
and len(file_filters) == 0
|
||||||
):
|
):
|
||||||
conversation_commands.remove(ConversationCommand.Summarize)
|
conversation_commands.remove(ConversationCommand.Summarize)
|
||||||
elif ConversationCommand.Summarize in conversation_commands:
|
elif ConversationCommand.Summarize in conversation_commands:
|
||||||
|
|||||||
@@ -20,13 +20,20 @@ def get_chat_model_options(
|
|||||||
request: Request,
|
request: Request,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
):
|
):
|
||||||
conversation_options = ConversationAdapters.get_conversation_processor_options().all()
|
chat_models = ConversationAdapters.get_conversation_processor_options().all()
|
||||||
|
|
||||||
all_conversation_options = list()
|
chat_model_options = list()
|
||||||
for conversation_option in conversation_options:
|
for chat_model in chat_models:
|
||||||
all_conversation_options.append({"chat_model": conversation_option.name, "id": conversation_option.id})
|
chat_model_options.append(
|
||||||
|
{
|
||||||
|
"name": chat_model.name,
|
||||||
|
"id": chat_model.id,
|
||||||
|
"strengths": chat_model.strengths,
|
||||||
|
"description": chat_model.description,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return Response(content=json.dumps(all_conversation_options), media_type="application/json", status_code=200)
|
return Response(content=json.dumps(chat_model_options), media_type="application/json", status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@api_model.get("/chat")
|
@api_model.get("/chat")
|
||||||
|
|||||||
@@ -2231,7 +2231,14 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
|
|||||||
chat_models = ConversationAdapters.get_conversation_processor_options().all()
|
chat_models = ConversationAdapters.get_conversation_processor_options().all()
|
||||||
chat_model_options = list()
|
chat_model_options = list()
|
||||||
for chat_model in chat_models:
|
for chat_model in chat_models:
|
||||||
chat_model_options.append({"name": chat_model.name, "id": chat_model.id})
|
chat_model_options.append(
|
||||||
|
{
|
||||||
|
"name": chat_model.name,
|
||||||
|
"id": chat_model.id,
|
||||||
|
"strengths": chat_model.strengths,
|
||||||
|
"description": chat_model.description,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
selected_paint_model_config = ConversationAdapters.get_user_text_to_image_model_config(user)
|
selected_paint_model_config = ConversationAdapters.get_user_text_to_image_model_config(user)
|
||||||
paint_model_options = ConversationAdapters.get_text_to_image_model_options().all()
|
paint_model_options = ConversationAdapters.get_text_to_image_model_options().all()
|
||||||
|
|||||||
Reference in New Issue
Block a user