Onurcan Genç commited on
Commit ·
ff023bb
1
Parent(s): d07fe3b
changed.
Browse files
app.py
CHANGED
|
@@ -15,14 +15,22 @@ if not api_key:
|
|
| 15 |
interpreter.llm.api_key = api_key
|
| 16 |
interpreter.llm.model = "meta-llama/Llama-3.1-8B-Instruct" # Example model
|
| 17 |
|
| 18 |
-
# Function to execute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def execute_task(task):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
-
return
|
| 26 |
|
| 27 |
# CLI interface using argparse
|
| 28 |
def cli_interface():
|
|
|
|
| 15 |
interpreter.llm.api_key = api_key
|
| 16 |
interpreter.llm.model = "meta-llama/Llama-3.1-8B-Instruct" # Example model
|
| 17 |
|
| 18 |
+
# Function to execute shell commands if detected in model output
|
| 19 |
+
def execute_shell_command(command):
|
| 20 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 21 |
+
return result.stdout if result.returncode == 0 else result.stderr
|
| 22 |
+
|
| 23 |
+
# Function to process tasks using OpenInterpreter and detect shell commands
|
| 24 |
def execute_task(task):
|
| 25 |
+
# Get the model-generated response first
|
| 26 |
+
response = interpreter.chat(task)
|
| 27 |
+
|
| 28 |
+
# Check if the response indicates a shell command
|
| 29 |
+
if "run shell" in response.lower():
|
| 30 |
+
command = response.split("run shell", 1)[1].strip()
|
| 31 |
+
return execute_shell_command(command)
|
| 32 |
else:
|
| 33 |
+
return response
|
| 34 |
|
| 35 |
# CLI interface using argparse
|
| 36 |
def cli_interface():
|