Skip to content

Commit

Permalink
updated frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
CoffeeCoder16 committed Jul 18, 2023
1 parent 95cd220 commit 9439e12
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
86 changes: 75 additions & 11 deletions gui/pages/Content/Agents/AgentCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'react-toastify/dist/ReactToastify.css';
import styles from './Agents.module.css';
import {
createAgent,
editAgentTemplate,
fetchAgentTemplateConfigLocal,
getOrganisationConfig,
updateExecution,
Expand Down Expand Up @@ -32,6 +33,7 @@ export default function AgentCreate({
}) {
const [advancedOptions, setAdvancedOptions] = useState(false);
const [agentName, setAgentName] = useState("");
const [agentTemplateId, setAgentTemplateId] = useState(null);
const [agentDescription, setAgentDescription] = useState("");
const [longTermMemory, setLongTermMemory] = useState(true);
const [addResources, setAddResources] = useState(true);
Expand All @@ -42,6 +44,7 @@ export default function AgentCreate({
const [maxIterations, setIterations] = useState(25);
const [toolkitList, setToolkitList] = useState(toolkits)
const [searchValue, setSearchValue] = useState('');
const [showButton, setShowButton] = useState(false);

const constraintsArray = [
"If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.",
Expand Down Expand Up @@ -132,6 +135,7 @@ export default function AgentCreate({
setLocalStorageValue("agent_name_" + String(internalId), template.name, setAgentName);
setLocalStorageValue("agent_description_" + String(internalId), template.description, setAgentDescription);
setLocalStorageValue("advanced_options_" + String(internalId), true, setAdvancedOptions);
setLocalStorageValue("agent_template_id_" + String(internalId), template.id, setAgentTemplateId);

fetchAgentTemplateConfigLocal(template.id)
.then((response) => {
Expand All @@ -146,6 +150,8 @@ export default function AgentCreate({
setLocalStorageValue("agent_database_" + String(internalId), data.LTM_DB, setDatabase);
setLocalStorageValue("agent_model_" + String(internalId), data.model, setModel);
setLocalStorageArray("tool_names_" + String(internalId), data.tools, setToolNames);
setLocalStorageValue("is_agent_template_" + String(internalId), true, setShowButton);
setShowButton(true);
})
.catch((error) => {
console.error('Error fetching template details:', error);
Expand Down Expand Up @@ -357,33 +363,35 @@ export default function AgentCreate({
}
}, [scheduleData]);

const handleAddAgent = () => {
if (!hasAPIkey) {
const validateAgentData = (isNewAgent) => {
if (isNewAgent && !hasAPIkey) {
toast.error("Your OpenAI/Palm API key is empty!", {autoClose: 1800});
openNewTab(-3, "Settings", "Settings", false);
return
return false;
}

if (agentName.replace(/\s/g, '') === '') {
toast.error("Agent name can't be blank", {autoClose: 1800});
return
return false;
}

if (agentDescription.replace(/\s/g, '') === '') {
toast.error("Agent description can't be blank", {autoClose: 1800});
return
return false;
}

const isEmptyGoal = goals.some((goal) => goal.replace(/\s/g, '') === '');
if (isEmptyGoal) {
toast.error("Goal can't be empty", {autoClose: 1800});
return;
return false;
}

if (selectedTools.length <= 0) {
toast.error("Add atleast one tool", {autoClose: 1800});
return
return false;
}
return true;
}

const handleAddAgent = () => {
if (!validateAgentData(true)) return;

setCreateClickable(false);

Expand Down Expand Up @@ -526,6 +534,46 @@ export default function AgentCreate({
event.preventDefault();
};

function updateTemplate() {

if (!validateAgentData(false)) return;

let permission_type = permission;
if (permission.includes("RESTRICTED")) {
permission_type = "RESTRICTED";
}

const agentTemplateConfigData = {
"goal": goals,
"instruction": instructions,
"agent_type": agentType,
"constraints": constraints,
"tools": toolNames,
"exit": exitCriterion,
"iteration_interval": stepTime,
"model": model,
"max_iterations": maxIterations,
"permission_type": permission_type,
"LTM_DB": longTermMemory ? database : null,
}
const editTemplateData = {
"name": agentName,
"description": agentDescription,
"agent_configs": agentTemplateConfigData
}

editAgentTemplate(agentTemplateId, editTemplateData)
.then((response) => {
if (response.status === 200) {
toast.success('Agent template has been updated successfully!', {autoClose: 1800});
}
})
.catch((error) => {
toast.error("Error updating agent template")
console.error('Error updating agent template:', error);
});
};

function setFileData(files) {
if (files.length > 0) {
const fileData = {
Expand Down Expand Up @@ -574,11 +622,21 @@ export default function AgentCreate({
setAdvancedOptions(JSON.parse(advanced_options));
}

const is_agent_template = localStorage.getItem("is_agent_template_" + String(internalId));
if (is_agent_template) {
setShowButton(true);
}

const agent_name = localStorage.getItem("agent_name_" + String(internalId));
if (agent_name) {
setAgentName(agent_name);
}

const agent_template_id = localStorage.getItem("agent_template_id_"+ String(internalId));
if(agent_template_id){
setAgentTemplateId(agent_template_id)
}

const agent_description = localStorage.getItem("agent_description_" + String(internalId));
if (agent_description) {
setAgentDescription(agent_description);
Expand Down Expand Up @@ -981,6 +1039,12 @@ export default function AgentCreate({
<button style={{marginRight: '7px'}} className="secondary_button"
onClick={() => removeTab(-1, "new agent", "Create_Agent", internalId)}>Cancel
</button>
{showButton && (
<button style={{ marginRight: '7px' }} className="secondary_button"
onClick={() => {updateTemplate()}}>
Update Template
</button>
)}
<div style={{display: 'flex', position: 'relative'}}>
{createDropdown && (<div className="custom_select_option" style={{
background: '#3B3B49',
Expand Down
4 changes: 4 additions & 0 deletions gui/pages/api/DashboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const updateExecution = (executionId, executionData) => {
return api.put(`/agentexecutions/update/${executionId}`, executionData);
};

export const editAgentTemplate = (agentTemplateId, agentTemplateData) => {
return api.put(`/agent_templates/edit_agent_template/${agentTemplateId}`, agentTemplateData)
}

export const addExecution = (executionData) => {
return api.post(`/agentexecutions/add`, executionData);
};
Expand Down
6 changes: 2 additions & 4 deletions superagi/controllers/agent_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ def edit_agent_template(agent_template_id: int,
if db_agent_template is None:
raise HTTPException(status_code=404, detail="Agent Template not found")

Check warning on line 171 in superagi/controllers/agent_template.py

View check run for this annotation

Codecov / codecov/patch

superagi/controllers/agent_template.py#L171

Added line #L171 was not covered by tests

if "name" in edited_agent_configs:
db_agent_template.name = edited_agent_configs["name"]
if "description" in edited_agent_configs:
db_agent_template.description = edited_agent_configs["description"]
db_agent_template.name = edited_agent_configs["name"]
db_agent_template.description = edited_agent_configs["description"]

Check warning on line 174 in superagi/controllers/agent_template.py

View check run for this annotation

Codecov / codecov/patch

superagi/controllers/agent_template.py#L173-L174

Added lines #L173 - L174 were not covered by tests

db.session.commit()

Check warning on line 176 in superagi/controllers/agent_template.py

View check run for this annotation

Codecov / codecov/patch

superagi/controllers/agent_template.py#L176

Added line #L176 was not covered by tests

Expand Down

0 comments on commit 9439e12

Please sign in to comment.