|
3 | 3 | For semantic search basics, see semantic_search_example.py. |
4 | 4 | For full agent execution, see agent_tool_search.py. |
5 | 5 |
|
| 6 | +Prerequisites: |
| 7 | + - STACKONE_API_KEY environment variable |
| 8 | + - STACKONE_ACCOUNT_ID environment variable |
| 9 | +
|
6 | 10 | Run with: |
7 | 11 | uv run python examples/search_tool_example.py |
8 | 12 | """ |
|
22 | 26 |
|
23 | 27 |
|
24 | 28 | def main() -> None: |
25 | | - account_id = os.getenv("STACKONE_ACCOUNT_ID", "") |
26 | | - _account_ids = [a.strip() for a in account_id.split(",") if a.strip()] if account_id else [] |
| 29 | + api_key = os.getenv("STACKONE_API_KEY") |
| 30 | + account_id = os.getenv("STACKONE_ACCOUNT_ID") |
| 31 | + |
| 32 | + if not api_key: |
| 33 | + print("Set STACKONE_API_KEY to run this example.") |
| 34 | + return |
| 35 | + if not account_id: |
| 36 | + print("Set STACKONE_ACCOUNT_ID to run this example.") |
| 37 | + return |
27 | 38 |
|
28 | 39 | # --- Example 1: get_search_tool() callable --- |
29 | 40 | print("=== get_search_tool() callable ===\n") |
30 | 41 |
|
31 | | - toolset = StackOneToolSet(search={}) |
| 42 | + toolset = StackOneToolSet(api_key=api_key, account_id=account_id, search={}) |
32 | 43 | search_tool = toolset.get_search_tool() |
33 | 44 |
|
34 | 45 | queries = ["cancel an event", "list employees", "send a message"] |
35 | 46 | for query in queries: |
36 | | - tools = search_tool(query, top_k=3, account_ids=_account_ids) |
| 47 | + tools = search_tool(query, top_k=3) |
37 | 48 | names = [t.name for t in tools] |
38 | 49 | print(f' "{query}" -> {", ".join(names) or "(none)"}') |
39 | 50 |
|
40 | 51 | # --- Example 2: Constructor top_k vs per-call override --- |
41 | 52 | print("\n=== Constructor top_k vs per-call override ===\n") |
42 | 53 |
|
43 | | - toolset_3 = StackOneToolSet(search={"top_k": 3}) |
44 | | - toolset_10 = StackOneToolSet(search={"top_k": 10}) |
| 54 | + toolset_3 = StackOneToolSet(api_key=api_key, account_id=account_id, search={"top_k": 3}) |
45 | 55 |
|
46 | 56 | query = "manage employee records" |
47 | 57 |
|
48 | | - tools_3 = toolset_3.search_tools(query, account_ids=_account_ids) |
| 58 | + tools_3 = toolset_3.search_tools(query) |
49 | 59 | print(f"Constructor top_k=3: got {len(tools_3)} tools") |
50 | 60 |
|
51 | | - tools_10 = toolset_10.search_tools(query, account_ids=_account_ids) |
52 | | - print(f"Constructor top_k=10: got {len(tools_10)} tools") |
53 | | - |
54 | | - # Per-call override: constructor says 3 but this call says 10 |
55 | | - tools_override = toolset_3.search_tools(query, top_k=10, account_ids=_account_ids) |
| 61 | + tools_override = toolset_3.search_tools(query, top_k=10) |
56 | 62 | print(f"Per-call top_k=10 (overrides constructor 3): got {len(tools_override)} tools") |
57 | 63 |
|
58 | 64 |
|
|
0 commit comments