Skip to content

Commit

Permalink
Merge branch 'scoring-timeout' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jstray committed Oct 25, 2024
2 parents 18d3de1 + 0685338 commit 6eed21d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions perspective_ranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,14 @@ async def score(self, attributes, statement, statement_id):

try:
start_time = time.time()
response_json = None
for _ in range(0,3):
try:
response = await self.client.post(
url=PERSPECTIVE_URL, json=data, headers=headers, timeout=self.scoring_timeout
)
response.raise_for_status()
response_json = await response.json()
except asyncio.TimeoutError:
scoring_timeouts.inc()
logger.warning(
Expand All @@ -235,12 +238,9 @@ async def score(self, attributes, statement, statement_id):
latency = time.time() - start_time
scoring_latency.observe(latency)

if not response:
if not response_json:
raise HTTPException(status_code=status.HTTP_504_GATEWAY_TIMEOUT, detail=f"Gave up after 3 timeouts while scoring statement_id {statement_id}")

response.raise_for_status()
response_json = await response.json()

results = []
scorable = True
for attr in attributes:
Expand Down

0 comments on commit 6eed21d

Please sign in to comment.