fix: handle empty chunks and retriever values in agent creation and update

This commit is contained in:
Siddhant Rai
2025-05-14 09:26:36 +05:30
parent a52a3e3158
commit d1d28df8a1
2 changed files with 32 additions and 6 deletions

View File

@@ -1222,6 +1222,10 @@ class CreateAgent(Resource):
"lastUsedAt": None,
"key": key,
}
if new_agent["chunks"] == "":
new_agent["chunks"] = "0"
if new_agent["source"] == "" and new_agent["retriever"] == "":
new_agent["retriever"] = "classic"
resp = agents_collection.insert_one(new_agent)
new_id = str(resp.inserted_id)
@@ -1334,6 +1338,33 @@ class UpdateAgent(Resource):
)
else:
update_fields[field] = ""
elif field == "chunks":
chunks_value = data.get("chunks")
if chunks_value == "":
update_fields[field] = "0"
else:
try:
if int(chunks_value) < 0:
return make_response(
jsonify(
{
"success": False,
"message": "Chunks value must be a positive integer",
}
),
400,
)
update_fields[field] = chunks_value
except ValueError:
return make_response(
jsonify(
{
"success": False,
"message": "Invalid chunks value provided",
}
),
400,
)
else:
update_fields[field] = data[field]

View File

@@ -102,12 +102,7 @@ export default function NewAgent({ mode }: { mode: 'new' | 'edit' | 'draft' }) {
const isPublishable = () => {
return (
agent.name &&
agent.description &&
(agent.source || agent.retriever) &&
agent.chunks &&
agent.prompt_id &&
agent.agent_type
agent.name && agent.description && agent.prompt_id && agent.agent_type
);
};