@@ -83,6 +83,12 @@ def append(self, role: str, content: str):
83
83
def upload_file (self , filename : str , file_info : str = None ):
84
84
self .append ("user" , f"In the following, I will refer to the file { filename } .\n { file_info } " )
85
85
86
+ def add_execution_result (self , result : str ):
87
+ self .append ("user" , f"Executing this code yielded the following output:\n { result } " )
88
+
89
+ def add_error (self , message : str ):
90
+ self .append ("user" , f"Executing this code lead to an error.\n The error message reads:\n { message } " )
91
+
86
92
def __call__ (self ):
87
93
return self ._buffer
88
94
@@ -213,6 +219,15 @@ def proxy_kernel_manager(path):
213
219
else :
214
220
resp = requests .get (f'http://localhost:{ KERNEL_APP_PORT } /{ path } ' )
215
221
222
+ # store execution results in conversation history to allow back-references by the user
223
+ for res in json .loads (resp .content ).get ('results' , []):
224
+ if res ['type' ] == "message" :
225
+ chat_history .add_execution_result (res ['value' ])
226
+ elif res ['type' ] == "message_error" :
227
+ chat_history .add_error (res ['value' ])
228
+
229
+ print (res )
230
+
216
231
excluded_headers = ['content-encoding' ,
217
232
'content-length' , 'transfer-encoding' , 'connection' ]
218
233
headers = [(name , value ) for (name , value ) in resp .raw .headers .items ()
0 commit comments