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

Резултати

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

Пребарај: #axelspringer

当前筛选 #axelspringer清除筛选
AI & Law

@ai_and_law · Post #189 · 14.12.2023 г., 08:04

Axel Springer Partners with OpenAI for AI-Empowered Journalism Hello everyone! Global news giant Axel Springer has joined forces with OpenAI, the creators of the ChatGPT chatbot, in a landmark deal. This collaboration pioneers a novel approach to news delivery by integrating summaries of Axel Springer's content directly into ChatGPT's responses. When ChatGPT users inquire, the chatbot will provide concise summaries of pertinent news stories from Axel Springer's renowned publications, including Politico, Business Insider, Bild, and Welt. These summaries will encompass material that would typically require a subscription, enhancing user access to premium content. The summaries will promptly accompany the article's publication, ensuring real-time integration of breaking news into the user experience starting from the first quarter of 2024. The Axel Springer content will enjoy a prominent position in ChatGPT search results, aiming to drive increased traffic and subscription revenue to Axel Springer brands. While specific financial terms remain undisclosed, OpenAI commits to paying for the Axel Springer content utilized in training its large language models, covering both current and archived materials. The multi-year, non-exclusive agreement underscores the mutual exploration of AI's opportunities in advancing journalism's quality, societal relevance, and business models. This partnership marks OpenAI's second collaboration with a major news publisher, following the agreement with the Associated Press. As the media landscape navigates copyright concerns, these partnerships illustrate a cooperative approach between AI innovators and publishers to address content usage, access, and AI training data concerns. #AIandMedia#AxelSpringer#OpenAI#ChatGPT#AIJournalism#NewsCollaboration