Skip to content

Commit

Permalink
wrapping embedding call inside try-exception block
Browse files Browse the repository at this point in the history
  • Loading branch information
PsicoThePato committed Aug 14, 2024
1 parent 057431b commit 3daeade
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/synthia/validator/text_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,20 @@ def _get_unit_euclid_distance(

def _score_miner(
self, miner_answer: str | None, embbeded_val_answer: list[float]
) -> float:
) -> float | None:
if not miner_answer:
return 0
embedded_miner_answer = self.embedder.get_embedding(miner_answer)
if isinstance(miner_answer, list):
# index 0 is sure to exist because of the if not miner_answer if
# huge gambiarra because of openrouter API giving weird responses
miner_answer = miner_answer[0]
try:
embedded_miner_answer = self.embedder.get_embedding(miner_answer)
except Exception as e:
log(f"WARN: Failed to embed miner answer: %20{miner_answer}%20")
print(e)
return None

normalized_distance = self._get_unit_euclid_distance(
embedded_miner_answer, embbeded_val_answer
)
Expand Down Expand Up @@ -412,7 +422,10 @@ async def validate_step(
log(f"Skipping miner {uid} that didn't answer")
continue
score = self._score_miner(
miner_answer, val_info.embedded_val_answer)
miner_answer, val_info.embedded_val_answer
)
if score is None:
continue
for answer in response_cache:
similarity = fuzz.ratio(answer, miner_answer) # type: ignore
response_cache.append(miner_answer)
Expand Down

0 comments on commit 3daeade

Please sign in to comment.