текущая версия (рабочая)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
from app.models.review import Review
|
||||
from app.models.settings import Settings
|
||||
|
||||
__all__ = ["Settings", "Review"]
|
||||
@@ -0,0 +1,30 @@
|
||||
from tortoise import Model, fields
|
||||
|
||||
|
||||
class Review(Model):
|
||||
id = fields.IntField(pk=True)
|
||||
external_id = fields.TextField()
|
||||
platform = fields.TextField() # "ozon" or "wb"
|
||||
rating = fields.IntField()
|
||||
is_good = fields.BooleanField()
|
||||
text = fields.TextField()
|
||||
published_at = fields.DatetimeField()
|
||||
|
||||
product_id = fields.TextField()
|
||||
product_name = fields.TextField()
|
||||
product_category = fields.TextField()
|
||||
product_subcategory = fields.TextField()
|
||||
|
||||
tone = fields.TextField(null=True) # positive, neutral, negative
|
||||
tone_reason = fields.TextField(null=True)
|
||||
is_critical = fields.BooleanField(null=True)
|
||||
|
||||
response_text = fields.TextField(null=True)
|
||||
response_id = fields.TextField(null=True)
|
||||
responded_at = fields.DatetimeField(null=True)
|
||||
|
||||
chat_id = fields.IntField(null=True)
|
||||
message_id = fields.IntField(null=True)
|
||||
images = fields.JSONField(null=True) # Store image URLs as JSON array
|
||||
# WB: теги отзыва из API (bables), например ["цена"]
|
||||
bables = fields.JSONField(null=True)
|
||||
@@ -0,0 +1,36 @@
|
||||
from tortoise import Model, fields
|
||||
|
||||
from app.config import ANALYSIS_PROMPT, ANSWER_PROMPT, GOOD_REVIEWS_THREAD_ID
|
||||
from app.models import Review
|
||||
|
||||
|
||||
class Settings(Model):
|
||||
id = fields.IntField(pk=True)
|
||||
is_good = fields.BooleanField(unique=True)
|
||||
|
||||
analysis_prompt = fields.TextField(default=ANALYSIS_PROMPT)
|
||||
analysis_enabled = fields.BooleanField(default=False)
|
||||
|
||||
answer_prompt = fields.TextField(default=ANSWER_PROMPT)
|
||||
auto_response_enabled = fields.BooleanField(default=False) # автоответ на отзывы с текстом (GPT)
|
||||
auto_response_empty_enabled = fields.BooleanField(default=False) # автоответ на отзывы без текста (шаблон)
|
||||
|
||||
# Шаблоны ответа на отзывы без текста (редактируются из бота)
|
||||
template_empty_low_rating = fields.TextField(null=True)
|
||||
template_empty_high_rating = fields.TextField(null=True)
|
||||
|
||||
gpt_model = fields.CharField(max_length=20, default="gpt-4o-mini")
|
||||
max_tokens = fields.IntField(default=100)
|
||||
|
||||
@classmethod
|
||||
async def get_from_context(
|
||||
cls, *, review: Review | None = None, message_thread_id: int | None = None
|
||||
) -> "Settings":
|
||||
if review is not None:
|
||||
is_good = review.is_good
|
||||
elif message_thread_id is not None:
|
||||
is_good = message_thread_id == GOOD_REVIEWS_THREAD_ID
|
||||
else:
|
||||
raise ValueError("Either review or message_thread_id must be provided")
|
||||
|
||||
return await cls.get(is_good=is_good)
|
||||
Reference in New Issue
Block a user