Изменены параметры 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 openrouter.utils import BackoffStrategy
|
||||||
|
|
||||||
from fal_client import AsyncClient as FalClient
|
from fal_client import AsyncClient as FalClient
|
||||||
|
from replicate import Client as ReplicateClient
|
||||||
import replicate
|
|
||||||
|
|
||||||
from database import BasicDatabase
|
from database import BasicDatabase
|
||||||
|
|
||||||
|
|
@ -29,6 +28,9 @@ GROUP_CHAT_MAX_MESSAGES = 20
|
||||||
PRIVATE_CHAT_MAX_MESSAGES = 40
|
PRIVATE_CHAT_MAX_MESSAGES = 40
|
||||||
MAX_OUTPUT_TOKENS = 500
|
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()
|
@dataclass()
|
||||||
class Message:
|
class Message:
|
||||||
|
|
@ -102,7 +104,6 @@ class AiAgent:
|
||||||
retry_connection_errors=True)
|
retry_connection_errors=True)
|
||||||
self.db = db
|
self.db = db
|
||||||
self.openrouter_model = openrouter_model
|
self.openrouter_model = openrouter_model
|
||||||
self.fal_model = "fal-ai/bytedance/seedream/v4.5/text-to-image"
|
|
||||||
self.platform = platform
|
self.platform = platform
|
||||||
|
|
||||||
self._load_prompts()
|
self._load_prompts()
|
||||||
|
|
@ -111,7 +112,7 @@ class AiAgent:
|
||||||
x_title=OPENROUTER_X_TITLE, http_referer=OPENROUTER_HTTP_REFERER,
|
x_title=OPENROUTER_X_TITLE, http_referer=OPENROUTER_HTTP_REFERER,
|
||||||
retry_config=retry_config)
|
retry_config=retry_config)
|
||||||
self.client_fal = FalClient(key=fal_token)
|
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()
|
@dataclass()
|
||||||
class _ToolsArtifacts:
|
class _ToolsArtifacts:
|
||||||
|
|
@ -298,7 +299,7 @@ class AiAgent:
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
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:
|
if "images" not in result:
|
||||||
raise RuntimeError("Неожиданный ответ от сервера.")
|
raise RuntimeError("Неожиданный ответ от сервера.")
|
||||||
image_url = result["images"][0]["url"]
|
image_url = result["images"][0]["url"]
|
||||||
|
|
@ -354,17 +355,15 @@ class AiAgent:
|
||||||
"negative_prompt": negative_prompt,
|
"negative_prompt": negative_prompt,
|
||||||
"width": width,
|
"width": width,
|
||||||
"height": height,
|
"height": height,
|
||||||
"cfg": 6,
|
"cfg": 4.5,
|
||||||
"steps": 30,
|
"steps": 20,
|
||||||
"disable_safety_checker": True
|
"disable_safety_checker": True
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
outputs = await self.replicate_client.async_run(
|
outputs = await self.replicate_client.async_run(REPLICATE_MODEL, input=arguments)
|
||||||
"ultracoderru/nova-anime-xl-il-140:2af9bf809587d173212ddf9679d99f1d7f9a5442ed23c0c02e77d3a230865303",
|
|
||||||
input=arguments)
|
|
||||||
|
|
||||||
image_bytes = await outputs[0].aread()
|
image_bytes = await outputs[0].aread()
|
||||||
|
|
||||||
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
image.save(output, format="JPEG", quality=80, optimize=True)
|
image.save(output, format="JPEG", quality=80, optimize=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue