-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_tools.py
More file actions
38 lines (27 loc) · 921 Bytes
/
Copy pathdemo_tools.py
File metadata and controls
38 lines (27 loc) · 921 Bytes
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
"""Sample tools module — import this from other scripts to test toolschema."""
from __future__ import annotations
from typing import Annotated, Literal
from toolschema import Field, schema, tool
@tool
def greet(name: str) -> str:
"""Say hello to someone."""
return f"Hello, {name}!"
@tool
def add(a: int, b: int = 1) -> int:
"""Add two integers."""
return a + b
@tool
def search_items(
query: Annotated[str, Field(description="Search text", min_length=1)],
limit: int = 10,
sort: Literal["relevance", "date"] = "relevance",
) -> list[dict]:
"""Search a catalog and return matching items."""
return [{"query": query, "limit": limit, "sort": sort}]
def get_tool_definitions():
"""Return ToolDefinition objects for every @tool in this module."""
return {
"greet": schema(greet),
"add": schema(add),
"search_items": schema(search_items),
}