mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Run safety check only when agent persona updated on agent edits
Running safety check isn't required if the agent persona wasn't updated this time around as it would have passed safety check previously. This should speed up editing agents when agent persona isn't updated.
This commit is contained in:
@@ -434,6 +434,17 @@ async def update_agent(
|
|||||||
) -> Response:
|
) -> Response:
|
||||||
user: KhojUser = request.user.object
|
user: KhojUser = request.user.object
|
||||||
|
|
||||||
|
selected_agent = await AgentAdapters.aget_agent_by_slug(body.slug, user)
|
||||||
|
|
||||||
|
if not selected_agent:
|
||||||
|
return Response(
|
||||||
|
content=json.dumps({"error": f"Agent with name {body.name} not found."}),
|
||||||
|
media_type="application/json",
|
||||||
|
status_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
if selected_agent.personality != body.persona:
|
||||||
|
# Check if the new persona is safe
|
||||||
is_safe_prompt, reason = await acheck_if_safe_prompt(
|
is_safe_prompt, reason = await acheck_if_safe_prompt(
|
||||||
body.persona, user, lax=body.privacy_level == Agent.PrivacyLevel.PRIVATE
|
body.persona, user, lax=body.privacy_level == Agent.PrivacyLevel.PRIVATE
|
||||||
)
|
)
|
||||||
@@ -445,15 +456,6 @@ async def update_agent(
|
|||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
selected_agent = await AgentAdapters.aget_agent_by_slug(body.slug, user)
|
|
||||||
|
|
||||||
if not selected_agent:
|
|
||||||
return Response(
|
|
||||||
content=json.dumps({"error": f"Agent with name {body.name} not found."}),
|
|
||||||
media_type="application/json",
|
|
||||||
status_code=404,
|
|
||||||
)
|
|
||||||
|
|
||||||
subscribed = has_required_scope(request, ["premium"])
|
subscribed = has_required_scope(request, ["premium"])
|
||||||
chat_model = await ConversationAdapters.aget_chat_model_by_friendly_name(body.chat_model)
|
chat_model = await ConversationAdapters.aget_chat_model_by_friendly_name(body.chat_model)
|
||||||
if subscribed or chat_model.price_tier == PriceTier.FREE:
|
if subscribed or chat_model.price_tier == PriceTier.FREE:
|
||||||
|
|||||||
Reference in New Issue
Block a user