diff --git a/test-api/test-knowledge-fetch b/test-api/test-knowledge-fetch new file mode 100755 index 00000000..c327a9d8 --- /dev/null +++ b/test-api/test-knowledge-fetch @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import requests +import json +import sys +import base64 +import time + +url = "http://localhost:8088/api/v1/" + +############################################################################ + +input = { + "operation": "fetch-kg-core", + "id": "https://trustgraph.ai/doc/intelligence-and-state", + "user": "trustgraph", +} + +resp = requests.post( + f"{url}knowledge", + json=input, +) + +print(resp.text) +resp = resp.json() + +print(resp) + +if "error" in resp: + print(f"Error: {resp['error']}") + sys.exit(1) + +# print(resp["response"]) +print(resp) + +sys.exit(0) + +############################################################################ + diff --git a/test-api/test-knowledge-fetch2 b/test-api/test-knowledge-fetch2 new file mode 100755 index 00000000..2a611547 --- /dev/null +++ b/test-api/test-knowledge-fetch2 @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import requests +import asyncio +import json +import sys +import base64 +import time +from websockets.asyncio.client import connect + +url = "ws://localhost:8088/api/v1/socket" + +############################################################################ + +async def run(): + + async with connect(url) as ws: + + req = { + "id": "aa11", + "service": "knowledge", + "request": { + "operation": "fetch-kg-core", + "user": "trustgraph", + "id": "https://trustgraph.ai/doc/intelligence-and-state" + } + } + + await ws.send(json.dumps(req)) + + while True: + + msg = await ws.recv() + obj = json.loads(msg) + + print(obj) + + if "error" in obj: + print(f"Error: {obj['error']}") + break + + if "response" not in obj: continue + + if "eos" in obj["response"]: + if obj["response"]["eos"]: + break + +############################################################################ + +asyncio.run(run()) diff --git a/test-api/test-knowledge-list b/test-api/test-knowledge-list new file mode 100755 index 00000000..b616c719 --- /dev/null +++ b/test-api/test-knowledge-list @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import requests +import json +import sys +import base64 +import time + +url = "http://localhost:8088/api/v1/" + +############################################################################ + +input = { + "operation": "list-kg-cores", + "user": "trustgraph", +} + +resp = requests.post( + f"{url}knowledge", + json=input, +) + +print(resp.text) +resp = resp.json() + +print(resp) + +if "error" in resp: + print(f"Error: {resp['error']}") + sys.exit(1) + +# print(resp["response"]) +print(resp) + +sys.exit(0) + +############################################################################ +