Skip to content

Commit

Permalink
Update CallOpenAI.py (#31)
Browse files Browse the repository at this point in the history
* Add allow_truncated
  • Loading branch information
codelion authored Apr 16, 2024
1 parent 40d0365 commit 0df0997
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions patchwork/steps/CallOpenAI/CallOpenAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, inputs: dict):
raise ValueError(f'Missing required data: "{self.required_keys}"')

self.model = inputs["model"]
self.allow_trunctated = inputs.get("allow_truncated", False)
self.model_args = {key[len("model_") :]: value for key, value in inputs.items() if key.startswith("model_")}
self.client_args = {key[len("client_") :]: value for key, value in inputs.items() if key.startswith("client_")}

Expand Down Expand Up @@ -81,8 +82,11 @@ def run(self) -> dict:
logger.error(f"No response choice given")
contents.append("")
elif completion.choices[0].finish_reason == "length":
logger.error(f"Response truncated because of finish reason = length")
contents.append("")
if self.allow_trunctated:
contents.append(completion.choices[0].message.content)
else:
logger.error(f"Response truncated because of finish reason = length. Use --allow_truncated option to process truncated responses.")
contents.append("")
else:
logger.debug(f"Response received: \n{indent(completion.choices[0].message.content, ' ')}")
contents.append(completion.choices[0].message.content)
Expand Down

0 comments on commit 0df0997

Please sign in to comment.