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
else:
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:
pass
@ -533,6 +528,7 @@ class Coder:
if self.pretty:
show_resp = self.modify_incremental_response()
if show_resp:
md = Markdown(
show_resp, style=self.assistant_output_color, code_theme="default"
)
@ -732,14 +728,12 @@ class Coder:
traceback.print_exc()
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
def check_model_availability(main_model):
available_models = openai.Model.list()
model_ids = [model.id for model in available_models["data"]]
return main_model.name in model_ids
def parse_partial_args(data):
try:
return json.loads(data)
except JSONDecodeError:
@ -754,3 +748,9 @@ def parse_partial_args(data):
return json.loads(data + '"}')
except JSONDecodeError:
pass
def check_model_availability(main_model):
available_models = openai.Model.list()
model_ids = [model.id for model in available_models["data"]]
return main_model.name in model_ids

View file

@ -1,3 +1,4 @@
import json
import os
from pathlib import Path
@ -48,6 +49,15 @@ class FunctionCoder(Coder):
self.cur_messages += [dict(role="assistant", content=content)]
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
return self.update_files(resp, mode="diff")