Skip to content

Commit

Permalink
bugfix: retry doesn't work when Claude API errors out (such as when o…
Browse files Browse the repository at this point in the history
…verloaded)
  • Loading branch information
GaiZhenbiao committed Mar 5, 2024
1 parent 5097de6 commit e2d069a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions modules/models/Claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ def get_answer_stream_iter(self):
system_prompt = self.system_prompt
history = self._get_claude_style_history()

with self.claude_client.messages.stream(
model=self.model_name,
max_tokens=self.max_generation_token,
messages=history,
system=system_prompt,
) as stream:
partial_text = ""
for text in stream.text_stream:
partial_text += text
yield partial_text
try:
with self.claude_client.messages.stream(
model=self.model_name,
max_tokens=self.max_generation_token,
messages=history,
system=system_prompt,
) as stream:
partial_text = ""
for text in stream.text_stream:
partial_text += text
yield partial_text
except Exception as e:
yield i18n(GENERAL_ERROR_MSG) + ": " + str(e)

def get_answer_at_once(self):
system_prompt = self.system_prompt
Expand Down

0 comments on commit e2d069a

Please sign in to comment.