Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify custom tool creation example #102

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
Loading