-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes in save template #1120
Merged
Merged
Changes in save template #1120
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4e62d61
fix
rounak610 ee53fd0
Merge remote-tracking branch 'origin/dev' into dev
rounak610 a27a8fe
changes in save template
rounak610 a193820
changes in save template
rounak610 b7c36bd
bug fixes
namansleeps2 ff2cadb
changes in save template
rounak610 6c303d7
changes in save template
rounak610 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,8 +192,9 @@ def edit_agent_template(agent_template_id: int, | |
db.session.flush() | ||
|
||
|
||
@router.post("/save_agent_as_template/agent_execution_id/{agent_execution_id}") | ||
@router.post("/save_agent_as_template/agent_id/{agent_id}/agent_execution_id/{agent_execution_id}") | ||
def save_agent_as_template(agent_execution_id: str, | ||
agent_id: str, | ||
organisation=Depends(get_user_organisation)): | ||
""" | ||
Save an agent as a template. | ||
|
@@ -209,44 +210,64 @@ def save_agent_as_template(agent_execution_id: str, | |
Raises: | ||
HTTPException (status_code=404): If the agent or agent execution configurations are not found. | ||
""" | ||
|
||
if agent_execution_id == 'undefined': | ||
raise HTTPException(status_code = 404, detail = "Agent Execution Id undefined") | ||
|
||
agent_executions = AgentExecution.get_agent_execution_from_id(db.session, agent_execution_id) | ||
if agent_executions is None: | ||
raise HTTPException(status_code = 404, detail = "Agent Execution not found") | ||
agent_id = agent_executions.agent_id | ||
if agent_id == 'undefined': | ||
raise HTTPException(status_code = 404, detail = "Agent Id undefined") | ||
|
||
agent = db.session.query(Agent).filter(Agent.id == agent_id).first() | ||
if agent is None: | ||
raise HTTPException(status_code=404, detail="Agent not found") | ||
|
||
agent_execution_configurations = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() | ||
if not agent_execution_configurations: | ||
raise HTTPException(status_code=404, detail="Agent configurations not found") | ||
main_keys = AgentTemplate.main_keys() | ||
|
||
agent_template = AgentTemplate(name=agent.name, description=agent.description, | ||
if agent_execution_id == "-1": | ||
agent_configurations = db.session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() | ||
if not agent_configurations: | ||
raise HTTPException(status_code=404, detail="Agent configurations not found") | ||
|
||
agent_template = AgentTemplate(name=agent.name, description=agent.description, | ||
agent_workflow_id=agent.agent_workflow_id, | ||
organisation_id=organisation.id) | ||
db.session.add(agent_template) | ||
db.session.commit() | ||
main_keys = AgentTemplate.main_keys() | ||
|
||
for agent_execution_configuration in agent_execution_configurations: | ||
config_value = agent_execution_configuration.value | ||
if agent_execution_configuration.key not in main_keys: | ||
continue | ||
if agent_execution_configuration.key == "tools": | ||
config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_execution_configuration.value))) | ||
agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_execution_configuration.key, | ||
value=config_value) | ||
db.session.add(agent_template_config) | ||
db.session.add(agent_template) | ||
db.session.commit() | ||
|
||
for agent_configuration in agent_configurations: | ||
config_value = agent_configuration.value | ||
if agent_configuration.key not in main_keys: | ||
continue | ||
if agent_configuration.key == "tools": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also improve the unit tests as there are too many changes, and code coverage might decrease. |
||
config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_configuration.value))) | ||
agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_configuration.key, | ||
value=config_value) | ||
db.session.add(agent_template_config) | ||
else: | ||
agent_execution_configurations = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() | ||
if not agent_execution_configurations: | ||
raise HTTPException(status_code=404, detail="Agent execution configurations not found") | ||
|
||
agent_template = AgentTemplate(name=agent.name, description=agent.description, | ||
agent_workflow_id=agent.agent_workflow_id, | ||
organisation_id=organisation.id) | ||
db.session.add(agent_template) | ||
db.session.commit() | ||
|
||
for agent_execution_configuration in agent_execution_configurations: | ||
config_value = agent_execution_configuration.value | ||
if agent_execution_configuration.key not in main_keys: | ||
continue | ||
if agent_execution_configuration.key == "tools": | ||
config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_execution_configuration.value))) | ||
agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_execution_configuration.key, | ||
value=config_value) | ||
db.session.add(agent_template_config) | ||
|
||
|
||
db.session.commit() | ||
db.session.flush() | ||
return agent_template.to_dict() | ||
|
||
|
||
@router.get("/list") | ||
def list_agent_templates(template_source="local", search_str="", page=0, organisation=Depends(get_user_organisation)): | ||
""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this variable instead directly use in call method, these variables make the method long and complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok