TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 3 слични објави

Пребарај: #fastai

当前筛选 #fastai清除筛选
ChatGPT AI Technology News

@chatgpt_officialnews · Post #49 · 19.03.2025 г., 14:59

🚀Say Hello to GPT-O3 Mini – Small but Mighty!🧠💡 Need a lightweight AI that’s still smart? GPT-O3 Mini is your go-to choice! ⚡️🎯 ✨What makes it great? 🟢 Super Fast – Perfect for quick chats & short tasks! 🟢 Energy Efficient – Uses minimal resources but delivers big! 🟢 Great for Simple Tasks – Ask questions, get answers, and enjoy AI on the go! 💡How to use it? Simply type: 🔹 /model – Select GPT-O3 Mini for a fast & smooth AI experience! 🔹 Need help? @OpenAI_helpdesk 🔹 Join the discussion: https://t.me/chatgpt_officialchat 🔥 Try GPT-O3 Mini now and enjoy AI in its lightest form! ➖➖➖➖🔻 💎@Chatgpt_OfficialNews – Stay Updated! ⚡️ 🧠 BOT: @Chatgpt_OfficialBOT #️⃣#GPT#GPT-O3Mini #FastAI#LightweightAI#SmartTech ➖➖➖➖🔺

ChatGPT AI Technology News

@chatgpt_officialnews · Post #48 · 18.03.2025 г., 15:59

🚀 Meet GPT-O1 – The Fast & Reliable AI! 🤖 ⚡️ Looking for a quick, efficient AI for everyday tasks? GPT-O1 is here to help! 🧠💡 ✨What can it do? ✅ Fast & Lightweight – Get instant answers without delays! ✅ Smart & Efficient – Perfect for casual chats, summaries, and quick responses. ✅ Low-latency AI – Works seamlessly even on lower-end devices. 💡How to use it? Simply type: 🔹 /model – Select GPT-O1 for speed & efficiency! 🔹 Need help? @OpenAI_helpdesk 🔹 Join the discussion: https://t.me/chatgpt_officialchat 🔥 Try GPT-O1 now and experience smooth AI interactions! ➖➖➖➖🔻 💎@Chatgpt_OfficialNews – Stay Updated! ⚡️ 🧠 BOT: @Chatgpt_OfficialBOT #️⃣#GPT#GPT-O1 #FastAI#SmartChat#AI#NextGen ➖➖➖➖🔺

ChatGPT AI Technology News

@chatgpt_officialnews · Post #50 · 20.03.2025 г., 04:36

📱Google:"Hey guys, wait for us! We have an AI chatbot too… it’s just not ready yet!" 📱GPT-4 gang:Silence. Judging. Side-eyes. 📱GPT-4 gang:Unanimous rejection with the ultimate thumbs-down 📱Google:Left standing like a kid who brought a calculator to a sword fight AI wars are brutal—either you launch big or get left behind! 📇Share ➖➖➖➖🔻 💎@Chatgpt_OfficialNews – Stay Updated! ⚡️ 🧠 BOT: @Chatgpt_OfficialBOT #️⃣#GPT#Fun#FastAI#SmartTech#Meme#Joke ➖➖➖➖🔺