Skip to content

Commit 0df0997

Browse files
authored
Update CallOpenAI.py (#31)
* Add allow_truncated
1 parent 40d0365 commit 0df0997

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

patchwork/steps/CallOpenAI/CallOpenAI.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, inputs: dict):
2727
raise ValueError(f'Missing required data: "{self.required_keys}"')
2828

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

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

0 commit comments

Comments
 (0)