mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 01:01:03 +02:00
Port a number of commands to use API gateway instead of Pulsar
This commit is contained in:
parent
44c0d6f347
commit
cb2e8a3724
6 changed files with 112 additions and 81 deletions
|
|
@ -6,23 +6,23 @@ Connects to the graph query service and dumps all graph edges.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from trustgraph.clients.triples_query_client import TriplesQueryClient
|
from trustgraph.api import Api
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
default_user = 'trustgraph'
|
default_user = 'trustgraph'
|
||||||
default_collection = 'default'
|
default_collection = 'default'
|
||||||
|
|
||||||
def show_graph(pulsar, user, collection):
|
def show_graph(url, user, collection):
|
||||||
|
|
||||||
tq = TriplesQueryClient(pulsar_host=pulsar)
|
api = Api(url)
|
||||||
|
|
||||||
rows = tq.request(
|
rows = api.triples_query(
|
||||||
user=user, collection=collection,
|
# user=user, collection=collection,
|
||||||
s=None, p=None, o=None, limit=10_000_000
|
s=None, p=None, o=None, limit=10_000,
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
print(row.s.value, row.p.value, row.o.value)
|
print(row.s, row.p, row.o)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
|
@ -32,19 +32,19 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--api-url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-u', '--user',
|
'-U', '--user',
|
||||||
default=default_user,
|
default=default_user,
|
||||||
help=f'User ID (default: {default_user})'
|
help=f'User ID (default: {default_user})'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--collection',
|
'-C', '--collection',
|
||||||
default=default_collection,
|
default=default_collection,
|
||||||
help=f'Collection ID (default: {default_collection})'
|
help=f'Collection ID (default: {default_collection})'
|
||||||
)
|
)
|
||||||
|
|
@ -54,7 +54,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
|
|
||||||
show_graph(
|
show_graph(
|
||||||
pulsar=args.pulsar_host, user=args.user,
|
url=args.api_url,
|
||||||
|
user=args.user,
|
||||||
collection=args.collection,
|
collection=args.collection,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,37 +5,45 @@ Connects to the graph query service and dumps all graph edges in Turtle
|
||||||
format.
|
format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
from trustgraph.clients.triples_query_client import TriplesQueryClient
|
|
||||||
import rdflib
|
import rdflib
|
||||||
import io
|
import io
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
from trustgraph.api import Api, Uri
|
||||||
|
|
||||||
def show_graph(pulsar):
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
default_user = 'trustgraph'
|
||||||
|
default_collection = 'default'
|
||||||
|
|
||||||
tq = TriplesQueryClient(pulsar_host=pulsar)
|
def show_graph(url, user, collection):
|
||||||
|
|
||||||
rows = tq.request(None, None, None, limit=10_000_000)
|
api = Api(url)
|
||||||
|
|
||||||
|
rows = api.triples_query(
|
||||||
|
s=None, p=None, o=None,
|
||||||
|
limit=10_000)
|
||||||
|
# user=user, collection=collection,
|
||||||
|
|
||||||
g = rdflib.Graph()
|
g = rdflib.Graph()
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
|
||||||
sv = rdflib.term.URIRef(row.s.value)
|
sv = rdflib.term.URIRef(row.s)
|
||||||
pv = rdflib.term.URIRef(row.p.value)
|
pv = rdflib.term.URIRef(row.p)
|
||||||
|
|
||||||
if row.o.is_uri:
|
if isinstance(row.o, Uri):
|
||||||
|
|
||||||
# Skip malformed URLs with spaces in
|
# Skip malformed URLs with spaces in
|
||||||
if " " in row.o.value:
|
if " " in row.o:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ov = rdflib.term.URIRef(row.o.value)
|
ov = rdflib.term.URIRef(row.o)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ov = rdflib.term.Literal(row.o.value)
|
|
||||||
|
ov = rdflib.term.Literal(row.o)
|
||||||
|
|
||||||
g.add((sv, pv, ov))
|
g.add((sv, pv, ov))
|
||||||
|
|
||||||
|
|
@ -56,16 +64,32 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--api-url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-U', '--user',
|
||||||
|
default=default_user,
|
||||||
|
help=f'User ID (default: {default_user})'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-C', '--collection',
|
||||||
|
default=default_collection,
|
||||||
|
help=f'Collection ID (default: {default_collection})'
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
show_graph(args.pulsar_host)
|
show_graph(
|
||||||
|
url=args.api_url,
|
||||||
|
user=args.user,
|
||||||
|
collection=args.collection
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,15 @@ and user prompt. Both arguments are required.
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from trustgraph.clients.llm_client import LlmClient
|
from trustgraph.api import Api
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
def query(pulsar_host, system, prompt):
|
def query(url, system, prompt):
|
||||||
|
|
||||||
cli = LlmClient(pulsar_host=pulsar_host)
|
api = Api(url)
|
||||||
|
|
||||||
resp = cli.request(system=system, prompt=prompt)
|
resp = api.text_completion(system=system, prompt=prompt)
|
||||||
|
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
||||||
|
|
@ -28,9 +28,9 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -50,7 +50,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query(
|
query(
|
||||||
pulsar_host=args.pulsar_host,
|
url=args.url,
|
||||||
system=args.system[0],
|
system=args.system[0],
|
||||||
prompt=args.prompt[0],
|
prompt=args.prompt[0],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,15 @@ using key=value arguments on the command line, and these replace
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from trustgraph.clients.prompt_client import PromptClient
|
from trustgraph.api import Api
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
def query(pulsar_host, template_id, variables):
|
def query(url, template_id, variables):
|
||||||
|
|
||||||
cli = PromptClient(pulsar_host=pulsar_host)
|
api = Api(url)
|
||||||
|
|
||||||
resp = cli.request(id=template_id, variables=variables)
|
resp = api.prompt(id=template_id, variables=variables)
|
||||||
|
|
||||||
if isinstance(resp, str):
|
if isinstance(resp, str):
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
@ -35,9 +35,9 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -70,7 +70,7 @@ specified multiple times''',
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query(
|
query(
|
||||||
pulsar_host=args.pulsar_host,
|
url=args.url,
|
||||||
template_id=args.id[0],
|
template_id=args.id[0],
|
||||||
variables=variables,
|
variables=variables,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Uses the Document RAG service to answer a query
|
Uses the GraphRAG service to answer a question
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from trustgraph.clients.document_rag_client import DocumentRagClient
|
from trustgraph.api import Api
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
default_user = 'trustgraph'
|
default_user = 'trustgraph'
|
||||||
default_collection = 'default'
|
default_collection = 'default'
|
||||||
|
|
||||||
def query(pulsar_host, query, user, collection):
|
def question(url, question, user, collection):
|
||||||
|
|
||||||
|
rag = Api(url)
|
||||||
|
|
||||||
|
# user=user, collection=collection,
|
||||||
|
resp = rag.document_rag(question=question)
|
||||||
|
|
||||||
rag = DocumentRagClient(pulsar_host=pulsar)
|
|
||||||
resp = rag.request(user=user, collection=collection, query=query)
|
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -26,25 +29,25 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-q', '--query',
|
'-q', '--question',
|
||||||
required=True,
|
required=True,
|
||||||
help=f'Query to execute',
|
help=f'Question to answer',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-u', '--user',
|
'-U', '--user',
|
||||||
default=default_user,
|
default=default_user,
|
||||||
help=f'User ID (default: {default_user})'
|
help=f'User ID (default: {default_user})'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--collection',
|
'-C', '--collection',
|
||||||
default=default_collection,
|
default=default_collection,
|
||||||
help=f'Collection ID (default: {default_collection})'
|
help=f'Collection ID (default: {default_collection})'
|
||||||
)
|
)
|
||||||
|
|
@ -53,9 +56,9 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query(
|
question(
|
||||||
pulsar_host=args.pulsar_host,
|
url=args.url,
|
||||||
query=args.query,
|
question=args.question,
|
||||||
user=args.user,
|
user=args.user,
|
||||||
collection=args.collection,
|
collection=args.collection,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Uses the GraphRAG service to answer a query
|
Uses the GraphRAG service to answer a question
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from trustgraph.clients.graph_rag_client import GraphRagClient
|
from trustgraph.api import Api
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
default_user = 'trustgraph'
|
default_user = 'trustgraph'
|
||||||
default_collection = 'default'
|
default_collection = 'default'
|
||||||
|
|
||||||
def query(pulsar_host, query, user, collection):
|
def question(url, question, user, collection):
|
||||||
|
|
||||||
|
rag = Api(url)
|
||||||
|
|
||||||
|
# user=user, collection=collection,
|
||||||
|
resp = rag.graph_rag(question=question)
|
||||||
|
|
||||||
rag = GraphRagClient(pulsar_host=pulsar_host)
|
|
||||||
resp = rag.request(user=user, collection=collection, query=query)
|
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -26,25 +29,25 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--pulsar-host',
|
'-u', '--url',
|
||||||
default=default_pulsar_host,
|
default=default_url,
|
||||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
help=f'API URL (default: {default_url})',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-q', '--query',
|
'-q', '--question',
|
||||||
required=True,
|
required=True,
|
||||||
help=f'Query to execute',
|
help=f'Question to answer',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-u', '--user',
|
'-U', '--user',
|
||||||
default=default_user,
|
default=default_user,
|
||||||
help=f'User ID (default: {default_user})'
|
help=f'User ID (default: {default_user})'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--collection',
|
'-C', '--collection',
|
||||||
default=default_collection,
|
default=default_collection,
|
||||||
help=f'Collection ID (default: {default_collection})'
|
help=f'Collection ID (default: {default_collection})'
|
||||||
)
|
)
|
||||||
|
|
@ -53,9 +56,9 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query(
|
question(
|
||||||
pulsar_host=args.pulsar_host,
|
url=args.url,
|
||||||
query=args.query,
|
question=args.question,
|
||||||
user=args.user,
|
user=args.user,
|
||||||
collection=args.collection,
|
collection=args.collection,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue