Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect detection of generation failure #66

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Writer/Interface/Wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def SafeGenerateText(

# Strip Empty Messages
for i in range(len(_Messages) - 1, 0, -1):
if _Messages[i]["content"] == "":
if _Messages[i]["content"].strip() == "":
del _Messages[i]

NewMsg = self.ChatAndStreamResponse(_Logger, _Messages, _Model, _SeedOverride, _Format)

while (self.GetLastMessageText(NewMsg).isspace()) or (len(self.GetLastMessageText(NewMsg).split(" ")) < _MinWordCount):
if self.GetLastMessageText(NewMsg).isspace():
while (self.GetLastMessageText(NewMsg).strip() == "") or (len(self.GetLastMessageText(NewMsg).split(" ")) < _MinWordCount):
if self.GetLastMessageText(NewMsg).strip() == "":
_Logger.Log("SafeGenerateText: Generation Failed Due To Empty (Whitespace) Response, Reattempting Output", 7)
elif (len(self.GetLastMessageText(NewMsg).split(" ")) < _MinWordCount):
_Logger.Log(f"SafeGenerateText: Generation Failed Due To Short Response ({len(self.GetLastMessageText(NewMsg).split(' '))}, min is {_MinWordCount}), Reattempting Output", 7)
Expand Down Expand Up @@ -385,7 +385,7 @@ def ChatAndStreamResponse(
4,
)
# Check if the response is empty and attempt regeneration if necessary
if _Messages[-1]["content"].isspace():
if _Messages[-1]["content"].strip() == "":
_Logger.Log("Model Returned Only Whitespace, Attempting Regeneration", 6)
_Messages.append(
self.BuildUserQuery(
Expand Down