mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-02 21:23:32 +00:00
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from typing import Any, List
|
|
|
|
from langchain_core.tools import BaseTool
|
|
from langchain_core.tools.base import BaseToolkit
|
|
from pydantic import model_validator
|
|
|
|
from langchain_community.tools.connery import ConneryService
|
|
|
|
|
|
class ConneryToolkit(BaseToolkit):
|
|
"""
|
|
Toolkit with a list of Connery Actions as tools.
|
|
|
|
Parameters:
|
|
tools (List[BaseTool]): The list of Connery Actions.
|
|
"""
|
|
|
|
tools: List[BaseTool]
|
|
|
|
def get_tools(self) -> List[BaseTool]:
|
|
"""
|
|
Returns the list of Connery Actions.
|
|
"""
|
|
return self.tools
|
|
|
|
@model_validator(mode="before")
|
|
@classmethod
|
|
def validate_attributes(cls, values: dict) -> Any:
|
|
"""
|
|
Validate the attributes of the ConneryToolkit class.
|
|
|
|
Args:
|
|
values (dict): The arguments to validate.
|
|
Returns:
|
|
dict: The validated arguments.
|
|
|
|
Raises:
|
|
ValueError: If the 'tools' attribute is not set
|
|
"""
|
|
|
|
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 get the list of Connery Actions.
|
|
Returns:
|
|
ConneryToolkit: The Connery Toolkit.
|
|
"""
|
|
|
|
instance = cls(tools=connery_service.list_actions()) # type: ignore[arg-type]
|
|
|
|
return instance
|