Skip to content

Commit

Permalink
Print recoverable exceptions in mistral model wrapper.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 671273229
Change-Id: Ie346c3d7460d5b5fc3c8ced789ae175a5018794a
  • Loading branch information
jzleibo authored and copybara-github committed Sep 5, 2024
1 parent 46b06bb commit fec9bab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions concordia/language_model/mistral_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# At least one Mistral model supports completion mode.
COMPLETION_MODELS = (
'codestral-latest',
'codestral-2405',
)


Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(
self._text_model_name = model_name
self._measurements = measurements
self._channel = channel
self._client = mistralai.Mistral(api_key=api_key)
self._client = mistralai.Mistral(api_key=self._api_key)

self._choice_model_name = self._text_model_name
if use_codestral_for_choices:
Expand Down Expand Up @@ -109,7 +110,8 @@ def _complete_text(
stop=terminators,
random_seed=seed,
)
except mistralai.models.sdkerror.SDKError:
except mistralai.models.sdkerror.SDKError as err:
print(f' Exception: {err}')
continue
else:
result = response.choices[0].message.content
Expand Down Expand Up @@ -172,7 +174,8 @@ def _chat_text(
max_tokens=max_tokens,
random_seed=seed,
)
except mistralai.models.sdkerror.SDKError:
except mistralai.models.sdkerror.SDKError as err:
print(f' Exception: {err}')
continue
else:
return response.choices[0].message.content
Expand Down

0 comments on commit fec9bab

Please sign in to comment.