Merge pull request #29 from birbbit/hb/skills_in_prompt
Skills added dynamically to prompt
This commit is contained in:
commit
ada6c5225c
|
@ -161,3 +161,6 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
# ignore the aifs index files
|
||||||
|
_.aifs
|
||||||
|
|
37
OS/01/i.py
37
OS/01/i.py
|
@ -5,7 +5,10 @@ import os
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from interpreter import OpenInterpreter
|
||||||
|
|
||||||
|
|
||||||
|
def configure_interpreter(interpreter: OpenInterpreter):
|
||||||
def configure_interpreter(interpreter):
|
def configure_interpreter(interpreter):
|
||||||
### SYSTEM MESSAGE
|
### SYSTEM MESSAGE
|
||||||
|
|
||||||
|
@ -41,6 +44,31 @@ def configure_interpreter(interpreter):
|
||||||
|
|
||||||
Remember: You can run Python code. Be very concise. Ensure that you actually run code every time! THIS IS IMPORTANT. You NEED to write code. **Help the user by being very concise in your answers.** Do not break down tasks excessively, just into simple, few minute steps. Don't assume the user lives their life in a certain way— pick very general tasks if you're breaking a task down.
|
Remember: You can run Python code. Be very concise. Ensure that you actually run code every time! THIS IS IMPORTANT. You NEED to write code. **Help the user by being very concise in your answers.** Do not break down tasks excessively, just into simple, few minute steps. Don't assume the user lives their life in a certain way— pick very general tasks if you're breaking a task down.
|
||||||
|
|
||||||
|
Use the following functions (assume they're imported) to complete your goals whenever possible:
|
||||||
|
{{
|
||||||
|
import sys
|
||||||
|
|
||||||
|
original_stdout = sys.stdout
|
||||||
|
sys.stdout = open(os.devnull, 'w')
|
||||||
|
original_stderr = sys.stderr
|
||||||
|
sys.stderr = open(os.devnull, 'w')
|
||||||
|
|
||||||
|
from interpreter import interpreter
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
query = "all functions"
|
||||||
|
skills_path = Path().resolve() / 'skills'
|
||||||
|
paths_in_skills = [str(path) for path in skills_path.glob('**/*.py')]
|
||||||
|
skills = interpreter.computer.docs.search(query, paths=paths_in_skills)
|
||||||
|
lowercase_skills = [skill[0].lower() + skill[1:] for skill in skills]
|
||||||
|
output = "\\n".join(lowercase_skills)
|
||||||
|
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
|
|
||||||
|
print(output)
|
||||||
|
}}
|
||||||
|
|
||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
interpreter.custom_instructions = system_message
|
interpreter.custom_instructions = system_message
|
||||||
|
@ -65,7 +93,6 @@ def configure_interpreter(interpreter):
|
||||||
interpreter.offline = True
|
interpreter.offline = True
|
||||||
interpreter.id = 206 # Used to identify itself to other interpreters. This should be changed programatically so it's unique.
|
interpreter.id = 206 # Used to identify itself to other interpreters. This should be changed programatically so it's unique.
|
||||||
|
|
||||||
|
|
||||||
### RESET conversations/user.json
|
### RESET conversations/user.json
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
@ -74,11 +101,7 @@ def configure_interpreter(interpreter):
|
||||||
json.dump([], file)
|
json.dump([], file)
|
||||||
|
|
||||||
### SKILLS
|
### SKILLS
|
||||||
|
interpreter.computer.skills.skills_dir = Path(__file__).parent / 'skills'
|
||||||
skills_path = Path(__file__).parent / 'skills'
|
interpreter.computer.skills.import_skills()
|
||||||
for file in glob.glob(os.path.join(skills_path, '*.py')):
|
|
||||||
with open(file, 'r') as f:
|
|
||||||
for chunk in interpreter.computer.run("python", f.read()):
|
|
||||||
print(chunk)
|
|
||||||
|
|
||||||
return interpreter
|
return interpreter
|
|
@ -3,8 +3,8 @@ from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def add_message_to_queue(message):
|
|
||||||
|
|
||||||
|
def _add_message_to_queue(message):
|
||||||
# Define the message data and convert it to JSON
|
# Define the message data and convert it to JSON
|
||||||
message_json = json.dumps({
|
message_json = json.dumps({
|
||||||
"role": "computer",
|
"role": "computer",
|
||||||
|
@ -14,12 +14,14 @@ def add_message_to_queue(message):
|
||||||
})
|
})
|
||||||
subprocess.run(['logger', '{TO_INTERPRETER{' + message_json + '}TO_INTERPRETER}'])
|
subprocess.run(['logger', '{TO_INTERPRETER{' + message_json + '}TO_INTERPRETER}'])
|
||||||
|
|
||||||
def schedule(dt, message):
|
|
||||||
|
def schedule(dt: datetime, message: str) -> None:
|
||||||
|
""""Schedules a reminder at a specific time. At the specified time, the message will be added to the queue."""
|
||||||
# Calculate the delay in seconds
|
# Calculate the delay in seconds
|
||||||
delay = (dt - datetime.now()).total_seconds()
|
delay = (dt - datetime.now()).total_seconds()
|
||||||
|
|
||||||
# Create a timer
|
# Create a timer
|
||||||
timer = threading.Timer(delay, add_message_to_queue, args=[message])
|
timer = threading.Timer(delay, _add_message_to_queue, args=[message])
|
||||||
|
|
||||||
# Start the timer
|
# Start the timer
|
||||||
timer.start()
|
timer.start()
|
Loading…
Reference in New Issue