From 8c3a963bf78bd8055f2e8df4266d684ae314d68d Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Thu, 18 Apr 2024 19:56:12 +0700 Subject: [PATCH] Fix agent_state codestyle --- devika.py | 24 ++++++++++++------------ src/llm/llm.py | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/devika.py b/devika.py index bf97df62..69c91169 100644 --- a/devika.py +++ b/devika.py @@ -42,7 +42,7 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false" manager = ProjectManager() -AgentState = AgentState() +agent_state = AgentState() config = Config() logger = Logger() @@ -88,7 +88,7 @@ def handle_message(data): new_message['from_devika'] = False manager.add_message_from_user(project_name, new_message['message']) - if AgentState.is_agent_completed(project_name): + if agent_state.is_agent_completed(project_name): thread = Thread(target=lambda: agent.subsequent_execute(message, project_name)) thread.start() @@ -102,7 +102,7 @@ def handle_message(data): def is_agent_active(): data = request.json project_name = data.get("project_name") - is_active = AgentState.is_agent_active(project_name) + is_active = agent_state.is_agent_active(project_name) return jsonify({"is_active": is_active}) @@ -111,8 +111,8 @@ def is_agent_active(): def get_agent_state(): data = request.json project_name = data.get("project_name") - agent_state = AgentState.get_latest_state(project_name) - return jsonify({"state": agent_state}) + latest_state = agent_state.get_latest_state(project_name) + return jsonify({"state": latest_state}) @app.route("/api/get-browser-snapshot", methods=["GET"]) @@ -126,11 +126,11 @@ def browser_snapshot(): @route_logger(logger) def get_browser_session(): project_name = request.args.get("project_name") - agent_state = AgentState.get_latest_state(project_name) - if not agent_state: + latest_state = agent_state.get_latest_state(project_name) + if not latest_state: return jsonify({"session": None}) else: - browser_session = agent_state["browser_session"] + browser_session = latest_state["browser_session"] return jsonify({"session": browser_session}) @@ -138,11 +138,11 @@ def get_browser_session(): @route_logger(logger) def get_terminal_session(): project_name = request.args.get("project_name") - agent_state = AgentState.get_latest_state(project_name) - if not agent_state: + latest_state = agent_state.get_latest_state(project_name) + if not latest_state: return jsonify({"terminal_state": None}) else: - terminal_state = agent_state["terminal_session"] + terminal_state = latest_state["terminal_session"] return jsonify({"terminal_state": terminal_state}) @@ -169,7 +169,7 @@ def calculate_tokens(): @route_logger(logger) def token_usage(): project_name = request.args.get("project_name") - token_count = AgentState.get_latest_token_usage(project_name) + token_count = agent_state.get_latest_token_usage(project_name) return jsonify({"token_usage": token_count}) diff --git a/src/llm/llm.py b/src/llm/llm.py index f040c38f..c3b44c1f 100644 --- a/src/llm/llm.py +++ b/src/llm/llm.py @@ -18,7 +18,7 @@ ollama = Ollama() logger = Logger() -agentState = AgentState() +agent_state = AgentState() class LLM: @@ -69,9 +69,9 @@ def model_id_to_enum_mapping(self) -> dict: @staticmethod def update_global_token_usage(string: str, project_name: str): token_usage = len(TIKTOKEN_ENC.encode(string)) - agentState.update_token_usage(project_name, token_usage) + agent_state.update_token_usage(project_name, token_usage) - total = agentState.get_latest_token_usage(project_name) + token_usage + total = agent_state.get_latest_token_usage(project_name) + token_usage emit_agent("tokens", {"token_usage": total}) def inference(self, prompt: str, project_name: str) -> str: