This commit is contained in:
mrq 2023-04-30 03:30:46 +00:00
parent f9cfd1667f
commit 0964f48fc0

View File

@ -15,7 +15,10 @@ def create_agent_proxy(name, age, traits, status, daily_summaries=None):
kwargs["daily_summaries"] = [ ( summary ) for summary in summaries ]
agent = create_agent(**kwargs)
AGENTS[agent.name] = agent
return f"Agent created: {agent.name}"
return (
f"Agent created: {agent.name}",
update_agents_list()
)
def edit_agent( name, age, traits, status, daily_summaries=None ):
if daily_summaries is not None:
@ -37,7 +40,7 @@ def agent_observes_proxy( agents, observations ):
for agent in agents:
agent = AGENTS[agent]
observations = observations.split("\n")
results = agent_observes( agent, observations, summarize = False )
results = agent_observes( agent, observations )
messages.append(f"[{agent.name} Observation noted. Importance score: {[ result[-1] for result in results ]}")
return "\n".join(messages)
@ -84,7 +87,7 @@ def get_saved_agents_list():
if not os.path.exists("./agents/"):
return []
return [ d.split(".")[:-1] for d in os.listdir("./agents/") if d.split(".")[-1] == "pth" ]
return [ ".".join(d.split(".")[:-1]) for d in os.listdir("./agents/") if d.split(".")[-1] == "pth" ]
def update_agents_list():
agents = get_agents_list()
@ -102,7 +105,6 @@ def save_agent_proxy( agents ):
save_agent( agent )
def load_agent_proxy( agents ):
print( agents )
if not isinstance( agents, list ):
agents = [ agents ]
@ -131,8 +133,6 @@ def setup_webui(share=False):
ACTIONS = {}
AGENT_LISTS = []
agents_list = get_agents_list()
saved_agents_list = get_saved_agents_list()
@ -151,10 +151,6 @@ def setup_webui(share=False):
with gr.Column():
console_output = gr.Textbox(lines=8, label="Console Output")
ACTIONS["add_agent"].click(create_agent_proxy,
inputs=list(AGENT_SETTINGS.values()),
outputs=console_output
)
ACTIONS["edit_agent"].click(edit_agent,
inputs=list(AGENT_SETTINGS.values()),
outputs=console_output
@ -162,7 +158,7 @@ def setup_webui(share=False):
with gr.Tab("Save/Load"):
with gr.Row():
with gr.Column():
SAVELOAD_SETTINGS["agent"] = gr.Dropdown(choices=saved_agents_list, label="Agent", type="value", value=saved_agents_list[0] if len(saved_agents_list) > 0 else [""], multiselect=True)
SAVELOAD_SETTINGS["agent"] = gr.Dropdown(choices=saved_agents_list, label="Agent", type="value", value=saved_agents_list if len(saved_agents_list) > 0 else [""], multiselect=True)
with gr.Row():
ACTIONS["save"] = gr.Button(value="Save")
@ -208,25 +204,19 @@ def setup_webui(share=False):
outputs=console_output
)
ACTIONS["add_agent"].click(update_saved_agents_list,
inputs=None,
outputs=SAVELOAD_SETTINGS["agent"]
ACTIONS["add_agent"].click(create_agent_proxy,
inputs=list(AGENT_SETTINGS.values()),
outputs=[
console_output,
OBSERVE_SETTINGS["agent"],
]
)
ACTIONS["add_agent"].click(update_agents_list,
inputs=None,
outputs=OBSERVE_SETTINGS["agent"]
)
ACTIONS["load"].click(load_agent_proxy,
inputs=SAVELOAD_SETTINGS["agent"],
outputs=OBSERVE_SETTINGS["agent"]
)
ACTIONS["load"].click(update_agents_list,
inputs=None,
outputs=OBSERVE_SETTINGS["agent"]
)
ACTIONS["refresh_agents_list"].click(update_agents_list,
inputs=None,
outputs=OBSERVE_SETTINGS["agent"]