-
Notifications
You must be signed in to change notification settings - Fork 277
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
custom tool input error #157
Comments
The following script is generated by AI Agent to help reproduce the issue: # crewAI-tools/reproduce.py
from pydantic import BaseModel, ValidationError
from typing import Type
import requests
class BaseTool:
name: str
description: str
args_schema: Type[BaseModel]
def run(self, *args, **kwargs):
raise NotImplementedError()
def to_langchain(self):
raise NotImplementedError()
class MyCustomToolSchema(BaseModel):
argument: str
class MyCustomTool(BaseTool):
name: str = "data retriever"
description: str = (
"This tool searches for the most relevant answers given the question."
)
args_schema: Type[BaseModel] = MyCustomToolSchema
def _run(self, argument: str) -> str:
# Implementation goes here
url = "some private url"
headers = {
'x-api-key': "private"
}
response = requests.get(url, headers=headers).json()
response = response['data']
response = [r['answer'].replace("\n", "") for r in response]
return response
def test_my_custom_tool():
my_tool = MyCustomTool()
# Test with valid input
try:
valid_input = {"argument": "valid string input"}
my_tool.args_schema(**valid_input)
print("Test passed successfully with no errors!")
except ValidationError as e:
raise AssertionError(e)
# Test with invalid input
try:
invalid_input = {"argument": {"description": "Invalid input", "type": "str"}}
my_tool.args_schema(**invalid_input)
except ValidationError as e:
raise AssertionError(e)
if __name__ == "__main__":
test_my_custom_tool() How to run: python3 crewAI-tools/reproduce.py Thank you for your valuable contribution to this project and we appreciate your feedback! Please respond with an emoji if you find this script helpful. Feel free to comment below if any improvements are needed. Best regards from an AI Agent! |
Check the type output of the tool, @farahFif. def _run(self, argument: str) -> str: Here you are declaring the output of the tool is a string. response = [r['answer'].replace("\n","") for r in response] Doesn't it make the actual type of the output a List? |
Hello,
I am creating a custom tool. The problem is that sometimes it can run the tool and sometimes it raises a problem with the input. I don't understand why such behaviour. Thanks for helping.
this is my tool :
The text was updated successfully, but these errors were encountered: