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

Пребарај: #copyrightlaws

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

@ai_and_law · Post #203 · 29.12.2023 г., 08:04

NY Times Takes On OpenAI and Microsoft Over Copyright Infringement Hello everybody! The New York Times has filed a lawsuit against OpenAI and Microsoft for alleged copyright infringement. This marks the first time a major American media organization has taken legal action against creators of prominent AI platforms, including ChatGPT. The lawsuit, filed in Federal District Court in Manhattan, claims that millions of articles from The Times were used without authorization to train automated chatbots, putting the media giant in direct competition with AI systems. The heart of the matter lies in the contention that the intellectual property of The New York Times was utilized to train AI models, specifically chatbots, that now serve as alternative sources of information. The lawsuit does not specify a monetary demand but emphasizes the responsibility of the defendants to be held accountable for "billions of dollars in statutory and actual damages." The legal action calls for the destruction of any chatbot models and training data incorporating copyrighted material from The Times. The lawsuit reveals that The Times initiated discussions with Microsoft and OpenAI in April to address concerns about the unauthorized use of its intellectual property. These talks, aimed at finding an amicable resolution, including a potential commercial agreement, did not result in a resolution. The legal battle could set a precedent for the legal boundaries surrounding generative AI technologies, particularly regarding the use of copyrighted materials. As concerns about the unlicensed use of intellectual property by AI systems grow, this case joins a series of legal actions within the tech industry. The outcome of such lawsuits may have far-reaching implications, not only for The New York Times but for the broader media landscape. #AILaw#NYTimes#OpenAI#Microsoft#ChatGPT#CopyrightLaws#AIEthics