@@ -88,8 +88,10 @@ async def test_fastapi_server():
88
88
while True :
89
89
message = await websocket .recv ()
90
90
message_data = json .loads (message )
91
+ if "error" in message_data :
92
+ raise Exception (message_data ["content" ])
91
93
print ("Received from WebSocket:" , message_data )
92
- if message_data .get ("content" ):
94
+ if type ( message_data .get ("content" )) == str :
93
95
accumulated_content += message_data .get ("content" )
94
96
if message_data == {
95
97
"role" : "server" ,
@@ -142,6 +144,8 @@ async def test_fastapi_server():
142
144
while True :
143
145
message = await websocket .recv ()
144
146
message_data = json .loads (message )
147
+ if "error" in message_data :
148
+ raise Exception (message_data ["content" ])
145
149
print ("Received from WebSocket:" , message_data )
146
150
if message_data .get ("content" ):
147
151
accumulated_content += message_data .get ("content" )
@@ -189,6 +193,8 @@ async def test_fastapi_server():
189
193
while True :
190
194
message = await websocket .recv ()
191
195
message_data = json .loads (message )
196
+ if "error" in message_data :
197
+ raise Exception (message_data ["content" ])
192
198
print ("Received from WebSocket:" , message_data )
193
199
if message_data .get ("content" ):
194
200
accumulated_content += message_data .get ("content" )
@@ -237,6 +243,8 @@ async def test_fastapi_server():
237
243
while True :
238
244
message = await websocket .recv ()
239
245
message_data = json .loads (message )
246
+ if "error" in message_data :
247
+ raise Exception (message_data ["content" ])
240
248
print ("Received from WebSocket:" , message_data )
241
249
if message_data .get ("content" ):
242
250
if type (message_data .get ("content" )) == str :
@@ -251,6 +259,88 @@ async def test_fastapi_server():
251
259
252
260
assert "18893094989" in accumulated_content .replace ("," , "" )
253
261
262
+ #### TEST FILE ####
263
+
264
+ # Send another POST request
265
+ post_url = "http://localhost:8000/settings"
266
+ settings = {"messages" : [], "auto_run" : True }
267
+ response = requests .post (post_url , json = settings )
268
+ print ("POST request sent, response:" , response .json ())
269
+
270
+ # Sending messages via WebSocket
271
+ await websocket .send (json .dumps ({"role" : "user" , "start" : True }))
272
+ print ("sent" , json .dumps ({"role" : "user" , "start" : True }))
273
+ await websocket .send (
274
+ json .dumps (
275
+ {
276
+ "role" : "user" ,
277
+ "type" : "message" ,
278
+ "content" : "Does this file exist?" ,
279
+ }
280
+ )
281
+ )
282
+ print (
283
+ "sent" ,
284
+ {
285
+ "role" : "user" ,
286
+ "type" : "message" ,
287
+ "content" : "Does this file exist?" ,
288
+ },
289
+ )
290
+ await websocket .send (
291
+ json .dumps (
292
+ {
293
+ "role" : "user" ,
294
+ "type" : "file" ,
295
+ "format" : "path" ,
296
+ "content" : "/something.txt" ,
297
+ }
298
+ )
299
+ )
300
+ print (
301
+ "sent" ,
302
+ {
303
+ "role" : "user" ,
304
+ "type" : "file" ,
305
+ "format" : "path" ,
306
+ "content" : "/something.txt" ,
307
+ },
308
+ )
309
+ await websocket .send (json .dumps ({"role" : "user" , "end" : True }))
310
+ print ("WebSocket chunks sent" )
311
+
312
+ # Wait for response
313
+ accumulated_content = ""
314
+ while True :
315
+ message = await websocket .recv ()
316
+ message_data = json .loads (message )
317
+ if "error" in message_data :
318
+ raise Exception (message_data ["content" ])
319
+ print ("Received from WebSocket:" , message_data )
320
+ if type (message_data .get ("content" )) == str :
321
+ accumulated_content += message_data .get ("content" )
322
+ if message_data == {
323
+ "role" : "server" ,
324
+ "type" : "status" ,
325
+ "content" : "complete" ,
326
+ }:
327
+ print ("Received expected message from server" )
328
+ break
329
+
330
+ # Get messages
331
+ get_url = "http://localhost:8000/settings/messages"
332
+ response_json = requests .get (get_url ).json ()
333
+ print ("GET request sent, response:" , response_json )
334
+ if isinstance (response_json , str ):
335
+ response_json = json .loads (response_json )
336
+ messages = response_json ["messages" ]
337
+
338
+ response = async_interpreter .computer .ai .chat (
339
+ str (messages )
340
+ + "\n \n In the conversation above, does the assistant think the file exists? Yes or no? Only reply with one word— 'yes' or 'no'."
341
+ )
342
+ assert response .strip (" \n ." ).lower () == "no"
343
+
254
344
# Sending POST request to /run endpoint with code to kill a thread in Python
255
345
# actually wait i dont think this will work..? will just kill the python interpreter
256
346
post_url = "http://localhost:8000/run"
0 commit comments