Skip to content

Commit 3bbd8f1

Browse files
committed
store execution results or error messages in conversation history to allow for easier back-reference, e.g. when asking 'Please fix the code'
1 parent 20e1afb commit 3bbd8f1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gpt_code_ui/webapp/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def append(self, role: str, content: str):
8383
def upload_file(self, filename: str, file_info: str = None):
8484
self.append("user", f"In the following, I will refer to the file {filename}.\n{file_info}")
8585

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.\nThe error message reads:\n{message}")
91+
8692
def __call__(self):
8793
return self._buffer
8894

@@ -213,6 +219,15 @@ def proxy_kernel_manager(path):
213219
else:
214220
resp = requests.get(f'http://localhost:{KERNEL_APP_PORT}/{path}')
215221

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+
216231
excluded_headers = ['content-encoding',
217232
'content-length', 'transfer-encoding', 'connection']
218233
headers = [(name, value) for (name, value) in resp.raw.headers.items()

0 commit comments

Comments
 (0)