11import os
22import platform
3+ import signal
34import time
45from random import randint
56
2223from 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")
6627def 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" )
306319def test_sms ():
307320 sms = interpreter .computer .sms
0 commit comments