Изменены параметры SDXL.
Немного рефакторинга.
This commit is contained in:
parent
a1b379beda
commit
44292898f5
1 changed files with 10 additions and 11 deletions
21
ai_agent.py
21
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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue