Skip to content

Commit

Permalink
few bugs solved
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigorij-Dudnik committed Jan 9, 2025
1 parent 7f5b2eb commit 8c55793
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
File renamed without changes.
7 changes: 2 additions & 5 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
add_todoist_envs()

from typing import TypedDict, Sequence
from langchain_core.messages import BaseMessage, HumanMessage
from langchain_core.messages import BaseMessage, HumanMessage, ToolMessage
from langchain_core.load import dumps
from langgraph.graph import StateGraph
from src.tools.tools_project_manager import add_task, modify_task, finish_project_planning, reorder_tasks
Expand Down Expand Up @@ -40,17 +40,14 @@ def __init__(self):
self.manager = self.setup_workflow()
self.saved_messages_path = join_paths(self.work_dir, ".clean_coder/manager_messages.json")




def call_model_manager(self, state):
self.save_messages_to_disk(state)
state = call_model(state, self.llms)
state = self.cut_off_context(state)
state = call_tool(state, self.tools)
messages = [msg for msg in state["messages"] if msg.type == "ai"]
last_ai_message = messages[-1]
if not last_ai_message.content:
if not last_ai_message.content and not last_ai_message.tool_calls:
state["messages"].pop()
state["messages"].append(HumanMessage(content=empty_message_msg))
elif len(last_ai_message.tool_calls) == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/agents/planner_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def call_planer(state):


def ask_human_planner(state):
human_message = user_input("Type (o)k if you accept or provide commentary.")
human_message = user_input("Type (o)k if you accept or provide commentary. ")
if human_message in ['o', 'ok']:
state["messages"].append(HumanMessage(content="Approved by human"))
else:
Expand Down
23 changes: 15 additions & 8 deletions src/tools/tools_project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from single_task_coder import run_clean_coder_pipeline
import uuid
import requests
from requests.exceptions import HTTPError
import json


Expand Down Expand Up @@ -44,12 +45,15 @@ def add_task(task_name, task_description, order):
if human_message not in ['o', 'ok']:
return TOOL_NOT_EXECUTED_WORD + f"Action wasn't executed because of human interruption. He said: {human_message}"

todoist_api.add_task(
project_id=os.getenv('TODOIST_PROJECT_ID'),
content=task_name,
description=task_description,
order=order,
)
try:
todoist_api.add_task(
project_id=os.getenv('TODOIST_PROJECT_ID'),
content=task_name,
description=task_description,
order=order,
)
except HTTPError:
raise Exception(f"Are you sure Todoist project (ID: {os.getenv('TODOIST_PROJECT_ID')}) exists?")
return "Task added successfully"


Expand All @@ -62,8 +66,11 @@ def modify_task(task_id, new_task_name=None, new_task_description=None, delete=F
:param new_task_description: new detailed description of what needs to be done in order to implement task (optional).
:param delete: if True, task will be deleted.
"""
task_name = todoist_api.get_task(task_id).content
human_message = user_input(f"I want to {'delete' if delete else 'modify'} task '{task_name}'. Type (o)k to agree or provide commentary.")
try:
task_name = todoist_api.get_task(task_id).content
except HTTPError:
raise Exception(f"Are you sure Todoist project (ID: {os.getenv('TODOIST_PROJECT_ID')}) exists?")
human_message = user_input(f"I want to {'delete' if delete else 'modify'} task '{task_name}'. Type (o)k or provide commentary. ")
if human_message not in ['o', 'ok']:
return TOOL_NOT_EXECUTED_WORD + f"Action wasn't executed because of human interruption. He said: {human_message}"

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/langgraph_common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def call_tool(state, tools):


def ask_human(state):
human_message = user_input("Type (o)k if you accept or provide commentary. ")
human_message = user_input("Type (o)k to accept or provide commentary. ")
if human_message in ['o', 'ok']:
state["messages"].append(HumanMessage(content="Approved by human"))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/manager_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def setup_todoist_project():

project_choices = [f"{proj.name} (ID: {proj.id})" for proj in projects]
choice = questionary.select(
"No project connected. Do you want to create a new project or use existing one?",
"No Todoist project connected. Do you want to create a new project or use existing one?",
choices=["Create new project", "Use existing project"],
style=QUESTIONARY_STYLE
).ask()
Expand Down

0 comments on commit 8c55793

Please sign in to comment.