mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 09:11: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
|
|
@ -1,21 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Uses the GraphRAG service to answer a query
|
||||
Uses the GraphRAG service to answer a question
|
||||
"""
|
||||
|
||||
import argparse
|
||||
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_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)
|
||||
|
||||
def main():
|
||||
|
|
@ -26,25 +29,25 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-p', '--pulsar-host',
|
||||
default=default_pulsar_host,
|
||||
help=f'Pulsar host (default: {default_pulsar_host})',
|
||||
'-u', '--url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-q', '--query',
|
||||
'-q', '--question',
|
||||
required=True,
|
||||
help=f'Query to execute',
|
||||
help=f'Question to answer',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--user',
|
||||
'-U', '--user',
|
||||
default=default_user,
|
||||
help=f'User ID (default: {default_user})'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-c', '--collection',
|
||||
'-C', '--collection',
|
||||
default=default_collection,
|
||||
help=f'Collection ID (default: {default_collection})'
|
||||
)
|
||||
|
|
@ -53,9 +56,9 @@ def main():
|
|||
|
||||
try:
|
||||
|
||||
query(
|
||||
pulsar_host=args.pulsar_host,
|
||||
query=args.query,
|
||||
question(
|
||||
url=args.url,
|
||||
question=args.question,
|
||||
user=args.user,
|
||||
collection=args.collection,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue