product dynanmic serializer

This commit is contained in:
Parsa Nazer
2025-02-02 03:16:12 +03:30
parent 94de307d56
commit abddb1bdc1
5 changed files with 67 additions and 28 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ from product.models import ProductModel, DollorModel
from django.conf import settings
import openai
from time import sleep
from product.serializers import ProductChatSerializer
from product.serializers import DynamicProductSerializer
ASSISTANT_ID = 'asst_1wOnCKncEHkOfp0FjOIz4Xkp'
@@ -26,7 +26,7 @@ class ProductChatModel(models.Model):
client = openai.OpenAI(api_key=settings.OPENAI_API_KEY)
dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique')
dollor_price = dollor_object.price
product_json = ProductChatSerializer(instance=self.product, context={'dollor_price': dollor_price}).data
product_json = DynamicProductSerializer(instance=self.product, context={'dollor_price': dollor_price, 'view_type': 'chat'}).data
try:
thread = client.beta.threads.create(