Skip to content

Commit 521b381

Browse files
committed
feat: add knowledge CLI group and serve command
1 parent 6236ac1 commit 521b381

File tree

1 file changed

+14
-14
lines changed
  • src/datapilot/core/knowledge

1 file changed

+14
-14
lines changed

src/datapilot/core/knowledge/cli.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import re
88

99

10-
@click.group()
10+
@click.group(name="knowledge")
1111
def cli():
1212
"""knowledge specific commands."""
1313

@@ -21,39 +21,39 @@ def serve(ctx, port):
2121
token = ctx.parent.obj.get('token')
2222
instance_name = ctx.parent.obj.get('instance_name')
2323
backend_url = ctx.parent.obj.get('backend_url')
24-
24+
2525
if not token or not instance_name:
2626
click.echo("Error: API token and instance name are required. Use --token and --instance-name options or set them in config.", err=True)
2727
ctx.exit(1)
28-
28+
2929
class KnowledgeBaseHandler(BaseHTTPRequestHandler):
3030
def do_GET(self):
3131
"""Handle GET requests."""
3232
path = urlparse(self.path).path
33-
33+
3434
# Match /knowledge_bases/{uuid} pattern
3535
match = re.match(r'^/knowledge_bases/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$', path)
36-
36+
3737
if match:
3838
public_id = match.group(1)
3939
self.handle_knowledge_base(public_id)
4040
elif path == '/health':
4141
self.handle_health()
4242
else:
4343
self.send_error(404, "Not Found")
44-
44+
4545
def handle_knowledge_base(self, public_id):
4646
"""Fetch and return knowledge base data."""
4747
url = f"{backend_url}/knowledge_bases/public/{public_id}"
48-
48+
4949
headers = {
5050
'Authorization': f'Bearer {token}',
5151
'X-Tenant': instance_name,
5252
'Content-Type': 'application/json'
5353
}
54-
54+
5555
req = Request(url, headers=headers)
56-
56+
5757
try:
5858
with urlopen(req) as response:
5959
data = response.read()
@@ -73,26 +73,26 @@ def handle_knowledge_base(self, public_id):
7373
self.end_headers()
7474
error_msg = json.dumps({'error': str(e)})
7575
self.wfile.write(error_msg.encode('utf-8'))
76-
76+
7777
def handle_health(self):
7878
"""Handle health check endpoint."""
7979
self.send_response(200)
8080
self.send_header('Content-Type', 'application/json')
8181
self.end_headers()
8282
self.wfile.write(json.dumps({'status': 'ok'}).encode('utf-8'))
83-
83+
8484
def log_message(self, format, *args):
8585
"""Override to use click.echo for logging."""
8686
click.echo(f"{self.address_string()} - {format % args}")
87-
87+
8888
server_address = ('', port)
8989
httpd = HTTPServer(server_address, KnowledgeBaseHandler)
90-
90+
9191
click.echo(f"Starting knowledge base server on port {port}...")
9292
click.echo(f"Backend URL: {backend_url}")
9393
click.echo(f"Instance: {instance_name}")
9494
click.echo(f"Server running at http://localhost:{port}")
95-
95+
9696
try:
9797
httpd.serve_forever()
9898
except KeyboardInterrupt:

0 commit comments

Comments
 (0)