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

Update 1_tool_constructor.py #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions 5_agents_and_tools/tools_deep_dive/1_tool_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class ConcatenateStringsArgs(BaseModel):
a: str = Field(description="First string")
b: str = Field(description="Second string")

class reverse_stringArgs(BaseModel):
text: str = Field(description="single string")


# Create tools using the Tool and StructuredTool constructor approach
tools = [
Expand All @@ -39,12 +42,18 @@ class ConcatenateStringsArgs(BaseModel):
func=greet_user, # Function to execute
description="Greets the user by name.", # Description of the tool
),
# Use Tool for another simple function with a single input parameter.
Tool(
name="ReverseString", # Name of the tool
StructuredTool.from_function(
func=reverse_string, # Function to execute
description="Reverses the given string.", # Description of the tool
),
name="reverse_string", # Name of the tool
description="Reverses the given string, Input to this tool must be a single string", # Description of the tool
args_schema=reverse_stringArgs, # Schema defining the tool's input arguments
), # Newer version Langchain seems don't work well with previous "ReverseString" code.
# # Use Tool for another simple function with a single input parameter.
# Tool(
# name="ReverseString", # Name of the tool
# func=reverse_string, # Function to execute
# description="Reverses the given string, Input to this tool must be a single string, not a list.", # Description of the tool
# ),
# Use StructuredTool for more complex functions that require multiple input parameters.
# StructuredTool allows us to define an input schema using Pydantic, ensuring proper validation and description.
StructuredTool.from_function(
Expand Down