@@ -18,7 +18,7 @@ from deepl.translator import TextResult from requests import Response from backend import settings -from ml_model.exceptions import DeploymentDisabled, ModelTimeoutError +from ml_model.exceptions import DeploymentDisabled, ModelTimeoutError, GenerationException from ml_model.utils import count_openrouter_tokens from poller.models import Proxy @@ -115,7 +115,14 @@ def openrouter_run(version: str, messages: list, callback_data: dict, model_name json={'model': version, 'messages': messages, 'transforms': ['middle-out'], **callback_data}, ) if (data := resp.json()) and data.get('choices'): - content = ','.join(choice['message']['content'] for choice in data.get('choices')) + raw_content = [ + c['message']['content'] + for c in data.get('choices', []) + if c.get('message') and c['message'].get('content') is not None + ] + if not raw_content: + raise GenerationException + content = ','.join(raw_content) reasoning = ','.join( reasoning for choice in data.get('choices', [])