22# SPDX-License-Identifier: Apache-2.0
33
44import json
5- import click
65import os
76from pathlib import Path
87from typing import Optional
8+
9+ import click
910from cli .client import EcragApiClient
1011from cli .config import get_config
1112
@@ -34,26 +35,26 @@ def run_chatqna_query(client: EcragApiClient, query: str, top_n: int, max_tokens
3435@click .pass_context
3536def cli (ctx , host : Optional [str ], port : Optional [int ], mega_port : Optional [int ]):
3637 """EdgeCraft RAG CLI Tool.
37-
38+
3839 Configure server connection via command-line options or environment variables:
3940 - ECRAG_HOST: Server host (default: http://localhost)
4041 - ECRAG_PORT: Server port (default: 16010)
4142 - ECRAG_MEGA_PORT: Mega service port (default: 16011)
4243 """
4344 ctx .ensure_object (dict )
44-
45+
4546 # Get defaults from config
4647 config = get_config ()
47-
48+
4849 # Use provided options or environment/defaults
4950 final_host = host or config .host
5051 final_port = port or config .port
5152 final_mega_port = mega_port or config .mega_port
52-
53+
5354 # Normalize host URL
5455 if not final_host .startswith (("http://" , "https://" )):
5556 final_host = f"http://{ final_host } "
56-
57+
5758 ctx .obj ["client" ] = EcragApiClient (host = final_host , server_port = final_port , mega_port = final_mega_port )
5859
5960
@@ -204,7 +205,7 @@ def load(ctx, model_type: str, model_id: str, model_path: str, device: str, weig
204205
205206@model .command ()
206207@click .pass_context
207- def list (ctx ):
208+ def list (ctx ): # noqa: F811
208209 """List all models."""
209210 client = ctx .obj ["client" ]
210211 result = client .get_models ()
@@ -214,7 +215,7 @@ def list(ctx):
214215@model .command ()
215216@click .option ("--id" , "model_id" , required = True , help = "Model ID" )
216217@click .pass_context
217- def get (ctx , model_id : str ):
218+ def get (ctx , model_id : str ): # noqa: F811
218219 """Get a specific model."""
219220 client = ctx .obj ["client" ]
220221 result = client .get_model (model_id )
@@ -241,7 +242,7 @@ def update(ctx, model_id: str, device: Optional[str], weight: Optional[str]):
241242@model .command ()
242243@click .option ("--id" , "model_id" , required = True , help = "Model ID" )
243244@click .pass_context
244- def delete (ctx , model_id : str ):
245+ def delete (ctx , model_id : str ): # noqa: F811
245246 """Delete a model."""
246247 client = ctx .obj ["client" ]
247248 if click .confirm (f"Are you sure you want to delete model '{ model_id } '?" ):
@@ -284,7 +285,7 @@ def kb():
284285@click .option ("--description" , help = "Knowledge base description" )
285286@click .option ("-f" , "--file" , type = click .Path (exists = True ), help = "KB config JSON file" )
286287@click .pass_context
287- def create (ctx , name : str , description : Optional [str ], file : Optional [str ]):
288+ def create (ctx , name : str , description : Optional [str ], file : Optional [str ]): # noqa: F811
288289 """Create a knowledge base."""
289290 client = ctx .obj ["client" ]
290291
@@ -302,7 +303,7 @@ def create(ctx, name: str, description: Optional[str], file: Optional[str]):
302303
303304@kb .command ()
304305@click .pass_context
305- def list (ctx ):
306+ def list (ctx ): # noqa: F811
306307 """List all knowledge bases."""
307308 client = ctx .obj ["client" ]
308309 result = client .get_knowledge_bases ()
@@ -312,7 +313,7 @@ def list(ctx):
312313@kb .command ()
313314@click .option ("-n" , "--name" , required = True , help = "Knowledge base name" )
314315@click .pass_context
315- def get (ctx , name : str ):
316+ def get (ctx , name : str ): # noqa: F811
316317 """Get a specific knowledge base."""
317318 client = ctx .obj ["client" ]
318319 result = client .get_knowledge_base (name )
@@ -322,7 +323,7 @@ def get(ctx, name: str):
322323@kb .command ()
323324@click .option ("-n" , "--name" , required = True , help = "Knowledge base name" )
324325@click .pass_context
325- def get_json (ctx , name : str ):
326+ def get_json (ctx , name : str ): # noqa: F811
326327 """Get knowledge base JSON data."""
327328 client = ctx .obj ["client" ]
328329 result = client .get_knowledge_base_json (name )
@@ -346,7 +347,7 @@ def filemap(ctx, name: str, page_num: int, page_size: int):
346347@click .option ("--active" , type = bool , help = "Set active status" )
347348@click .option ("--description" , help = "Update description" )
348349@click .pass_context
349- def update (ctx , name : str , active : Optional [bool ], description : Optional [str ]):
350+ def update (ctx , name : str , active : Optional [bool ], description : Optional [str ]): # noqa: F811
350351 """Update a knowledge base."""
351352 client = ctx .obj ["client" ]
352353 kb_data = {"name" : name }
@@ -361,7 +362,7 @@ def update(ctx, name: str, active: Optional[bool], description: Optional[str]):
361362@kb .command ()
362363@click .option ("-n" , "--name" , required = True , help = "Knowledge base name" )
363364@click .pass_context
364- def delete (ctx , name : str ):
365+ def delete (ctx , name : str ): # noqa: F811
365366 """Delete a knowledge base."""
366367 client = ctx .obj ["client" ]
367368 if click .confirm (f"Are you sure you want to delete knowledge base '{ name } '?" ):
@@ -402,7 +403,7 @@ def experience():
402403
403404@experience .command ()
404405@click .pass_context
405- def list (ctx ):
406+ def list (ctx ): # noqa: F811
406407 """List all experiences."""
407408 client = ctx .obj ["client" ]
408409 result = client .get_experiences ()
@@ -412,7 +413,7 @@ def list(ctx):
412413@experience .command ()
413414@click .option ("--id" , required = True , help = "Experience ID" )
414415@click .pass_context
415- def get (ctx , id : str ):
416+ def get (ctx , id : str ): # noqa: F811
416417 """Get a specific experience."""
417418 client = ctx .obj ["client" ]
418419 result = client .get_experience (id )
@@ -424,7 +425,7 @@ def get(ctx, id: str):
424425@click .option ("--question" , required = True , help = "Question" )
425426@click .option ("--content" , multiple = True , required = True , help = "Answer content" )
426427@click .pass_context
427- def create (ctx , id : str , question : str , content : tuple ):
428+ def create (ctx , id : str , question : str , content : tuple ): # noqa: F811
428429 """Create or update an experience."""
429430 client = ctx .obj ["client" ]
430431 exp_data = {"idx" : id , "question" : question , "content" : list (content )}
@@ -435,7 +436,7 @@ def create(ctx, id: str, question: str, content: tuple):
435436@experience .command ()
436437@click .option ("--id" , required = True , help = "Experience ID" )
437438@click .pass_context
438- def delete (ctx , id : str ):
439+ def delete (ctx , id : str ): # noqa: F811
439440 """Delete an experience."""
440441 client = ctx .obj ["client" ]
441442 if click .confirm (f"Are you sure you want to delete experience '{ id } '?" ):
@@ -464,7 +465,7 @@ def agent():
464465
465466@agent .command ()
466467@click .pass_context
467- def list (ctx ):
468+ def list (ctx ): # noqa: F811
468469 """List all agents."""
469470 client = ctx .obj ["client" ]
470471 result = client .get_agents ()
@@ -474,7 +475,7 @@ def list(ctx):
474475@agent .command ()
475476@click .option ("-n" , "--name" , required = True , help = "Agent name" )
476477@click .pass_context
477- def get (ctx , name : str ):
478+ def get (ctx , name : str ): # noqa: F811
478479 """Get a specific agent."""
479480 client = ctx .obj ["client" ]
480481 result = client .get_agent (name )
@@ -496,7 +497,7 @@ def configs(ctx, type: str):
496497@click .option ("--type" , required = True , help = "Agent type" )
497498@click .option ("--pipeline" , required = True , help = "Pipeline index or name" )
498499@click .pass_context
499- def create (ctx , name : str , type : str , pipeline : str ):
500+ def create (ctx , name : str , type : str , pipeline : str ): # noqa: F811
500501 """Create an agent."""
501502 client = ctx .obj ["client" ]
502503 agent_data = {"name" : name , "type" : type , "pipeline_idx" : pipeline }
@@ -508,7 +509,7 @@ def create(ctx, name: str, type: str, pipeline: str):
508509@click .option ("-n" , "--name" , required = True , help = "Agent name" )
509510@click .option ("--active" , type = bool , help = "Active status" )
510511@click .pass_context
511- def update (ctx , name : str , active : Optional [bool ]):
512+ def update (ctx , name : str , active : Optional [bool ]): # noqa: F811
512513 """Update an agent."""
513514 client = ctx .obj ["client" ]
514515 agent_data = {}
@@ -521,7 +522,7 @@ def update(ctx, name: str, active: Optional[bool]):
521522@agent .command ()
522523@click .option ("-n" , "--name" , required = True , help = "Agent name" )
523524@click .pass_context
524- def delete (ctx , name : str ):
525+ def delete (ctx , name : str ): # noqa: F811
525526 """Delete an agent."""
526527 client = ctx .obj ["client" ]
527528 if click .confirm (f"Are you sure you want to delete agent '{ name } '?" ):
@@ -540,7 +541,7 @@ def prompt():
540541
541542@prompt .command ()
542543@click .pass_context
543- def get (ctx ):
544+ def get (ctx ): # noqa: F811
544545 """Get the current system prompt."""
545546 client = ctx .obj ["client" ]
546547 result = client .get_prompt ()
@@ -674,7 +675,7 @@ def session():
674675
675676@session .command ()
676677@click .pass_context
677- def list (ctx ):
678+ def list (ctx ): # noqa: F811
678679 """List all sessions."""
679680 client = ctx .obj ["client" ]
680681 result = client .get_sessions ()
@@ -684,7 +685,7 @@ def list(ctx):
684685@session .command ()
685686@click .option ("--id" , required = True , help = "Session ID" )
686687@click .pass_context
687- def get (ctx , id : str ):
688+ def get (ctx , id : str ): # noqa: F811
688689 """Get a specific session."""
689690 client = ctx .obj ["client" ]
690691 result = client .get_session (id )
0 commit comments