Skip to content
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

Agent state codestyle fix #436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions devika.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
os.environ["TOKENIZERS_PARALLELISM"] = "false"

manager = ProjectManager()
AgentState = AgentState()
agent_state = AgentState()
config = Config()
logger = Logger()

Expand Down Expand Up @@ -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()

Expand All @@ -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})


Expand All @@ -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"])
Expand All @@ -126,23 +126,23 @@ 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})


@app.route("/api/get-terminal-session", methods=["GET"])
@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})


Expand All @@ -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})


Expand Down
6 changes: 3 additions & 3 deletions src/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

ollama = Ollama()
logger = Logger()
agentState = AgentState()
agent_state = AgentState()


class LLM:
Expand Down Expand Up @@ -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:
Expand Down