Spaces:
Sleeping
Sleeping
Rename app.py to run.py
Browse files- app.py β run.py +135 -161
app.py β run.py
RENAMED
|
@@ -1,14 +1,28 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
AGENT_TYPES = [
|
| 13 |
"Task Executor",
|
| 14 |
"Information Retriever",
|
|
@@ -24,26 +38,12 @@ TOOL_TYPES = [
|
|
| 24 |
]
|
| 25 |
VERBOSE = False
|
| 26 |
MAX_HISTORY = 100
|
| 27 |
-
MODEL = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 28 |
|
| 29 |
-
# Initialize Hugging Face client
|
| 30 |
client = InferenceClient(MODEL)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
from .prompts import (
|
| 34 |
-
ACTION_PROMPT,
|
| 35 |
-
ADD_PROMPT,
|
| 36 |
-
COMPRESS_HISTORY_PROMPT,
|
| 37 |
-
LOG_PROMPT,
|
| 38 |
-
LOG_RESPONSE,
|
| 39 |
-
MODIFY_PROMPT,
|
| 40 |
-
PREFIX,
|
| 41 |
-
READ_PROMPT,
|
| 42 |
-
TASK_PROMPT,
|
| 43 |
-
UNDERSTAND_TEST_RESULTS_PROMPT,
|
| 44 |
-
)
|
| 45 |
-
from .utils import parse_action, parse_file_content, read_python_module_structure
|
| 46 |
-
|
| 47 |
class Agent:
|
| 48 |
def __init__(self, name: str, agent_type: str, complexity: int):
|
| 49 |
self.name = name
|
|
@@ -57,6 +57,7 @@ class Agent:
|
|
| 57 |
def __str__(self):
|
| 58 |
return f"{self.name} ({self.type}) - Complexity: {self.complexity}"
|
| 59 |
|
|
|
|
| 60 |
class Tool:
|
| 61 |
def __init__(self, name: str, tool_type: str):
|
| 62 |
self.name = name
|
|
@@ -65,6 +66,7 @@ class Tool:
|
|
| 65 |
def __str__(self):
|
| 66 |
return f"{self.name} ({self.type})"
|
| 67 |
|
|
|
|
| 68 |
class Pypelyne:
|
| 69 |
def __init__(self):
|
| 70 |
self.agents: List[Agent] = []
|
|
@@ -84,11 +86,16 @@ class Pypelyne:
|
|
| 84 |
time.sleep(2) # Simulate processing time
|
| 85 |
return f"Chat app generated with {len(self.agents)} agents and {len(self.tools)} tools."
|
| 86 |
|
| 87 |
-
def run_gpt(
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
if VERBOSE:
|
| 94 |
print(LOG_PROMPT.format(content))
|
|
@@ -120,7 +127,7 @@ class Pypelyne:
|
|
| 120 |
)
|
| 121 |
self.history = f"observation: {resp}\n"
|
| 122 |
|
| 123 |
-
def run_action(self, action_name, action_input):
|
| 124 |
if action_name == "COMPLETE":
|
| 125 |
return "Task completed."
|
| 126 |
|
|
@@ -144,7 +151,7 @@ class Pypelyne:
|
|
| 144 |
print(f"RUN: {action_name} {action_input}")
|
| 145 |
return action_funcs[action_name](action_input)
|
| 146 |
|
| 147 |
-
def call_main(self, action_input):
|
| 148 |
resp = self.run_gpt(
|
| 149 |
ACTION_PROMPT,
|
| 150 |
stop_tokens=["observation:", "task:"],
|
|
@@ -164,25 +171,31 @@ class Pypelyne:
|
|
| 164 |
return self.run_action(action_name, action_input)
|
| 165 |
return "No valid action found."
|
| 166 |
|
| 167 |
-
def call_set_task(self, action_input):
|
| 168 |
-
self.task =
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
self.history += f"observation: task has been updated to: {self.task}\n"
|
| 176 |
return f"Task updated: {self.task}"
|
| 177 |
|
| 178 |
-
def call_modify(self, action_input):
|
| 179 |
if not os.path.exists(action_input):
|
| 180 |
self.history += "observation: file does not exist\n"
|
| 181 |
return "File does not exist."
|
| 182 |
|
| 183 |
content = read_python_module_structure(self.directory)[1]
|
| 184 |
f_content = (
|
| 185 |
-
content[action_input]
|
|
|
|
|
|
|
| 186 |
)
|
| 187 |
|
| 188 |
resp = self.run_gpt(
|
|
@@ -206,14 +219,16 @@ class Pypelyne:
|
|
| 206 |
self.history += f"observation: {description}\n"
|
| 207 |
return f"File modified: {action_input}"
|
| 208 |
|
| 209 |
-
def call_read(self, action_input):
|
| 210 |
if not os.path.exists(action_input):
|
| 211 |
self.history += "observation: file does not exist\n"
|
| 212 |
return "File does not exist."
|
| 213 |
|
| 214 |
content = read_python_module_structure(self.directory)[1]
|
| 215 |
f_content = (
|
| 216 |
-
content[action_input]
|
|
|
|
|
|
|
| 217 |
)
|
| 218 |
|
| 219 |
resp = self.run_gpt(
|
|
@@ -228,7 +243,7 @@ class Pypelyne:
|
|
| 228 |
self.history += f"observation: {resp}\n"
|
| 229 |
return f"File read: {action_input}"
|
| 230 |
|
| 231 |
-
def call_add(self, action_input):
|
| 232 |
d = os.path.dirname(action_input)
|
| 233 |
if not d.startswith(self.directory):
|
| 234 |
self.history += (
|
|
@@ -265,7 +280,7 @@ class Pypelyne:
|
|
| 265 |
self.history += "observation: file already exists\n"
|
| 266 |
return "File already exists."
|
| 267 |
|
| 268 |
-
def call_test(self, action_input):
|
| 269 |
result = subprocess.run(
|
| 270 |
["python", "-m", "pytest", "--collect-only", self.directory],
|
| 271 |
capture_output=True,
|
|
@@ -275,7 +290,9 @@ class Pypelyne:
|
|
| 275 |
self.history += f"observation: there are no tests! Test should be written in a test folder under {self.directory}\n"
|
| 276 |
return "No tests found."
|
| 277 |
result = subprocess.run(
|
| 278 |
-
["python", "-m", "pytest", self.directory],
|
|
|
|
|
|
|
| 279 |
)
|
| 280 |
if result.returncode == 0:
|
| 281 |
self.history += "observation: tests pass\n"
|
|
@@ -293,132 +310,89 @@ class Pypelyne:
|
|
| 293 |
self.history += f"observation: tests failed: {resp}\n"
|
| 294 |
return f"Tests failed: {resp}"
|
| 295 |
|
|
|
|
|
|
|
| 296 |
pypelyne = Pypelyne()
|
| 297 |
|
|
|
|
|
|
|
| 298 |
def create_agent(name: str, agent_type: str, complexity: int) -> Agent:
|
| 299 |
agent = Agent(name, agent_type, complexity)
|
| 300 |
pypelyne.add_agent(agent)
|
| 301 |
return agent
|
| 302 |
|
|
|
|
| 303 |
def create_tool(name: str, tool_type: str) -> Tool:
|
| 304 |
tool = Tool(name, tool_type)
|
| 305 |
pypelyne.add_tool(tool)
|
| 306 |
return tool
|
| 307 |
|
| 308 |
-
def main():
|
| 309 |
-
# Create a Flask app
|
| 310 |
-
app = Flask(__name__)
|
| 311 |
-
|
| 312 |
-
# Define a route for the chat interface
|
| 313 |
-
@app.route("/chat", methods=["GET", "POST"])
|
| 314 |
-
def chat():
|
| 315 |
-
if request.method == "POST":
|
| 316 |
-
# Get the user's input
|
| 317 |
-
user_input = request.form["input"]
|
| 318 |
-
|
| 319 |
-
# Run the input through the Pypelyne
|
| 320 |
-
response = pypelyne.run_action("MAIN", user_input)
|
| 321 |
-
|
| 322 |
-
# Return the response
|
| 323 |
-
return jsonify({"response": response})
|
| 324 |
-
else:
|
| 325 |
-
# Return the chat interface
|
| 326 |
-
return """
|
| 327 |
-
<html>
|
| 328 |
-
<body>
|
| 329 |
-
<h1>Pypelyne Chat Interface</h1>
|
| 330 |
-
<form action="/chat" method="post">
|
| 331 |
-
<input type="text" name="input" placeholder="Enter your input">
|
| 332 |
-
<input type="submit" value="Submit">
|
| 333 |
-
</form>
|
| 334 |
-
<div id="response"></div>
|
| 335 |
-
<script>
|
| 336 |
-
// Update the response div with the response from the server
|
| 337 |
-
function updateResponse(response) {
|
| 338 |
-
document.getElementById("response").innerHTML = response;
|
| 339 |
-
}
|
| 340 |
-
</script>
|
| 341 |
-
</body>
|
| 342 |
-
</html>
|
| 343 |
-
"""
|
| 344 |
-
|
| 345 |
-
# Define a route for the agent creation interface
|
| 346 |
-
@app.route("/create_agent", methods=["GET", "POST"])
|
| 347 |
-
def create_agent_interface():
|
| 348 |
-
if request.method == "POST":
|
| 349 |
-
# Get the agent's name, type, and complexity
|
| 350 |
-
name = request.form["name"]
|
| 351 |
-
agent_type = request.form["type"]
|
| 352 |
-
complexity = int(request.form["complexity"])
|
| 353 |
-
|
| 354 |
-
# Create the agent
|
| 355 |
-
agent = create_agent(name, agent_type, complexity)
|
| 356 |
-
|
| 357 |
-
# Return a success message
|
| 358 |
-
return jsonify({"message": f"Agent {name} created successfully"})
|
| 359 |
-
else:
|
| 360 |
-
# Return the agent creation interface
|
| 361 |
-
return """
|
| 362 |
-
<html>
|
| 363 |
-
<body>
|
| 364 |
-
<h1>Create Agent</h1>
|
| 365 |
-
<form action="/create_agent" method="post">
|
| 366 |
-
<label for="name">Name:</label>
|
| 367 |
-
<input type="text" id="name" name="name"><br><br>
|
| 368 |
-
<label for="type">Type:</label>
|
| 369 |
-
<select id="type" name="type">
|
| 370 |
-
<option value="Task Executor">Task Executor</option>
|
| 371 |
-
<option value="Information Retriever">Information Retriever</option>
|
| 372 |
-
<option value="Decision Maker">Decision Maker</option>
|
| 373 |
-
<option value="Data Analyzer">Data Analyzer</option>
|
| 374 |
-
</select><br><br>
|
| 375 |
-
<label for="complexity">Complexity:</label>
|
| 376 |
-
<input type="number" id="complexity" name="complexity"><br><br>
|
| 377 |
-
<input type="submit" value="Create Agent">
|
| 378 |
-
</form>
|
| 379 |
-
</body>
|
| 380 |
-
</html>
|
| 381 |
-
"""
|
| 382 |
-
|
| 383 |
-
# Define a route for the tool creation interface
|
| 384 |
-
@app.route("/create_tool", methods=["GET", "POST"])
|
| 385 |
-
def create_tool_interface():
|
| 386 |
-
if request.method == "POST":
|
| 387 |
-
# Get the tool's name and type
|
| 388 |
-
name = request.form["name"]
|
| 389 |
-
tool_type = request.form["type"]
|
| 390 |
-
|
| 391 |
-
# Create the tool
|
| 392 |
-
tool = create_tool(name, tool_type)
|
| 393 |
-
|
| 394 |
-
# Return a success message
|
| 395 |
-
return jsonify({"message": f"Tool {name} created successfully"})
|
| 396 |
-
else:
|
| 397 |
-
# Return the tool creation interface
|
| 398 |
-
return """
|
| 399 |
-
<html>
|
| 400 |
-
<body>
|
| 401 |
-
<h1>Create Tool</h1>
|
| 402 |
-
<form action="/create_tool" method="post">
|
| 403 |
-
<label for="name">Name:</label>
|
| 404 |
-
<input type="text" id="name" name="name"><br><br>
|
| 405 |
-
<label for="type">Type:</label>
|
| 406 |
-
<select id="type" name="type">
|
| 407 |
-
<option value="Web Scraper">Web Scraper</option>
|
| 408 |
-
<option value="Database Connector">Database Connector</option>
|
| 409 |
-
<option value="API Caller">API Caller</option>
|
| 410 |
-
<option value="File Handler">File Handler</option>
|
| 411 |
-
<option value="Text Processor">Text Processor</option>
|
| 412 |
-
</select><br><br>
|
| 413 |
-
<input type="submit" value="Create Tool">
|
| 414 |
-
</form>
|
| 415 |
-
</body>
|
| 416 |
-
</html>
|
| 417 |
-
"""
|
| 418 |
-
|
| 419 |
-
# Run the app
|
| 420 |
-
if __name__ == "__main__":
|
| 421 |
-
app.run(debug=True)
|
| 422 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
if __name__ == "__main__":
|
| 424 |
main()
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
+
from typing import List, Dict, Tuple
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
+
import streamlit as st
|
| 6 |
+
|
| 7 |
+
from app.prompts import (
|
| 8 |
+
ACTION_PROMPT,
|
| 9 |
+
ADD_PROMPT,
|
| 10 |
+
COMPRESS_HISTORY_PROMPT,
|
| 11 |
+
LOG_PROMPT,
|
| 12 |
+
LOG_RESPONSE,
|
| 13 |
+
MODIFY_PROMPT,
|
| 14 |
+
PREFIX,
|
| 15 |
+
READ_PROMPT,
|
| 16 |
+
TASK_PROMPT,
|
| 17 |
+
UNDERSTAND_TEST_RESULTS_PROMPT,
|
| 18 |
+
)
|
| 19 |
+
from app.utils import (
|
| 20 |
+
parse_action,
|
| 21 |
+
parse_file_content,
|
| 22 |
+
read_python_module_structure,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# --- Constants ---
|
| 26 |
AGENT_TYPES = [
|
| 27 |
"Task Executor",
|
| 28 |
"Information Retriever",
|
|
|
|
| 38 |
]
|
| 39 |
VERBOSE = False
|
| 40 |
MAX_HISTORY = 100
|
| 41 |
+
MODEL = "mistralai/Mixtral-8x7B-Instruct-v0.1" # Consider using a smaller model
|
| 42 |
|
| 43 |
+
# --- Initialize Hugging Face client ---
|
| 44 |
client = InferenceClient(MODEL)
|
| 45 |
|
| 46 |
+
# --- Classes ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
class Agent:
|
| 48 |
def __init__(self, name: str, agent_type: str, complexity: int):
|
| 49 |
self.name = name
|
|
|
|
| 57 |
def __str__(self):
|
| 58 |
return f"{self.name} ({self.type}) - Complexity: {self.complexity}"
|
| 59 |
|
| 60 |
+
|
| 61 |
class Tool:
|
| 62 |
def __init__(self, name: str, tool_type: str):
|
| 63 |
self.name = name
|
|
|
|
| 66 |
def __str__(self):
|
| 67 |
return f"{self.name} ({self.type})"
|
| 68 |
|
| 69 |
+
|
| 70 |
class Pypelyne:
|
| 71 |
def __init__(self):
|
| 72 |
self.agents: List[Agent] = []
|
|
|
|
| 86 |
time.sleep(2) # Simulate processing time
|
| 87 |
return f"Chat app generated with {len(self.agents)} agents and {len(self.tools)} tools."
|
| 88 |
|
| 89 |
+
def run_gpt(
|
| 90 |
+
self, prompt_template: str, stop_tokens: List[str], max_tokens: int, **prompt_kwargs
|
| 91 |
+
) -> str:
|
| 92 |
+
content = (
|
| 93 |
+
PREFIX.format(
|
| 94 |
+
module_summary=read_python_module_structure(self.directory)[0],
|
| 95 |
+
purpose=self.purpose,
|
| 96 |
+
)
|
| 97 |
+
+ prompt_template.format(**prompt_kwargs)
|
| 98 |
+
)
|
| 99 |
|
| 100 |
if VERBOSE:
|
| 101 |
print(LOG_PROMPT.format(content))
|
|
|
|
| 127 |
)
|
| 128 |
self.history = f"observation: {resp}\n"
|
| 129 |
|
| 130 |
+
def run_action(self, action_name: str, action_input: str) -> str:
|
| 131 |
if action_name == "COMPLETE":
|
| 132 |
return "Task completed."
|
| 133 |
|
|
|
|
| 151 |
print(f"RUN: {action_name} {action_input}")
|
| 152 |
return action_funcs[action_name](action_input)
|
| 153 |
|
| 154 |
+
def call_main(self, action_input: str) -> str:
|
| 155 |
resp = self.run_gpt(
|
| 156 |
ACTION_PROMPT,
|
| 157 |
stop_tokens=["observation:", "task:"],
|
|
|
|
| 171 |
return self.run_action(action_name, action_input)
|
| 172 |
return "No valid action found."
|
| 173 |
|
| 174 |
+
def call_set_task(self, action_input: str) -> str:
|
| 175 |
+
self.task = (
|
| 176 |
+
self.run_gpt(
|
| 177 |
+
TASK_PROMPT,
|
| 178 |
+
stop_tokens=[],
|
| 179 |
+
max_tokens=64,
|
| 180 |
+
task=self.task,
|
| 181 |
+
history=self.history,
|
| 182 |
+
)
|
| 183 |
+
.strip("\n")
|
| 184 |
+
.strip()
|
| 185 |
+
)
|
| 186 |
self.history += f"observation: task has been updated to: {self.task}\n"
|
| 187 |
return f"Task updated: {self.task}"
|
| 188 |
|
| 189 |
+
def call_modify(self, action_input: str) -> str:
|
| 190 |
if not os.path.exists(action_input):
|
| 191 |
self.history += "observation: file does not exist\n"
|
| 192 |
return "File does not exist."
|
| 193 |
|
| 194 |
content = read_python_module_structure(self.directory)[1]
|
| 195 |
f_content = (
|
| 196 |
+
content[action_input]
|
| 197 |
+
if content[action_input]
|
| 198 |
+
else "< document is empty >"
|
| 199 |
)
|
| 200 |
|
| 201 |
resp = self.run_gpt(
|
|
|
|
| 219 |
self.history += f"observation: {description}\n"
|
| 220 |
return f"File modified: {action_input}"
|
| 221 |
|
| 222 |
+
def call_read(self, action_input: str) -> str:
|
| 223 |
if not os.path.exists(action_input):
|
| 224 |
self.history += "observation: file does not exist\n"
|
| 225 |
return "File does not exist."
|
| 226 |
|
| 227 |
content = read_python_module_structure(self.directory)[1]
|
| 228 |
f_content = (
|
| 229 |
+
content[action_input]
|
| 230 |
+
if content[action_input]
|
| 231 |
+
else "< document is empty >"
|
| 232 |
)
|
| 233 |
|
| 234 |
resp = self.run_gpt(
|
|
|
|
| 243 |
self.history += f"observation: {resp}\n"
|
| 244 |
return f"File read: {action_input}"
|
| 245 |
|
| 246 |
+
def call_add(self, action_input: str) -> str:
|
| 247 |
d = os.path.dirname(action_input)
|
| 248 |
if not d.startswith(self.directory):
|
| 249 |
self.history += (
|
|
|
|
| 280 |
self.history += "observation: file already exists\n"
|
| 281 |
return "File already exists."
|
| 282 |
|
| 283 |
+
def call_test(self, action_input: str) -> str:
|
| 284 |
result = subprocess.run(
|
| 285 |
["python", "-m", "pytest", "--collect-only", self.directory],
|
| 286 |
capture_output=True,
|
|
|
|
| 290 |
self.history += f"observation: there are no tests! Test should be written in a test folder under {self.directory}\n"
|
| 291 |
return "No tests found."
|
| 292 |
result = subprocess.run(
|
| 293 |
+
["python", "-m", "pytest", self.directory],
|
| 294 |
+
capture_output=True,
|
| 295 |
+
text=True,
|
| 296 |
)
|
| 297 |
if result.returncode == 0:
|
| 298 |
self.history += "observation: tests pass\n"
|
|
|
|
| 310 |
self.history += f"observation: tests failed: {resp}\n"
|
| 311 |
return f"Tests failed: {resp}"
|
| 312 |
|
| 313 |
+
|
| 314 |
+
# --- Global Pypelyne Instance ---
|
| 315 |
pypelyne = Pypelyne()
|
| 316 |
|
| 317 |
+
|
| 318 |
+
# --- Helper Functions ---
|
| 319 |
def create_agent(name: str, agent_type: str, complexity: int) -> Agent:
|
| 320 |
agent = Agent(name, agent_type, complexity)
|
| 321 |
pypelyne.add_agent(agent)
|
| 322 |
return agent
|
| 323 |
|
| 324 |
+
|
| 325 |
def create_tool(name: str, tool_type: str) -> Tool:
|
| 326 |
tool = Tool(name, tool_type)
|
| 327 |
pypelyne.add_tool(tool)
|
| 328 |
return tool
|
| 329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
+
# --- Streamlit App Code ---
|
| 332 |
+
def main():
|
| 333 |
+
st.title("π§ Pypelyne: Your AI-Powered Coding Assistant")
|
| 334 |
+
|
| 335 |
+
# --- Sidebar ---
|
| 336 |
+
st.sidebar.title("βοΈ Settings")
|
| 337 |
+
pypelyne.directory = st.sidebar.text_input(
|
| 338 |
+
"Project Directory:", value=".", help="Path to your coding project"
|
| 339 |
+
)
|
| 340 |
+
pypelyne.purpose = st.sidebar.text_area(
|
| 341 |
+
"Project Purpose:",
|
| 342 |
+
help="Describe the purpose of your coding project.",
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
# --- Agent and Tool Management ---
|
| 346 |
+
st.sidebar.header("π€ Agents")
|
| 347 |
+
show_agent_creation = st.sidebar.expander(
|
| 348 |
+
"Create New Agent", expanded=False
|
| 349 |
+
)
|
| 350 |
+
with show_agent_creation:
|
| 351 |
+
agent_name = st.text_input("Agent Name:")
|
| 352 |
+
agent_type = st.selectbox("Agent Type:", AGENT_TYPES)
|
| 353 |
+
agent_complexity = st.slider("Complexity (1-5):", 1, 5, 3)
|
| 354 |
+
if st.button("Add Agent"):
|
| 355 |
+
create_agent(agent_name, agent_type, agent_complexity)
|
| 356 |
+
|
| 357 |
+
st.sidebar.header("π οΈ Tools")
|
| 358 |
+
show_tool_creation = st.sidebar.expander("Create New Tool", expanded=False)
|
| 359 |
+
with show_tool_creation:
|
| 360 |
+
tool_name = st.text_input("Tool Name:")
|
| 361 |
+
tool_type = st.selectbox("Tool Type:", TOOL_TYPES)
|
| 362 |
+
if st.button("Add Tool"):
|
| 363 |
+
create_tool(tool_name, tool_type)
|
| 364 |
+
|
| 365 |
+
# --- Display Agents and Tools ---
|
| 366 |
+
st.sidebar.subheader("Active Agents:")
|
| 367 |
+
for agent in pypelyne.agents:
|
| 368 |
+
st.sidebar.write(f"- {agent}")
|
| 369 |
+
|
| 370 |
+
st.sidebar.subheader("Available Tools:")
|
| 371 |
+
for tool in pypelyne.tools:
|
| 372 |
+
st.sidebar.write(f"- {tool}")
|
| 373 |
+
|
| 374 |
+
# --- Main Content Area ---
|
| 375 |
+
st.header("π» Code Interaction")
|
| 376 |
+
|
| 377 |
+
task_input = st.text_area(
|
| 378 |
+
"π― Task:",
|
| 379 |
+
value=pypelyne.task if pypelyne.task else "",
|
| 380 |
+
help="Describe the coding task you want to perform.",
|
| 381 |
+
)
|
| 382 |
+
if task_input:
|
| 383 |
+
pypelyne.task = task_input
|
| 384 |
+
|
| 385 |
+
user_input = st.text_input(
|
| 386 |
+
"π¬ Your Input:", help="Provide instructions or ask questions."
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
if st.button("Execute"):
|
| 390 |
+
if user_input:
|
| 391 |
+
with st.spinner("Pypelyne is working..."):
|
| 392 |
+
response = pypelyne.run_action("MAIN", user_input)
|
| 393 |
+
st.write("Pypelyne Says: ", response)
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
# --- Run the Streamlit app ---
|
| 397 |
if __name__ == "__main__":
|
| 398 |
main()
|