File size: 1,152 Bytes
c74e524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Headless check: one text turn must return a reply.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd)
"$ROOT/.venv-thinker/bin/python" - "$ROOT" <<'PY'
import sys, json, hmac, asyncio, aiohttp
from pathlib import Path
root = Path(sys.argv[1])
code = (root / '.access_code').read_text().strip()
key = hmac.new(code.encode(), b'aiden-demo-cookie-v1', 'sha256').hexdigest()
async def main():
    async with aiohttp.ClientSession() as s:
        async with s.ws_connect('ws://127.0.0.1:8998/ws',
                headers={'Origin': 'http://127.0.0.1:8998',
                         'Cookie': '__Host-aiden_access=' + key}) as ws:
            await ws.send_json({'type': 'text', 'text': 'Tell me a fun fact about the ocean.'})
            while True:
                m = await ws.receive(timeout=120)
                if m.type == aiohttp.WSMsgType.TEXT:
                    d = json.loads(m.data)
                    if d['type'] == 'reply':
                        print('reply:', d['text'][:120]); return
                    if d['type'] == 'error':
                        raise SystemExit(d['message'])
asyncio.run(main())
PY