stop infinite calling of non-existent python func
This commit is contained in:
parent
033d94fd4c
commit
4901760d70
4 changed files with 11 additions and 3 deletions
|
|
@ -33,7 +33,7 @@ def get_error_title(e: Exception) -> str:
|
|||
return "The request to OpenAI failed. Please try again."
|
||||
elif isinstance(e, openai_errors.APIConnectionError):
|
||||
return "The request failed. Please check your internet connection and try again."
|
||||
return e.__repr__()
|
||||
return e.__str__() or e.__repr__()
|
||||
|
||||
|
||||
class Autopilot(ContinueBaseModel):
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ class ContinueSDK(AbstractContinueSDK):
|
|||
for rif in highlighted_code:
|
||||
code = await self.ide.readRangeInFile(rif)
|
||||
msg = ChatMessage(content=f"{preface} ({rif.filepath}):\n```\n{code}\n```",
|
||||
role="user", summary=f"{preface}: {rif.filepath}")
|
||||
role="system", summary=f"{preface}: {rif.filepath}")
|
||||
|
||||
# Don't insert after latest user message or function call
|
||||
i = -1
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class GetUserSecretResponse(BaseModel):
|
|||
|
||||
|
||||
class RunCommandResponse(BaseModel):
|
||||
output: str
|
||||
output: str = ""
|
||||
|
||||
|
||||
class UniqueIdResponse(BaseModel):
|
||||
|
|
|
|||
|
|
@ -152,6 +152,8 @@ class ChatWithFunctions(Step):
|
|||
))
|
||||
|
||||
last_function_called_index_in_history = None
|
||||
# GPT keeps wanting to call the non-existent 'python' function repeatedly, so limiting to once
|
||||
already_called_python = False
|
||||
while True:
|
||||
was_function_called = False
|
||||
func_args = ""
|
||||
|
|
@ -195,6 +197,9 @@ class ChatWithFunctions(Step):
|
|||
break
|
||||
else:
|
||||
if func_name == "python" and "python" not in step_name_step_class_map:
|
||||
if already_called_python:
|
||||
return
|
||||
already_called_python = True
|
||||
# GPT must be fine-tuned to believe this exists, but it doesn't always
|
||||
func_name = "EditHighlightedCodeStep"
|
||||
func_args = json.dumps({"user_input": self.user_input})
|
||||
|
|
@ -231,6 +236,9 @@ class ChatWithFunctions(Step):
|
|||
summary=f"Called function {func_name}"
|
||||
))
|
||||
last_function_called_index_in_history = sdk.history.current_index + 1
|
||||
if func_name not in step_name_step_class_map:
|
||||
raise Exception(
|
||||
f"The model tried to call a function ({func_name}) that does not exist. Please try again.")
|
||||
step_to_run = step_name_step_class_map[func_name](
|
||||
**fn_call_params)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue