Skip to content

Commit 931ac90

Browse files
committed
Test server
1 parent 5994bd7 commit 931ac90

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-50
lines changed

.github/workflows/python-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Build and Test
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: ["main", "development"]
66
pull_request:
7-
branches: ["main"]
7+
branches: ["main", "development"]
88

99
jobs:
1010
build:

interpreter/core/async_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def run(self, retries=5, *args, **kwargs):
610610
)
611611
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
612612
s.connect(("8.8.8.8", 80)) # Google's public DNS server
613-
print(f"Server is running at http://{s.getsockname()[0]}:{self.port}")
613+
print(f"Server will run at http://{s.getsockname()[0]}:{self.port}")
614614
s.close()
615615

616616
for _ in range(retries):

tests/test_interpreter.py

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
import signal
34
import time
45
from random import randint
56

@@ -22,49 +23,14 @@
2223
from websocket import create_connection
2324

2425

25-
def test_hallucinations():
26-
# We should be resiliant to common hallucinations.
27-
28-
code = """{
29-
"language": "python",
30-
"code": "10+12"
31-
}"""
32-
33-
interpreter.messages = [
34-
{"role": "assistant", "type": "code", "format": "python", "content": code}
35-
]
36-
for chunk in interpreter._respond_and_store():
37-
if chunk.get("format") == "output":
38-
assert chunk.get("content") == "22"
39-
break
40-
41-
code = """functions.execute({
42-
"language": "python",
43-
"code": "10+12"
44-
})"""
45-
46-
interpreter.messages = [
47-
{"role": "assistant", "type": "code", "format": "python", "content": code}
48-
]
49-
for chunk in interpreter._respond_and_store():
50-
if chunk.get("format") == "output":
51-
assert chunk.get("content") == "22"
52-
break
53-
54-
code = """{language: "python", code: "print('hello')" }"""
55-
56-
interpreter.messages = [
57-
{"role": "assistant", "type": "code", "format": "python", "content": code}
58-
]
59-
for chunk in interpreter._respond_and_store():
60-
if chunk.get("format") == "output":
61-
assert chunk.get("content").strip() == "hello"
62-
break
63-
64-
65-
@pytest.mark.skip(reason="Requires uvicorn, which we don't require by default")
26+
# @pytest.mark.skip(reason="Requires uvicorn, which we don't require by default")
6627
def test_server():
67-
# os.system("pip install 'open-interpreter[server]'")
28+
try:
29+
import janus
30+
except:
31+
os.system(
32+
'pip install "git+https://github.com/OpenInterpreter/open-interpreter.git#egg=open-interpreter[server]"'
33+
)
6834
# Start the server in a new thread
6935
async_interpreter = AsyncInterpreter()
7036
async_interpreter.print = False
@@ -90,7 +56,7 @@ async def test_fastapi_server():
9056
# Sending POST request
9157
post_url = "http://localhost:8000/settings"
9258
settings = {
93-
"model": "gpt-4o",
59+
"llm": {"model": "gpt-4o"},
9460
"messages": [
9561
{
9662
"role": "user",
@@ -144,7 +110,7 @@ async def test_fastapi_server():
144110
# Send another POST request
145111
post_url = "http://localhost:8000/settings"
146112
settings = {
147-
"model": "gpt-4o",
113+
"llm": {"model": "gpt-4o"},
148114
"messages": [
149115
{
150116
"role": "user",
@@ -291,17 +257,64 @@ async def test_fastapi_server():
291257

292258
assert "18893094989" in accumulated_content.replace(",", "")
293259

260+
# Sending POST request to /run endpoint with code to kill a thread in Python
261+
# actually wait i dont think this will work..? will just kill the python interpreter
262+
post_url = "http://localhost:8000/run"
263+
code_data = {
264+
"code": "import os, signal; os.kill(os.getpid(), signal.SIGINT)",
265+
"language": "python",
266+
}
267+
response = requests.post(post_url, json=code_data)
268+
print("POST request sent, response:", response.json())
269+
294270
# Get the current event loop and run the test function
295271
loop = asyncio.get_event_loop()
296272
loop.run_until_complete(test_fastapi_server())
297273

298-
# Stop the server
299-
async_interpreter.server.uvicorn_server.should_exit = True
300-
301274
# Wait for the server thread to finish
302275
server_thread.join(timeout=1)
303276

304277

278+
def test_hallucinations():
279+
# We should be resiliant to common hallucinations.
280+
281+
code = """{
282+
"language": "python",
283+
"code": "10+12"
284+
}"""
285+
286+
interpreter.messages = [
287+
{"role": "assistant", "type": "code", "format": "python", "content": code}
288+
]
289+
for chunk in interpreter._respond_and_store():
290+
if chunk.get("format") == "output":
291+
assert chunk.get("content") == "22"
292+
break
293+
294+
code = """functions.execute({
295+
"language": "python",
296+
"code": "10+12"
297+
})"""
298+
299+
interpreter.messages = [
300+
{"role": "assistant", "type": "code", "format": "python", "content": code}
301+
]
302+
for chunk in interpreter._respond_and_store():
303+
if chunk.get("format") == "output":
304+
assert chunk.get("content") == "22"
305+
break
306+
307+
code = """{language: "python", code: "print('hello')" }"""
308+
309+
interpreter.messages = [
310+
{"role": "assistant", "type": "code", "format": "python", "content": code}
311+
]
312+
for chunk in interpreter._respond_and_store():
313+
if chunk.get("format") == "output":
314+
assert chunk.get("content").strip() == "hello"
315+
break
316+
317+
305318
@pytest.mark.skip(reason="Mac only")
306319
def test_sms():
307320
sms = interpreter.computer.sms

0 commit comments

Comments
 (0)