xintongsong commented on code in PR #70: URL: https://github.com/apache/flink-agents/pull/70#discussion_r2212478738
########## python/flink_agents/api/resource.py: ########## @@ -0,0 +1,88 @@ +################################################################################ +# 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 abc import ABC, abstractmethod +from enum import Enum + +from pydantic import BaseModel, model_validator + + +class ResourceType(Enum): + """Type enum of resource.""" + + CHAT_MODEL = "chat_model" + EMBEDDING_MODEL = "embedding_model" + PROMPT = "prompt" + TOOL = "tool" + VECTOR_STORE = "vector_store" + MCP_SERVER = "mcp_server" Review Comment: We may comment out types that we planned to but not yet support. ########## python/flink_agents/api/resource.py: ########## @@ -0,0 +1,88 @@ +################################################################################ +# 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 abc import ABC, abstractmethod +from enum import Enum + +from pydantic import BaseModel, model_validator + + +class ResourceType(Enum): + """Type enum of resource.""" + + CHAT_MODEL = "chat_model" + EMBEDDING_MODEL = "embedding_model" + PROMPT = "prompt" + TOOL = "tool" + VECTOR_STORE = "vector_store" + MCP_SERVER = "mcp_server" + + +class Resource(BaseModel, ABC): + """Base abstract class of all kinds of resources, includes chat model, + prompt, tool and so on. + + Resource extends BaseModel only for decreasing the complexity of attribute + declaration of subclasses, this not represents Resource object is serializable. + + Attributes: + ---------- + name : str + The name of the resource. + type : ResourceType + The type of the resource. + """ + + name: str + + @classmethod + def resource_type(cls) -> ResourceType: + """Return resource type of class.""" + + +class SerializableResource(Resource, ABC): + """Resource which is serializable.""" + + @model_validator(mode="after") + def validate_serializable(self) -> "SerializableResource": + """Ensure resource is serializable.""" + self.model_dump_json() + return self + + +class ResourceProvider(BaseModel, ABC): Review Comment: Should this be part of the public API? Does user need to directly implement or call this interface? ########## python/flink_agents/api/decorators.py: ########## @@ -38,13 +38,32 @@ def action(*listen_events: Tuple[Type[Event], ...]) -> Callable: AssertionError If no events are provided to listen to. """ - assert len(listen_events) > 0, 'action must have at least one event type to listen to' + assert len(listen_events) > 0, ( + "action must have at least one event type to listen to" + ) for event in listen_events: - assert issubclass(event, Event), 'action must only listen to event types.' + assert issubclass(event, Event), "action must only listen to event types." def decorator(func: Callable) -> Callable: func._listen_events = listen_events return func return decorator + + +def resource(func: Callable) -> Callable: Review Comment: Why do we have this decorator? We should not allow any custom resource types. So users should always use built-in decorators like `@model`, `@tool`. ########## python/flink_agents/api/resource.py: ########## @@ -0,0 +1,88 @@ +################################################################################ +# 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 abc import ABC, abstractmethod +from enum import Enum + +from pydantic import BaseModel, model_validator + + +class ResourceType(Enum): + """Type enum of resource.""" + + CHAT_MODEL = "chat_model" + EMBEDDING_MODEL = "embedding_model" + PROMPT = "prompt" + TOOL = "tool" + VECTOR_STORE = "vector_store" + MCP_SERVER = "mcp_server" + + +class Resource(BaseModel, ABC): + """Base abstract class of all kinds of resources, includes chat model, + prompt, tool and so on. + + Resource extends BaseModel only for decreasing the complexity of attribute + declaration of subclasses, this not represents Resource object is serializable. + + Attributes: + ---------- + name : str + The name of the resource. + type : ResourceType + The type of the resource. + """ + + name: str + + @classmethod + def resource_type(cls) -> ResourceType: Review Comment: This should also be an abstract method -- 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]
