mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
265e650e64
This PR updates root validators for: * Embeddings: llamacpp, jina, dashscope, mosaicml, huggingface_hub * Toolkits: Connery * ChatModels: PAI_EAS Following this issue: https://github.com/langchain-ai/langchain/issues/22819
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from typing import List
|
|
|
|
from langchain_core.pydantic_v1 import root_validator
|
|
from langchain_core.tools import BaseTool, BaseToolkit
|
|
|
|
from langchain_community.tools.connery import ConneryService
|
|
|
|
|
|
class ConneryToolkit(BaseToolkit):
|
|
"""
|
|
Toolkit with a list of Connery Actions as tools.
|
|
"""
|
|
|
|
tools: List[BaseTool]
|
|
|
|
def get_tools(self) -> List[BaseTool]:
|
|
"""
|
|
Returns the list of Connery Actions.
|
|
"""
|
|
return self.tools
|
|
|
|
@root_validator(pre=True)
|
|
def validate_attributes(cls, values: dict) -> dict:
|
|
"""
|
|
Validate the attributes of the ConneryToolkit class.
|
|
Parameters:
|
|
values (dict): The arguments to validate.
|
|
Returns:
|
|
dict: The validated arguments.
|
|
"""
|
|
|
|
if not values.get("tools"):
|
|
raise ValueError("The attribute 'tools' must be set.")
|
|
|
|
return values
|
|
|
|
@classmethod
|
|
def create_instance(cls, connery_service: ConneryService) -> "ConneryToolkit":
|
|
"""
|
|
Creates a Connery Toolkit using a Connery Service.
|
|
Parameters:
|
|
connery_service (ConneryService): The Connery Service
|
|
to to get the list of Connery Actions.
|
|
Returns:
|
|
ConneryToolkit: The Connery Toolkit.
|
|
"""
|
|
|
|
instance = cls(tools=connery_service.list_actions()) # type: ignore[arg-type]
|
|
|
|
return instance
|