Skip to content

Commit

Permalink
Simplify custom tool creation example (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
StreetLamb authored Aug 4, 2024
1 parent e5c2266 commit 841535a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
10 changes: 5 additions & 5 deletions backend/app/core/graph/skills/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
WikipediaAPIWrapper,
)

# from .calculator import calculator
# from .calculator import multiply


class SkillInfo(BaseModel):
Expand All @@ -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.
24 changes: 7 additions & 17 deletions backend/app/core/graph/skills/calculator.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 841535a

Please sign in to comment.