Skip to content

chore: use union syntax over pipe syntax for older python version #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions agntcy_iomapper/base/agent_iomapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import re
from abc import abstractmethod
from typing import ClassVar
from typing import ClassVar, Optional, Union

import jsonschema
from jinja2 import Environment
Expand All @@ -22,7 +22,7 @@


class AgentIOMapperInput(BaseIOMapperInput):
message_template: str | None = Field(
message_template: Union[str, None] = Field(
max_length=4096,
default=None,
description="Message (user) to send to LLM to effect translation.",
Expand Down Expand Up @@ -52,9 +52,9 @@ class AgentIOMapper(BaseIOMapper):

def __init__(
self,
config: AgentIOMapperConfig | None = None,
jinja_env: Environment | None = None,
jinja_env_async: Environment | None = None,
config: Optional[AgentIOMapperConfig] = None,
jinja_env: Optional[Environment] = None,
jinja_env_async: Optional[Environment] = None,
):
if config is None:
config = AgentIOMapperConfig()
Expand Down
10 changes: 5 additions & 5 deletions agntcy_iomapper/base/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, Union, Optional

from openapi_pydantic import Schema
from pydantic import BaseModel, Field, model_validator
Expand All @@ -14,13 +14,13 @@ class ArgumentsDescription(BaseModel):
the details necessary to perfom io mapping between two agents
"""

json_schema: Schema | None = Field(
json_schema: Optional[Schema] = Field(
default=None, description="Data format JSON schema"
)
description: str | None = Field(
description: Optional[str] = Field(
default=None, description="Data (semantic) natural language description"
)
agent_manifest: dict[str, Any] | None = Field(
agent_manifest: Optional[dict[str, Any]] = Field(
default=None,
description="Agent Manifest definition as per https://agntcy.github.io/acp-spec/openapi.html#model/agentmanifest",
)
Expand Down Expand Up @@ -89,7 +89,7 @@ class BaseIOMapper(ABC):

def __init__(
self,
config: BaseIOMapperConfig | None = None,
config: Optional[BaseIOMapperConfig] = None,
):
self.config = config if config is not None else BaseIOMapperConfig()

Expand Down
2 changes: 0 additions & 2 deletions agntcy_iomapper/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def resolve_ref(ref, current_defs):

def _refine_schema(schema, paths):
filtered_schema = {}
print(f"{paths}-{schema}")

for path in paths:
path_parts = path.split(".")
Expand Down Expand Up @@ -153,7 +152,6 @@ def _refine_schema(schema, paths):
properties = _filter_properties(
root_schema, curr_properties, path_parts[1:]
)
print(f" after {paths}-{filtered_schema}")
return filtered_schema


Expand Down
6 changes: 6 additions & 0 deletions agntcy_iomapper/imperative/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
ImperativeIOMapperInput,
ImperativeIOMapperOutput,
)

__all__ = [
"ImperativeIOMapper",
"ImperativeIOMapperInput",
"ImperativeIOMapperOutput",
]
12 changes: 7 additions & 5 deletions agntcy_iomapper/imperative/imperative.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import json
import logging
from typing import Any, Callable, Union
from typing import Any, Callable, Optional, Union

import jsonschema
from jsonpath_ng.ext import parse
Expand All @@ -44,13 +44,15 @@ class ImperativeIOMapper(BaseIOMapper):

def __init__(
self,
field_mapping: dict[str, Union[str, Callable]] | None,
config: BaseIOMapperConfig | None = None,
field_mapping: Optional[dict[str, Union[str, Callable]]],
config: Optional[BaseIOMapperConfig] = None,
) -> None:
super().__init__(config)
self.field_mapping = field_mapping

def invoke(self, input: ImperativeIOMapperInput) -> ImperativeIOMapperOutput | None:
def invoke(
self, input: ImperativeIOMapperInput
) -> Optional[ImperativeIOMapperOutput]:
if input.data is None:
return None
if self.field_mapping is None:
Expand All @@ -61,7 +63,7 @@ def invoke(self, input: ImperativeIOMapperInput) -> ImperativeIOMapperOutput | N

def ainvoke(
self, input: ImperativeIOMapperInput
) -> ImperativeIOMapperOutput | None:
) -> Optional[ImperativeIOMapperOutput]:
return self.invoke(input)

def _imperative_map(self, input_definition: ImperativeIOMapperInput) -> Any:
Expand Down
12 changes: 6 additions & 6 deletions agntcy_iomapper/langgraph/langgraph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
import logging
from typing import Any
from typing import Any, Optional, Union

from langchain.chat_models import init_chat_model
from langchain_core.language_models import BaseChatModel
Expand All @@ -23,7 +23,7 @@


class LangGraphIOMapperConfig(AgentIOMapperConfig):
llm: BaseChatModel | str = (
llm: Union[BaseChatModel, str] = (
Field(
...,
description="Model to use for translation as LangChain description or model class.",
Expand All @@ -34,7 +34,7 @@ class LangGraphIOMapperConfig(AgentIOMapperConfig):
class _LangGraphAgentIOMapper(AgentIOMapper):
def __init__(
self,
config: LangGraphIOMapperConfig | None = None,
config: Optional[LangGraphIOMapperConfig] = None,
**kwargs,
):
if config is None:
Expand All @@ -50,7 +50,7 @@ def _invoke(
input: LangGraphIOMapperInput,
messages: list[dict[str, str]],
*,
config: RunnableConfig | None = None,
config: Optional[RunnableConfig] = None,
**kwargs,
) -> str:
response = self.llm.invoke(messages, config, **kwargs)
Expand All @@ -61,7 +61,7 @@ async def _ainvoke(
input: LangGraphIOMapperOutput,
messages: list[dict[str, str]],
*,
config: RunnableConfig | None = None,
config: Optional[RunnableConfig] = None,
**kwargs,
) -> str:
response = await self.llm.ainvoke(messages, config, **kwargs)
Expand All @@ -72,7 +72,7 @@ class LangGraphIOMapper:
def __init__(
self,
config: LangGraphIOMapperConfig,
input: LangGraphIOMapperInput | None = None,
input: Optional[LangGraphIOMapperInput] = None,
):
self._iomapper = _LangGraphAgentIOMapper(config)
self._input = input
Expand Down
4 changes: 2 additions & 2 deletions agntcy_iomapper/llamaindex/llamaindex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0"
import logging
from typing import Any
from typing import Any, Optional

from llama_index.core.base.llms.base import BaseLLM
from llama_index.core.llms import ChatMessage
Expand All @@ -24,7 +24,7 @@ class LLamaIndexIOMapperConfig(AgentIOMapperConfig):
class _LLmaIndexAgentIOMapper(AgentIOMapper):
def __init__(
self,
config: LLamaIndexIOMapperConfig | None = None,
config: Optional[LLamaIndexIOMapperConfig] = None,
**kwargs,
):
if config is None:
Expand Down
8 changes: 4 additions & 4 deletions agntcy_iomapper/pydantic_ai.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
import logging
from typing import Any, Literal, TypedDict
from typing import Any, Literal, Optional, TypedDict

from openai import AsyncAzureOpenAI
from pydantic import Field, model_validator
Expand Down Expand Up @@ -49,11 +49,11 @@ class AgentModelSettings(TypedDict, total=False):


class PydanticAIAgentIOMapperInput(AgentIOMapperInput):
model_settings: AgentModelSettings | None = Field(
model_settings: Optional[AgentModelSettings] = Field(
default=None,
description="Specific arguments for LLM transformation.",
)
model: str | None = Field(
model: Optional[str] = Field(
default=None,
description="Specific model out of those configured to handle request.",
)
Expand All @@ -67,7 +67,7 @@ class PydanticAIAgentIOMapperConfig(AgentIOMapperConfig):
default={"azure:gpt-4o-mini": AgentIOModelArgs()},
description="LLM configuration to use for translation",
)
default_model: str | None = Field(
default_model: Optional[str] = Field(
default="azure:gpt-4o-mini",
description="Default arguments to LLM completion function by configured model.",
)
Expand Down