br413 commented on code in PR #70184: URL: https://github.com/apache/airflow/pull/70184#discussion_r3623024173
########## providers/common/ai/src/airflow/providers/common/ai/triggers/llm.py: ########## @@ -0,0 +1,112 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from collections.abc import AsyncIterator +from typing import Any + +from airflow.providers.common.ai.hooks.pydantic_ai import PydanticAIHook +from airflow.providers.common.ai.utils.logging import log_run_summary +from airflow.providers.common.ai.utils.output_type import ( + deserialize_output_type, + serialize_llm_output, +) +from airflow.triggers.base import BaseTrigger, TriggerEvent + + +def serialize_usage_limits(usage_limits: Any | None) -> dict[str, Any] | None: + """Serialize pydantic-ai ``UsageLimits`` for trigger persistence.""" + if usage_limits is None: + return None + return usage_limits.model_dump(exclude_defaults=True) + + +def deserialize_usage_limits(data: dict[str, Any] | None) -> Any | None: + """Restore pydantic-ai ``UsageLimits`` from trigger persistence.""" + if data is None: + return None + from pydantic_ai.usage import UsageLimits Review Comment: Good catch — there was no need for a lazy import here. pydantic-ai is already a provider dependency, so I moved UsageLimits to the module level in 061ad47. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
