mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
Feature/api gateway (#164)
* Bare bones API gateway * Working for LLM + prompt * RAG query works * Triples query * Added agent API * Embeddings API * Put API tests in a subdir
This commit is contained in:
parent
b536d78b57
commit
92b84441eb
9 changed files with 768 additions and 0 deletions
28
test-api/test-agent-api
Executable file
28
test-api/test-agent-api
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"question": "What is the highest risk aspect of running a space shuttle program? Provide 5 detailed reasons to justify our answer.",
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}agent",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
print(resp["answer"])
|
||||
|
||||
|
||||
25
test-api/test-embeddings-api
Executable file
25
test-api/test-embeddings-api
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"text": "What is the highest risk aspect of running a space shuttle program? Provide 5 detailed reasons to justify our answer.",
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}embeddings",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
31
test-api/test-graph-rag-api
Executable file
31
test-api/test-graph-rag-api
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"query": "Give me 10 facts",
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}graph-rag",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
print(resp)
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
print(resp["response"])
|
||||
|
||||
sys.exit(0)
|
||||
############################################################################
|
||||
|
||||
31
test-api/test-llm-api
Executable file
31
test-api/test-llm-api
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"system": "Respond in French. Use long word, form of numbers, no digits",
|
||||
# "prompt": "Add 2 and 12"
|
||||
"prompt": "Add 12 and 14, and then make a poem about llamas which incorporates that number. Then write a joke about llamas"
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}text-completion",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
print(resp["response"])
|
||||
|
||||
############################################################################
|
||||
|
||||
38
test-api/test-prompt-api
Executable file
38
test-api/test-prompt-api
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"id": "question",
|
||||
"variables": {
|
||||
"question": "Write a joke about llamas."
|
||||
}
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}prompt",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
print(resp)
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
if "object" in resp:
|
||||
print(f"Object: {resp['object']}")
|
||||
sys.exit(1)
|
||||
|
||||
print(resp["text"])
|
||||
|
||||
sys.exit(0)
|
||||
############################################################################
|
||||
|
||||
39
test-api/test-prompt2-api
Executable file
39
test-api/test-prompt2-api
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"id": "extract-definitions",
|
||||
"variables": {
|
||||
"text": "A cat is a large mammal."
|
||||
}
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}prompt",
|
||||
json=input,
|
||||
)
|
||||
|
||||
resp = resp.json()
|
||||
|
||||
print(resp)
|
||||
if "error" in resp:
|
||||
print(f"Error: {resp['error']}")
|
||||
sys.exit(1)
|
||||
|
||||
if "object" in resp:
|
||||
object = json.loads(resp["object"])
|
||||
print(json.dumps(object, indent=4))
|
||||
sys.exit(1)
|
||||
|
||||
print(resp["text"])
|
||||
|
||||
sys.exit(0)
|
||||
############################################################################
|
||||
|
||||
35
test-api/test-triples-query-api
Executable file
35
test-api/test-triples-query-api
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
url = "http://localhost:8088/api/v1/"
|
||||
|
||||
############################################################################
|
||||
|
||||
input = {
|
||||
"p": "http://www.w3.org/2000/01/rdf-schema#label",
|
||||
"limit": 10
|
||||
}
|
||||
|
||||
resp = requests.post(
|
||||
f"{url}triples-query",
|
||||
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"])
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
############################################################################
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue