Skip to content

Commit

Permalink
Improve info printed on error in the together_ai model wrapper.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675060263
Change-Id: Id04b343c49c9c186d1177141b58bef52486cb5c4
  • Loading branch information
jzleibo authored and copybara-github committed Sep 16, 2024
1 parent 9ddfb21 commit dc06b41
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions concordia/language_model/together_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def sample_choice(
) -> tuple[int, str, dict[str, float]]:

def _sample_choice(response: str) -> float:
augmented_prompt = prompt + response
messages = [
{
'role': 'system',
Expand All @@ -176,7 +177,7 @@ def _sample_choice(response: str) -> float:
),
},
{'role': 'assistant', 'content': 'sleeping.'},
{'role': 'user', 'content': prompt + response},
{'role': 'user', 'content': augmented_prompt},
]

result = None
Expand All @@ -198,14 +199,16 @@ def _sample_choice(response: str) -> float:
except together.error.RateLimitError as err:
if attempts >= _NUM_SILENT_ATTEMPTS:
print(f' Exception: {err}')
print(f' Exception prompt: {augmented_prompt}')
continue
else:
break

if result:
lp = sum(result.choices[0].logprobs.token_logprobs)
else:
raise ValueError('Failed to get logprobs.')
raise ValueError(
f'Failed to get logprobs.\nException prompt: {augmented_prompt}')

return lp

Expand Down

0 comments on commit dc06b41

Please sign in to comment.