diff --git a/backend/app/core/graph/skills/__init__.py b/backend/app/core/graph/skills/__init__.py index 37e4af12..86a6c262 100644 --- a/backend/app/core/graph/skills/__init__.py +++ b/backend/app/core/graph/skills/__init__.py @@ -6,7 +6,7 @@ WikipediaAPIWrapper, ) -# from .calculator import calculator +# from .calculator import multiply class SkillInfo(BaseModel): @@ -26,13 +26,13 @@ class SkillInfo(BaseModel): description="Get information from Yahoo Finance News.", tool=YahooFinanceNewsTool(), ), - # "calculator": SkillInfo( - # description=calculator.description, - # tool=calculator, + # multiply.name: SkillInfo( + # description=multiply.description, + # tool=multiply, # ), } # To add more custom tools, follow these steps: # 1. Create a new Python file in the `skills` folder (e.g., `calculator.py`). -# 2. Define your tool. Refer to `calculator.py` or see https://python.langchain.com/v0.1/docs/modules/tools/custom_tools/ +# 2. Define your tool. Refer to `calculator.py` or see https://python.langchain.com/v0.2/docs/how_to/custom_tools/ # 3. Import your new tool here and add it to the `managed_skills` dictionary above. diff --git a/backend/app/core/graph/skills/calculator.py b/backend/app/core/graph/skills/calculator.py index 70a70ab2..105a38ca 100644 --- a/backend/app/core/graph/skills/calculator.py +++ b/backend/app/core/graph/skills/calculator.py @@ -1,23 +1,13 @@ # This is an example showing how to create a simple calculator skill -from langchain.pydantic_v1 import BaseModel, Field -from langchain.tools import StructuredTool +from typing import Annotated +from langchain_core.tools import tool -class CalculatorInput(BaseModel): - a: int = Field(description="first number") - b: int = Field(description="second number") - -def multiply(a: int, b: int) -> int: - """Multiply two numbers.""" +@tool +def multiply( + a: Annotated[int, "first number"], b: Annotated[int, "second number"] +) -> int: + """Multiple two numbers.""" return a * b - - -calculator = StructuredTool.from_function( - func=multiply, - name="Calculator", - description="Useful for when you need to multiply two numbers.", - args_schema=CalculatorInput, - return_direct=True, -)