-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
48 lines (36 loc) · 1.39 KB
/
Copy pathbasic_usage.py
File metadata and controls
48 lines (36 loc) · 1.39 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
"""
Example: using SupportAssistant programmatically (not via the CLI).
This script requires a real AI_API_KEY to actually call the provider.
Set it in your .env file (see .env.example) before running:
python examples/basic_usage.py
All customer messages below are fictional and used purely for
demonstration purposes.
"""
import sys
from pathlib import Path
# Allow running this example directly without installing the package.
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
from ai_support_assistant.assistant import SupportAssistant # noqa: E402
from ai_support_assistant.config import ConfigError # noqa: E402
from ai_support_assistant.exceptions import AIProviderError # noqa: E402
DEMO_MESSAGES = [
"Hi, how can I change my delivery address for an order I just placed?",
"And what if the order has already shipped?",
]
def main() -> None:
try:
assistant = SupportAssistant()
except ConfigError as exc:
print(f"Configuration error: {exc}")
print("Tip: copy .env.example to .env and add your own AI_API_KEY.")
return
for message in DEMO_MESSAGES:
print(f"\nCustomer: {message}")
try:
reply = assistant.ask(message)
except AIProviderError as exc:
print(f"[AI provider error] {exc}")
return
print(f"Assistant: {reply}")
if __name__ == "__main__":
main()