From f70d139447f89695e766fbef43b518c7130e64b6 Mon Sep 17 00:00:00 2001 From: mudler Date: Wed, 2 Aug 2023 00:52:12 +0200 Subject: [PATCH] wip python repl - minor notes --- main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/main.py b/main.py index fd0de23..401b6b8 100644 --- a/main.py +++ b/main.py @@ -346,6 +346,8 @@ def evaluate(user_input, conversation_history = [],re_evaluate=False, agent_acti cr+= "Request: "+subtask["reasoning"] subtask_response, function_results = process_functions(cr, subtask["function"],agent_actions=agent_actions) subtask_result+=process_history(subtask_response) + if postprocess: + subtask_result=post_process(subtask_result) responses.extend(subtask_response) if re_evaluate: ## Better output or this infinite loops.. @@ -363,6 +365,7 @@ def evaluate(user_input, conversation_history = [],re_evaluate=False, agent_acti conversation_history.extend(responses) return conversation_history + # TODO: this needs to be optimized responses.append( { "role": "system", @@ -396,6 +399,7 @@ def evaluate(user_input, conversation_history = [],re_evaluate=False, agent_acti logger.info("==> μAGI will reply to the user") return conversation_history + # TODO: this needs to be optimized # get the response from the model response = openai.ChatCompletion.create( model=LLM_MODEL, @@ -456,6 +460,14 @@ def search(query, agent_actions={}): text_res+="- "+doc.page_content+"\n" return text_res +# Python REPL +def python_repl(args, agent_actions={}): + args = json.loads(args) + try: + return eval(args["code"]) + except Exception as e: + return str(e) + def calculate_plan(user_input, agent_actions={}): res = json.loads(user_input) logger.info("--> Calculating plan: {description}", description=res["description"]) @@ -660,6 +672,29 @@ agent_actions = { } }, }, + "python": { + "function": python_repl, + "plannable": True, + "description": 'The assistant replies with the action "python" to execute Python code.', + "signature": { + "name": "python", + "description": """Search in memory""", + "parameters": { + "type": "object", + "properties": { + "code": { + "type": "string", + "description": "reasoning behind the intent" + }, + "reasoning": { + "type": "string", + "description": "reasoning behind the intent" + }, + }, + "required": ["code"] + } + }, + }, "search_memory": { "function": search, "plannable": True,