Spaces:
Sleeping
Sleeping
Commit
·
dfabb80
1
Parent(s):
a3da6c6
req updated
Browse files- Dockerfile +1 -0
- frontend/app/src/App.jsx +5 -4
- src/__pycache__/app.cpython-313.pyc +0 -0
- src/app.py +5 -1
- src/codeagent/src/codeagent/crews/SqlCrew/sqlcrew.py +2 -5
- src/codeagent/src/codeagent/main.py +21 -4
Dockerfile
CHANGED
|
@@ -24,6 +24,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 24 |
COPY requirements.txt ./
|
| 25 |
COPY src/ ./src/
|
| 26 |
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
|
|
| 27 |
|
| 28 |
RUN python3 -m venv /opt/venv
|
| 29 |
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
| 24 |
COPY requirements.txt ./
|
| 25 |
COPY src/ ./src/
|
| 26 |
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 27 |
+
COPY frontend/app/dist/ /app/src/static/
|
| 28 |
|
| 29 |
RUN python3 -m venv /opt/venv
|
| 30 |
ENV PATH="/opt/venv/bin:$PATH"
|
frontend/app/src/App.jsx
CHANGED
|
@@ -348,10 +348,11 @@ function WSListener() {
|
|
| 348 |
});
|
| 349 |
setShowDiffForFile(data.filename || selectedFile?.name);
|
| 350 |
}
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
|
|
|
| 355 |
});
|
| 356 |
|
| 357 |
socket.on("disconnect", () => {
|
|
|
|
| 348 |
});
|
| 349 |
setShowDiffForFile(data.filename || selectedFile?.name);
|
| 350 |
}
|
| 351 |
+
});
|
| 352 |
+
|
| 353 |
+
socket.on("log", (data) => {
|
| 354 |
+
console.log("WS message:", data);
|
| 355 |
+
pushChat({ role: "agent", text: `${data.msg}`});
|
| 356 |
});
|
| 357 |
|
| 358 |
socket.on("disconnect", () => {
|
src/__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/src/__pycache__/app.cpython-313.pyc and b/src/__pycache__/app.cpython-313.pyc differ
|
|
|
src/app.py
CHANGED
|
@@ -14,7 +14,11 @@ from flask_socketio import SocketIO, emit
|
|
| 14 |
|
| 15 |
event_queue = queue.Queue()
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
| 19 |
|
| 20 |
__all__ = ["app", "socketio"]
|
|
|
|
| 14 |
|
| 15 |
event_queue = queue.Queue()
|
| 16 |
|
| 17 |
+
if "SPACE_ID" in os.environ:
|
| 18 |
+
app = Flask(__name__, static_folder='static', static_url_path='/')
|
| 19 |
+
else:
|
| 20 |
+
app = Flask(__name__, static_folder='../frontend/app/dist', static_url_path='/')
|
| 21 |
+
|
| 22 |
socketio = SocketIO(app, cors_allowed_origins="*")
|
| 23 |
|
| 24 |
__all__ = ["app", "socketio"]
|
src/codeagent/src/codeagent/crews/SqlCrew/sqlcrew.py
CHANGED
|
@@ -5,16 +5,13 @@ from crewai.agents.agent_builder.base_agent import BaseAgent
|
|
| 5 |
import sys
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")))
|
| 9 |
-
from app import socketio
|
| 10 |
-
|
| 11 |
from codeagent.src.codeagent.tools.custom_tools import execute_sql_file, get_files_and_schema, propose_code_changes, get_recent_query_result
|
| 12 |
|
| 13 |
llm = LLM(model="ollama/llama3.1:8b-instruct-q4_0", base_url="http://localhost:11434")
|
| 14 |
|
| 15 |
|
| 16 |
-
def send_chat_message(output: str) -> None:
|
| 17 |
-
|
| 18 |
|
| 19 |
@CrewBase
|
| 20 |
class SqlCrew:
|
|
|
|
| 5 |
import sys
|
| 6 |
import os
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
from codeagent.src.codeagent.tools.custom_tools import execute_sql_file, get_files_and_schema, propose_code_changes, get_recent_query_result
|
| 9 |
|
| 10 |
llm = LLM(model="ollama/llama3.1:8b-instruct-q4_0", base_url="http://localhost:11434")
|
| 11 |
|
| 12 |
|
| 13 |
+
# def send_chat_message(output: str) -> None:
|
| 14 |
+
# socketio.emit("event", {'kind':'agent_message', 'output': output})
|
| 15 |
|
| 16 |
@CrewBase
|
| 17 |
class SqlCrew:
|
src/codeagent/src/codeagent/main.py
CHANGED
|
@@ -5,11 +5,31 @@ from crewai.flow import Flow, listen, start
|
|
| 5 |
from crewai import Agent, LLM
|
| 6 |
|
| 7 |
from typing import Literal
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# from codeagent.src.codeagent.crews.git_crew.git_crew import GitCrew
|
| 11 |
from codeagent.src.codeagent.crews.SqlCrew.sqlcrew import SqlCrew
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class FlowState(BaseModel):
|
| 14 |
user_input: str = ""
|
| 15 |
decision: str = ""
|
|
@@ -59,13 +79,13 @@ class CodeAgentFlow(Flow[FlowState]):
|
|
| 59 |
elif self.state.decision == "SqlCrew":
|
| 60 |
result = SqlCrew().crew().kickoff(inputs={"task": self.state.user_input})
|
| 61 |
self.state.result = result.raw
|
|
|
|
| 62 |
else:
|
| 63 |
self.state.result = f"Invalid decision from router: {self.state.decision}"
|
| 64 |
|
| 65 |
|
| 66 |
@listen(decide_crew)
|
| 67 |
def save_result(self):
|
| 68 |
-
print("Saving result...")
|
| 69 |
with open("crew_result.txt", "w") as f:
|
| 70 |
f.write(self.state.result)
|
| 71 |
|
|
@@ -81,6 +101,3 @@ def plot():
|
|
| 81 |
code_agent_flow.plot()
|
| 82 |
|
| 83 |
|
| 84 |
-
if __name__ == "__main__":
|
| 85 |
-
# Example kickoff
|
| 86 |
-
kickoff("please push my changes to git repository")
|
|
|
|
| 5 |
from crewai import Agent, LLM
|
| 6 |
|
| 7 |
from typing import Literal
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
|
| 11 |
|
| 12 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")))
|
| 13 |
+
from app import socketio
|
| 14 |
+
|
| 15 |
# from codeagent.src.codeagent.crews.git_crew.git_crew import GitCrew
|
| 16 |
from codeagent.src.codeagent.crews.SqlCrew.sqlcrew import SqlCrew
|
| 17 |
|
| 18 |
+
from io import TextIOWrapper
|
| 19 |
+
|
| 20 |
+
class SocketWriter(TextIOWrapper):
|
| 21 |
+
def __init__(self, emit_func):
|
| 22 |
+
self.emit = emit_func
|
| 23 |
+
super().__init__(None, write_through=True)
|
| 24 |
+
|
| 25 |
+
def write(self, text):
|
| 26 |
+
if text.strip():
|
| 27 |
+
self.emit('log', {'msg': text.strip()})
|
| 28 |
+
super().write(text)
|
| 29 |
+
|
| 30 |
+
old_stdout = sys.stdout
|
| 31 |
+
sys.stdout = SocketWriter(lambda event, data: socketio.emit(event, data))
|
| 32 |
+
|
| 33 |
class FlowState(BaseModel):
|
| 34 |
user_input: str = ""
|
| 35 |
decision: str = ""
|
|
|
|
| 79 |
elif self.state.decision == "SqlCrew":
|
| 80 |
result = SqlCrew().crew().kickoff(inputs={"task": self.state.user_input})
|
| 81 |
self.state.result = result.raw
|
| 82 |
+
sys.stdout = old_stdout
|
| 83 |
else:
|
| 84 |
self.state.result = f"Invalid decision from router: {self.state.decision}"
|
| 85 |
|
| 86 |
|
| 87 |
@listen(decide_crew)
|
| 88 |
def save_result(self):
|
|
|
|
| 89 |
with open("crew_result.txt", "w") as f:
|
| 90 |
f.write(self.state.result)
|
| 91 |
|
|
|
|
| 101 |
code_agent_flow.plot()
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|