This commit is contained in:
Paul Gauthier 2023-06-21 18:50:06 -07:00
parent 1c53bff5ca
commit 1f8ce95dfa
2 changed files with 36 additions and 26 deletions

View file

@ -513,11 +513,6 @@ class Coder:
self.partial_response_function_call[k] += v self.partial_response_function_call[k] += v
else: else:
self.partial_response_function_call[k] = v self.partial_response_function_call[k] = v
# dump(self.partial_response_function_call)
args = self.partial_response_function_call.get("arguments")
args = parse_partial_args(args)
dump(args)
except AttributeError: except AttributeError:
pass pass
@ -533,10 +528,11 @@ class Coder:
if self.pretty: if self.pretty:
show_resp = self.modify_incremental_response() show_resp = self.modify_incremental_response()
md = Markdown( if show_resp:
show_resp, style=self.assistant_output_color, code_theme="default" md = Markdown(
) show_resp, style=self.assistant_output_color, code_theme="default"
live.update(md) )
live.update(md)
else: else:
sys.stdout.write(text) sys.stdout.write(text)
sys.stdout.flush() sys.stdout.flush()
@ -732,25 +728,29 @@ class Coder:
traceback.print_exc() traceback.print_exc()
return None, err return None, err
def parse_partial_args(self):
# dump(self.partial_response_function_call)
data = self.partial_response_function_call.get("arguments")
if not data:
return
try:
return json.loads(data)
except JSONDecodeError:
pass
try:
return json.loads(data + "}")
except JSONDecodeError:
pass
try:
return json.loads(data + '"}')
except JSONDecodeError:
pass
def check_model_availability(main_model): def check_model_availability(main_model):
available_models = openai.Model.list() available_models = openai.Model.list()
model_ids = [model.id for model in available_models["data"]] model_ids = [model.id for model in available_models["data"]]
return main_model.name in model_ids return main_model.name in model_ids
def parse_partial_args(data):
try:
return json.loads(data)
except JSONDecodeError:
pass
try:
return json.loads(data + "}")
except JSONDecodeError:
pass
try:
return json.loads(data + '"}')
except JSONDecodeError:
pass

View file

@ -1,3 +1,4 @@
import json
import os import os
from pathlib import Path from pathlib import Path
@ -48,6 +49,15 @@ class FunctionCoder(Coder):
self.cur_messages += [dict(role="assistant", content=content)] self.cur_messages += [dict(role="assistant", content=content)]
def modify_incremental_response(self): def modify_incremental_response(self):
args = self.parse_partial_args()
if not args:
return
args = json.dumps(args, indent=4)
return f"""
```js
{args}
```
"""
resp = self.partial_response_content resp = self.partial_response_content
return self.update_files(resp, mode="diff") return self.update_files(resp, mode="diff")