54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Remote tool example — ask something that needs fresh info from the web.
|
|
|
|
Raycast's `web_search` is server-routed: pass `RemoteTool.WEB_SEARCH` in
|
|
`tools=` and that's it. The model decides when to invoke it, the server
|
|
runs the search, and the assistant streams the synthesised answer back.
|
|
Nothing for the client to execute.
|
|
|
|
Prerequisites: same as basic_usage.py (config.json, RAYCAST_BEARER,
|
|
RAYCAST_DEVICE_ID).
|
|
|
|
Run:
|
|
python examples/web_search.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from raycast_api import Client, Config, Message, RemoteTool
|
|
|
|
CONFIG_PATH = Path(os.environ.get("RAYCAST_CONFIG", "config.json"))
|
|
MODEL = os.environ.get("RAYCAST_MODEL", "Claude Sonnet 4.6")
|
|
|
|
|
|
async def main() -> None:
|
|
bearer = os.environ.get("RAYCAST_BEARER")
|
|
device_id = os.environ.get("RAYCAST_DEVICE_ID")
|
|
if not bearer or not device_id:
|
|
sys.exit("set RAYCAST_BEARER and RAYCAST_DEVICE_ID before running")
|
|
if not CONFIG_PATH.is_file():
|
|
sys.exit(f"no config at {CONFIG_PATH} — run `raycast-api init` first")
|
|
|
|
async with Client(
|
|
config=Config.load(CONFIG_PATH), bearer_token=bearer, device_id=device_id
|
|
) as client:
|
|
result = await client.chat.complete(
|
|
model=MODEL,
|
|
messages=[
|
|
Message.user(
|
|
"What's the most recent stable Python release? "
|
|
"Reply with just the version number."
|
|
)
|
|
],
|
|
tools=[RemoteTool.WEB_SEARCH],
|
|
)
|
|
print(result.text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|