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 слични објави

Пребарај: #aiterminology

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

@ai_and_law · Post #786 · 17.03.2026 г., 08:04

🌐OECD Report Seeks Clear Terminology for AI Agents and Agentic AI The Organisation for Economic Co-operation and Development (OECD) has published a report examining the concepts of “AI agents” and “agentic AI” and the distinction between them. The report analyses how both terms are used in existing literature and evaluates their meaning through the lens of the OECD definition of an AI system. The study aims to establish more precise and consistent terminology around these concepts. By reviewing current academic and policy discussions, the report highlights differences in how the terms are applied and seeks to clarify their use in the context of AI governance and research. #AI#AIGovernance#AITerminology#AIRegulation#OECD

AI & Law

@ai_and_law · Post #167 · 17.11.2023 г., 08:04

EU and U.S. Release 65 Key AI Terms: Seeking Public Input Hello, dear subscribers! The European Union and the United States have unveiled 65 key AI terms crucial for comprehending risk-based AI approaches. As part of the Fourth EU-US Trade and Technology Council held in May 2023, the EU and U.S. have released essential AI terminology and taxonomy. The initiative aims to foster a shared understanding of risk management in the realm of Artificial Intelligence. Now, they are inviting public input. Comments on the completeness, relevance, and correctness of these definitions are encouraged. #AInews#EUUSTradeTech#AIterminology

AI & Law

@ai_and_law · Post #42 · 29.06.2023 г., 07:04

EU-US draft Terminology and Taxonomy for artificial intelligence released The Trade and Technology Council has published a significant document called the "Draft EU-US Terminology and Taxonomy for Artificial Intelligence." This publication marks a crucial milestone in establishing a common understanding of AI systems between the European Union and the United States. The identified terms in this draft reflect a shared understanding of the technical, socio-technical, and values-based aspects of AI. They are designed to lay the groundwork for future definitions and facilitate transatlantic collaboration on AI terminology and taxonomy. It's important to note that this list is preliminary and is expected to evolve further. In the coming months, experts and stakeholders will provide their input to expand and validate the terminology. This collaborative effort ensures a comprehensive and inclusive approach to defining AI concepts. #AITerminology#AITaxonomy#TransatlanticCooperation#AI#Law