mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
parent
2bcf375103
commit
3ba6a3238f
6 changed files with 970 additions and 0 deletions
56
dev-tools/tests/librarian/simple_text_upload.py
Normal file
56
dev-tools/tests/librarian/simple_text_upload.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Minimal example: upload a small text document via websocket API
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import base64
|
||||
import time
|
||||
import websockets
|
||||
|
||||
async def main():
|
||||
url = "ws://localhost:8088/api/v1/socket"
|
||||
|
||||
# Small text content
|
||||
content = b"AAAAAAAAAABBBBBBBBBBCCCCCCCCCC"
|
||||
|
||||
request_id = 0
|
||||
|
||||
async def send_request(ws, request):
|
||||
nonlocal request_id
|
||||
request_id += 1
|
||||
msg = {
|
||||
"id": f"req-{request_id}",
|
||||
"service": "librarian",
|
||||
"request": request
|
||||
}
|
||||
await ws.send(json.dumps(msg))
|
||||
response = json.loads(await ws.recv())
|
||||
if "error" in response:
|
||||
raise Exception(response["error"])
|
||||
return response.get("response", {})
|
||||
|
||||
async with websockets.connect(url) as ws:
|
||||
|
||||
print(f"Uploading {len(content)} bytes...")
|
||||
|
||||
resp = await send_request(ws, {
|
||||
"operation": "add-document",
|
||||
"document-metadata": {
|
||||
"id": "test-chunked-doc-001",
|
||||
"time": int(time.time()),
|
||||
"kind": "text/plain",
|
||||
"title": "My Test Document",
|
||||
"comments": "Small doc for chunk testing",
|
||||
"user": "trustgraph",
|
||||
"tags": ["test"],
|
||||
"metadata": [],
|
||||
},
|
||||
"content": base64.b64encode(content).decode("utf-8"),
|
||||
})
|
||||
|
||||
print("Done!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue