-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_assistants.py
More file actions
65 lines (53 loc) · 2.16 KB
/
Copy pathlist_assistants.py
File metadata and controls
65 lines (53 loc) · 2.16 KB
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
#!/usr/bin/env python3
"""
List custom assistants and their IDs (for use with --assistant-id in chat.py).
Usage: python list_assistants.py [--base-url URL]
"""
from __future__ import annotations
import argparse
import sys
import requests
from config import get_base_url, load_apikey
from watson_client import WatsonOrchestrateClient
def main() -> int:
parser = argparse.ArgumentParser(description="List Watson Orchestrate custom assistants and their IDs")
parser.add_argument("--base-url", default=None, help="Watson Orchestrate API base URL")
parser.add_argument("--apikey-file", default=None, help="Path to apikey.json")
args = parser.parse_args()
try:
api_key = load_apikey(args.apikey_file)
except (FileNotFoundError, ValueError) as e:
print(f"Error: {e}", file=sys.stderr)
return 1
base_url = args.base_url or get_base_url()
client = WatsonOrchestrateClient(base_url=base_url, api_key=api_key)
try:
data = client.list_custom_assistants()
except requests.HTTPError as e:
print(f"API error: {e}", file=sys.stderr)
if e.response is not None and getattr(e.response, "text", None):
print("Response body:", e.response.text[:800], file=sys.stderr)
return 1
except Exception as e:
print(f"API error: {e}", file=sys.stderr)
return 1
# Response may be {"assistants": [...]} or a list
assistants = data.get("assistants", data) if isinstance(data, dict) else data
if not isinstance(assistants, list):
assistants = [data]
if not assistants:
print("No custom assistants found.")
print("Create one in Watson Orchestrate, or omit --assistant-id to use the default.")
return 0
print("Custom assistants (use --assistant-id <id> in chat.py):\n")
for a in assistants:
aid = a.get("id") or a.get("assistant_id") or "(no id)"
name = a.get("name") or a.get("title") or "(no name)"
print(f" {aid}")
print(f" name: {name}")
if a.get("description"):
print(f" description: {a.get('description')[:80]}...")
print()
return 0
if __name__ == "__main__":
sys.exit(main())