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

This PR fix devika #603

Open
wants to merge 23 commits 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
6 changes: 5 additions & 1 deletion devika.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@


app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": ["https://localhost:3000"]}}) # Change the origin to your frontend URL
CORS(app, resources={r"/*": {"origins": # Change the origin to your frontend URL
[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add port 3001

"https://localhost:3000",
"http://localhost:3000",
]}})
app.register_blueprint(project_bp)
socketio.init_app(app)

Expand Down
16 changes: 11 additions & 5 deletions src/agents/coder/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render(
def validate_response(self, response: str) -> Union[List[Dict[str, str]], bool]:
response = response.strip()

self.logger.debug(f"Response from the model: {response}")
# self.logger.debug(f"Response from the model: {response}")

if "~~~" not in response:
return False
Expand All @@ -49,10 +49,15 @@ def validate_response(self, response: str) -> Union[List[Dict[str, str]], bool]:
code_block = False

for line in response.split("\n"):
if line.startswith("File: "):
if line.startswith("File:"):
if current_file and current_code:
result.append({"file": current_file, "code": "\n".join(current_code)})
current_file = line.split(":")[1].strip()
if "`" in line:
current_file = line.split("`")[1].strip()
elif line.startswith("File:") and line.endswith(":") and "`" not in line:
current_file = line.split(":")[1].strip()
else:
return False
current_code = []
code_block = False
elif line.startswith("```"):
Expand All @@ -71,10 +76,11 @@ def save_code_to_project(self, response: List[Dict[str, str]], project_name: str

for file in response:
file_path = os.path.join(self.project_dir, project_name, file['file'])
file_path_dir = os.path.dirname(file_path)
file_norm_path = os.path.normpath(file_path)
file_path_dir = os.path.dirname(file_norm_path)
os.makedirs(file_path_dir, exist_ok=True)

with open(file_path, "w", encoding="utf-8") as f:
with open(file_norm_path, "w+", encoding="utf-8") as f:
f.write(file["code"])

return file_path_dir
Expand Down
5 changes: 3 additions & 2 deletions src/agents/feature/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def save_code_to_project(self, response: List[Dict[str, str]], project_name: str

for file in response:
file_path = os.path.join(self.project_dir, project_name, file['file'])
file_path_dir = os.path.dirname(file_path)
file_norm_path = os.path.normpath(file_path)
file_path_dir = os.path.dirname(file_norm_path)
os.makedirs(file_path_dir, exist_ok=True)

with open(file_path, "w", encoding="utf-8") as f:
with open(file_norm_path, "w+", encoding="utf-8") as f:
f.write(file["code"])

return file_path_dir
Expand Down
19 changes: 18 additions & 1 deletion src/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,30 @@ def create_project(self, project: str):
project_state = Projects(project=project, message_stack_json=json.dumps([]))
session.add(project_state)
session.commit()
# Create project directory
project_dir = os.path.join(self.project_path, project)
os.makedirs(project_dir, exist_ok=True)

def delete_project(self, project: str):
with Session(self.engine) as session:
project_state = session.query(Projects).filter(Projects.project == project).first()
project_state = session.query(Projects).filter_by(project=project).first()
if project_state:
session.delete(project_state)
session.commit()
# Delete project directory
project_dir = os.path.join(self.project_path, project)
if os.path.exists(project_dir):
# Empty the directory
for root, dirs, files in os.walk(project_dir, topdown=False):
for file in files:
file_path = os.path.join(root, file)
os.remove(file_path)
for dir1 in dirs:
dir_path = os.path.join(root, dir1)
os.rmdir(dir_path)

# Remove the empty directory
os.rmdir(project_dir)

def add_message_to_project(self, project: str, message: dict):
with Session(self.engine) as session:
Expand Down
5 changes: 4 additions & 1 deletion src/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def update_latest_state(self, project: str, state: dict):
emit_agent("agent-state", state_stack)

def get_latest_state(self, project: str):
if not project:
# If no project is selected, return None immediately
return None
with Session(self.engine) as session:
agent_state = session.query(AgentStateModel).filter(AgentStateModel.project == project).first()
if agent_state:
Expand Down Expand Up @@ -174,4 +177,4 @@ def get_latest_token_usage(self, project: str):
if agent_state:
return json.loads(agent_state.state_stack_json)[-1]["token_usage"]
return 0