-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_example.py
72 lines (54 loc) · 2.14 KB
/
tool_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from simpletool import SimpleTool, Field, List
from simpletool.types import TextContent
from simpletool.models import SimpleInputModel
import asyncio
class MyInputModel(SimpleInputModel):
"""Input model for the MyTool"""
text: str = Field(description="An input field for testing")
class MyTool(SimpleTool):
name = "my_tool"
description = "A tool for testing"
input_model = MyInputModel
async def run(self, arguments: dict) -> List[TextContent]:
"""Execute the tool with the given arguments"""
# Validate input using Pydantic model
arg: MyInputModel = MyInputModel(**arguments)
return [TextContent(text=f"You said: {arg.text}")]
async def main(t: str):
mytool = MyTool()
return mytool, await mytool.run({"text": t})
my_tool, r = asyncio.run(main("Hello, world!"))
print("----------------------------------------------------------------------")
print("MyTool Return Value:")
print(f"type: {type(r)}")
print(str(r))
print("----------------------------------------------------------------------")
# Demonstrate different ways of accessing tool information
print("String Representation - str(my_tool):")
print(f"Type: {type(str(my_tool))}")
print(str(my_tool))
print("\nTool Details Print - my_tool.info:")
print(f"Type: {type(my_tool.info)}")
print(my_tool.info)
print("\nDictionary - my_tool.to_dict:")
print(f"Type: {type(my_tool.to_dict)}")
print(my_tool.to_dict)
# Display the string representation of MyTool
print("\nString Representation - repr(my_tool):")
print(f"Type: {type(repr(my_tool))}")
print(repr(my_tool))
print("----------------------------------------------------------------------")
# Demonstrate in/out - model/schema
print("Input: MODEL:")
print(f"Type: {type(my_tool.input_model)}")
print(my_tool.input_model)
print("\nInput: SCHEMA:")
print(f"Type: {type(my_tool.input_schema)}")
print(my_tool.input_schema)
print("\nOutput: MODEL:")
print(f"Type: {type(my_tool.output_model)}")
print(my_tool.output_model)
print("\nOutput: SCHEMA:")
print(f"Type: {type(my_tool.output_schema)}")
print(my_tool.output_schema)
print("----------------------------------------------------------------------")