Skip to content

Commit

Permalink
Fixed "procedures" not in JSON error
Browse files Browse the repository at this point in the history
KillianLucas committed Aug 11, 2023
1 parent c5811ae commit f57f52e
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion interpreter/interpreter.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import getpass
import requests
import readline
import urllib.parse
import tokentrim as tt
from rich import print
from rich.markdown import Markdown
@@ -107,8 +108,12 @@ def get_info_for_system_message(self):
# Open Procedures is an open-source database of tiny, structured coding tutorials.
# We can query it semantically and append relevant tutorials/procedures to our system message:

# Get procedures that are relevant to the last messages
# Embed and truncate the last two messages
query = str(self.messages[-2:])
query = urllib.parse.quote(query)
query = query[-2000:]

# Use them to query Open Procedures
url = f"https://open-procedures.replit.app/search/?query={query}"
relevant_procedures = requests.get(url).json()["procedures"]
info += "\n\n# Potentially Helpful Procedures (may or may not be related)\n" + "\n---\n".join(relevant_procedures)
6 changes: 3 additions & 3 deletions tests/test_interpreter.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@

def test_hello_world():
interpreter.reset()
messages = interpreter.chat("""Please reply with just the words "Hello, World!" and nothing else.""", return_messages=True)
assert messages == [{'role': 'user', 'content': 'Please reply with just the words "Hello, World!" and nothing else.'}, {'role': 'assistant', 'content': 'Hello, World!'}]
messages = interpreter.chat("""Please reply with just the words "Hello, World!" and nothing else. Do not run code.""", return_messages=True)
assert messages == [{'role': 'user', 'content': 'Please reply with just the words "Hello, World!" and nothing else. Do not run code.'}, {'role': 'assistant', 'content': 'Hello, World!'}]

def test_math():
interpreter.reset()
@@ -23,4 +23,4 @@ def test_nested_loops_and_multiple_newlines():

def test_markdown():
interpreter.reset()
interpreter.chat("Hi, can you test out a bunch of markdown features? Try writing a fenced code block, a table, headers, everything. DO NOT write the markdown inside a markdown code block, just write it raw.")
interpreter.chat("""Hi, can you test out a bunch of markdown features? Try writing a fenced code block, a table, headers, everything. DO NOT write the markdown inside a markdown code block, just write it raw.""")

0 comments on commit f57f52e

Please sign in to comment.