@@ -5,13 +5,6 @@ from decimal import Decimal from io import BytesIO from typing import Any -from ml_model.exceptions import ( - RequestBlocked, - GenerationException, - ExceededContextLengthError, - ImageAnalysisError, -) - import filetype import requests from django.core.files import File @@ -23,8 +16,8 @@ from ml_model.tasks import replicate_run class Reve(SimpleService): PRICE = { - 'create': Decimal('7.5'), - 'edit-fast': Decimal('3') + 'create': Decimal('12.5'), + 'edit-fast': Decimal('5'), } @classmethod @@ -8,8 +8,8 @@ class SSEChunkService: return SSEChunk(event_id=event_id, event=event, data=data or {}) @classmethod - def start(cls, event_id: int, message_uuid: str) -> SSEChunk: - return cls._chunk(event_id, 'start', {'message_uuid': message_uuid}) + def start(cls, event_id: int, data: SSEData) -> SSEChunk: + return cls._chunk(event_id, 'start', data) @classmethod def token(cls, event_id: int, content: str) -> SSEChunk: @@ -14,13 +14,23 @@ from tools.chats.services.sse_store import PublicSSEStoreService, SSEStoreServic from tools.public_api.models import APIKey, APIStore -def _run_stream(store: SSEStoreService, message_uuid: str, service: StreamSimpleService, message): +def _run_stream( + store: SSEStoreService, + message_uuid: str, + service: StreamSimpleService, + message, + *, + file_url: str | None = None, +): stream = None event_id = 0 try: event_id += 1 - store.push(SSEChunkService.start(event_id, message_uuid)) + start_data = {'message_uuid': message_uuid} + if file_url: + start_data['file'] = file_url + store.push(SSEChunkService.start(event_id, start_data)) stream = service.make_stream(message) while True: @@ -52,7 +62,13 @@ def event_stream_task(chat_uuid: str, message_uuid: str, user_uuid: str) -> None service = chat.model.service(chat) - _run_stream(store, message_uuid, service, message) + _run_stream( + store, + message_uuid, + service, + message, + file_url=message.file.url if message.file else None, + ) @shared_task(soft_time_limit=570, time_limit=600)