-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_tool_examples.py
45 lines (35 loc) · 1.24 KB
/
api_tool_examples.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
# tool_generators.py
from tool_converters.schema_converter import generate_all_schemas
def add_numbers(a: float, b: float) -> float:
"""Adds two numbers together."""
print(f"TOOL_USED: Adding {a} and {b}")
return a + b
def subtract_numbers(a: float, b: float) -> float:
"""Subtracts one number from another."""
print(f"TOOL_USED: Subtracting {a} and {b}")
return a - b
def multiply_numbers(a: float, b: float) -> float:
"""Multiplies two numbers."""
print(f"TOOL_USED: Multiplying {a} and {b}")
return a * b
def divide_numbers(a: float, b: float) -> float:
"""Divides one number by another."""
if b == 0:
return "Error: Division by zero."
print(f"TOOL_USED: Dividing {a} by {b}")
return a / b
tools = [add_numbers, subtract_numbers, multiply_numbers, divide_numbers]
# Generate all schemas
all_schemas = generate_all_schemas(tools)
# Example: get the Anthropic schema
anthropic_schema = all_schemas["anthropic"]
print("Anthropic Schema:")
print(anthropic_schema)
# Example: get the Gemini schema
gemini_schema = all_schemas["gemini"]
print("Gemini Schema:")
print(gemini_schema)
# Example: get the OpenAI schema
openai_schema = all_schemas["openai"]
print("OpenAI Schema:")
print(openai_schema)