Artificial-superintelligence commited on
Commit
6890f24
·
verified ·
1 Parent(s): c7280a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -72,6 +72,11 @@ def execute_command(command, cwd=None):
72
  stdout, stderr = process.communicate()
73
  return stdout + stderr
74
 
 
 
 
 
 
75
  @app.route("/")
76
  def index():
77
  return render_template("index.html")
@@ -87,9 +92,10 @@ def execute_code():
87
  if command.lower().startswith("ai:"):
88
  # Process command with Gemini AI
89
  ai_command = command[3:].strip()
90
- response = chat.send_message(system_instruction + f"\nUser request: {ai_command}")
 
91
  ai_result = response.text.strip()
92
-
93
  # Execute the AI-suggested command or action
94
  if ai_result.startswith("CREATE_FILE:"):
95
  filename = ai_result.split(":")[1]
@@ -103,22 +109,14 @@ def execute_code():
103
  with open(filepath, 'w') as f:
104
  f.write(content)
105
  result = f"File {filename} created and edited successfully."
106
- elif ai_result.startswith("!python -m pip install"):
107
- result = execute_command(ai_result[1:]) # Remove the leading '!'
108
- elif ai_result.startswith("git clone"):
109
- result = execute_command(ai_result)
110
- elif ai_result.startswith("cd "):
111
- new_dir = os.path.join(current_dir, ai_result[3:])
112
- if os.path.isdir(new_dir):
113
- current_dir = os.path.abspath(new_dir)
114
- result = f"Changed directory to: {current_dir}"
115
- else:
116
- result = f"Error: Directory not found: {new_dir}"
117
- elif ai_result.startswith("!python "):
118
  result = execute_command(ai_result[1:]) # Remove the leading '!'
 
 
 
119
  else:
120
- result = f"Unclear AI response: {ai_result}"
121
-
122
  return jsonify({"result": f"AI Executed: {ai_result}\n\nOutput:\n{result}"})
123
  elif command == "show files":
124
  files = os.listdir(current_dir)
 
72
  stdout, stderr = process.communicate()
73
  return stdout + stderr
74
 
75
+ def read_knowledge_base():
76
+ knowledge_file = os.path.join(os.path.dirname(__file__), 'knowledge.txt')
77
+ with open(knowledge_file, 'r') as file:
78
+ return file.read()
79
+
80
  @app.route("/")
81
  def index():
82
  return render_template("index.html")
 
92
  if command.lower().startswith("ai:"):
93
  # Process command with Gemini AI
94
  ai_command = command[3:].strip()
95
+ knowledge_base = read_knowledge_base()
96
+ response = chat.send_message(f"{system_instruction}\n\nKnowledge Base:\n{knowledge_base}\n\nUser request: {ai_command}")
97
  ai_result = response.text.strip()
98
+
99
  # Execute the AI-suggested command or action
100
  if ai_result.startswith("CREATE_FILE:"):
101
  filename = ai_result.split(":")[1]
 
109
  with open(filepath, 'w') as f:
110
  f.write(content)
111
  result = f"File {filename} created and edited successfully."
112
+ elif ai_result.startswith("!"):
 
 
 
 
 
 
 
 
 
 
 
113
  result = execute_command(ai_result[1:]) # Remove the leading '!'
114
+ elif ai_result.startswith("show files"):
115
+ files = os.listdir(current_dir)
116
+ result = "Files in current directory:\n" + "\n".join(files)
117
  else:
118
+ result = execute_command(ai_result)
119
+
120
  return jsonify({"result": f"AI Executed: {ai_result}\n\nOutput:\n{result}"})
121
  elif command == "show files":
122
  files = os.listdir(current_dir)