From 44292898f561430a2b8d816b23bb4fbf72f7ad0d Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 28 Feb 2026 02:07:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D1=8B?= =?UTF-8?q?=20SDXL.=20=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai_agent.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ai_agent.py b/ai_agent.py index acc1c20..93f3992 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -17,8 +17,7 @@ from openrouter.errors import ResponseValidationError, ChatError from openrouter.utils import BackoffStrategy from fal_client import AsyncClient as FalClient - -import replicate +from replicate import Client as ReplicateClient from database import BasicDatabase @@ -29,6 +28,9 @@ GROUP_CHAT_MAX_MESSAGES = 20 PRIVATE_CHAT_MAX_MESSAGES = 40 MAX_OUTPUT_TOKENS = 500 +FAL_MODEL = "fal-ai/bytedance/seedream/v4.5/text-to-image" +REPLICATE_MODEL = "ultracoderru/nova-anime-xl-il-140:2af9bf809587d173212ddf9679d99f1d7f9a5442ed23c0c02e77d3a230865303" + @dataclass() class Message: @@ -102,7 +104,6 @@ class AiAgent: retry_connection_errors=True) self.db = db self.openrouter_model = openrouter_model - self.fal_model = "fal-ai/bytedance/seedream/v4.5/text-to-image" self.platform = platform self._load_prompts() @@ -111,7 +112,7 @@ class AiAgent: x_title=OPENROUTER_X_TITLE, http_referer=OPENROUTER_HTTP_REFERER, retry_config=retry_config) self.client_fal = FalClient(key=fal_token) - self.replicate_client = replicate.Client(api_token=replicate_token) + self.replicate_client = ReplicateClient(api_token=replicate_token) @dataclass() class _ToolsArtifacts: @@ -298,7 +299,7 @@ class AiAgent: } try: - result = await self.client_fal.run(self.fal_model, arguments=arguments) + result = await self.client_fal.run(FAL_MODEL, arguments=arguments) if "images" not in result: raise RuntimeError("Неожиданный ответ от сервера.") image_url = result["images"][0]["url"] @@ -354,17 +355,15 @@ class AiAgent: "negative_prompt": negative_prompt, "width": width, "height": height, - "cfg": 6, - "steps": 30, + "cfg": 4.5, + "steps": 20, "disable_safety_checker": True } try: - outputs = await self.replicate_client.async_run( - "ultracoderru/nova-anime-xl-il-140:2af9bf809587d173212ddf9679d99f1d7f9a5442ed23c0c02e77d3a230865303", - input=arguments) - + outputs = await self.replicate_client.async_run(REPLICATE_MODEL, input=arguments) image_bytes = await outputs[0].aread() + image = Image.open(BytesIO(image_bytes)).convert("RGB") output = BytesIO() image.save(output, format="JPEG", quality=80, optimize=True)