autocoder-nano 0.1.28__py3-none-any.whl → 0.1.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,11 +23,12 @@ from autocoder_nano.git_utils import (repo_init, commit_changes, revert_changes,
23
23
  get_uncommitted_changes, generate_commit_message)
24
24
  from autocoder_nano.sys_utils import default_exclude_dirs, detect_env
25
25
  from autocoder_nano.project import PyProject, SuffixProject
26
+ from autocoder_nano.utils.printer_utils import Printer
26
27
 
27
28
  import yaml
28
- import tabulate
29
+ # import tabulate
29
30
  from jinja2 import Template
30
- from loguru import logger
31
+ # from loguru import logger
31
32
  from prompt_toolkit import prompt as _toolkit_prompt, PromptSession
32
33
  from prompt_toolkit.completion import Completer, Completion
33
34
  from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
@@ -45,7 +46,9 @@ from rich.table import Table
45
46
  from rich.text import Text
46
47
 
47
48
 
48
- console = Console()
49
+ printer = Printer()
50
+ console = printer.get_console()
51
+ # console = Console()
49
52
  project_root = os.getcwd()
50
53
  base_persist_dir = os.path.join(project_root, ".auto-coder", "plugins", "chat-auto-coder")
51
54
  # defaut_exclude_dirs = [".git", ".svn", "node_modules", "dist", "build", "__pycache__", ".auto-coder", "actions",
@@ -792,12 +795,12 @@ def exclude_dirs(dir_names: List[str]):
792
795
  existing_dirs.extend(dirs_to_add)
793
796
  if "exclude_dirs" not in memory:
794
797
  memory["exclude_dirs"] = existing_dirs
795
- print(f"Added exclude dirs: {dirs_to_add}")
798
+ printer.print_text(Text(f"已添加排除目录: {dirs_to_add}", style="bold green"))
796
799
  for d in dirs_to_add:
797
800
  exclude_files(f"regex://.*/{d}/*.")
798
801
  # exclude_files([f"regex://.*/{d}/*." for d in dirs_to_add])
799
802
  else:
800
- print("All specified dirs are already in the exclude list.")
803
+ printer.print_text(Text(f"所有指定目录已在排除列表中. ", style="bold green"))
801
804
  save_memory()
802
805
  completer.refresh_files()
803
806
 
@@ -807,12 +810,12 @@ def exclude_files(query: str):
807
810
  query = query.replace("/list", "", 1).strip()
808
811
  existing_file_patterns = memory.get("exclude_files", [])
809
812
 
810
- # 打印表格
811
- table = Table(title="Exclude Files")
812
- table.add_column("File Pattern")
813
- for file_pattern in existing_file_patterns:
814
- table.add_row(file_pattern)
815
- console.print(table)
813
+ printer.print_table_compact(
814
+ headers=["File Pattern"],
815
+ data=[[file_pattern] for file_pattern in existing_file_patterns],
816
+ title="Exclude Files",
817
+ show_lines=False
818
+ )
816
819
  return
817
820
 
818
821
  if "/drop" in query:
@@ -843,16 +846,16 @@ def exclude_files(query: str):
843
846
  if "exclude_files" not in memory:
844
847
  memory["exclude_files"] = existing_file_patterns
845
848
  save_memory()
846
- print(f"Added exclude files: {file_patterns_to_add}")
849
+ printer.print_text(f"已添加排除文件: {file_patterns_to_add}. ", style="green")
847
850
  else:
848
- print("All specified files are already in the exclude list.")
851
+ printer.print_text(f"所有指定文件已在排除列表中. ", style="green")
849
852
 
850
853
 
851
854
  def index_command(llm):
852
855
  update_config_to_args(query="", delete_execute_file=True)
853
856
 
854
857
  source_dir = os.path.abspath(args.source_dir)
855
- logger.info(f"开始对目录 {source_dir} 中的源代码进行索引")
858
+ printer.print_text(f"开始对目录 {source_dir} 中的源代码进行索引", style="green")
856
859
  if args.project_type == "py":
857
860
  pp = PyProject(llm=llm, args=args)
858
861
  else:
@@ -867,7 +870,7 @@ def index_export(export_path: str) -> bool:
867
870
  try:
868
871
  index_path = os.path.join(project_root, ".auto-coder", "index.json")
869
872
  if not os.path.exists(index_path):
870
- console.print(f"索引文件不存在", style="bold red")
873
+ printer.print_text(Text(f"索引文件不存在. ", style="bold red"))
871
874
  return False
872
875
 
873
876
  with open(index_path, "r", encoding="utf-8") as f:
@@ -880,16 +883,16 @@ def index_export(export_path: str) -> bool:
880
883
  data["module_name"] = rel_path
881
884
  converted_data[rel_path] = data
882
885
  except ValueError:
883
- console.print(f"索引转换路径失败", style="bold yellow")
886
+ printer.print_text(Text(f"索引转换路径失败. ", style="dim yellow"))
884
887
  converted_data[abs_path] = data
885
888
 
886
889
  export_file = os.path.join(export_path, "index.json")
887
890
  with open(export_file, "w", encoding="utf-8") as f:
888
891
  json.dump(converted_data, f, indent=2)
889
- console.print(f"索引文件导出成功", style="bold green")
892
+ printer.print_text(Text(f"索引文件导出成功. ", style="bold green"))
890
893
  return True
891
894
  except Exception as err:
892
- console.print(f"索引文件导出失败", style="bold red")
895
+ printer.print_text(Text(f"索引文件导出失败: {err}", style="bold red"))
893
896
  return False
894
897
 
895
898
 
@@ -897,12 +900,10 @@ def index_import(import_path: str):
897
900
  try:
898
901
  import_file = os.path.join(import_path, "index.json")
899
902
  if not os.path.exists(import_file):
900
- console.print(f"导入索引文件不存在", style="bold red")
903
+ printer.print_text(Text(f"导入索引文件不存在", style="bold red"))
901
904
  return False
902
- # Read and convert paths
903
905
  with open(import_file, "r", encoding="utf-8") as f:
904
906
  index_data = json.load(f)
905
- # Convert relative paths to absolute
906
907
  converted_data = {}
907
908
  for rel_path, data in index_data.items():
908
909
  try:
@@ -910,12 +911,12 @@ def index_import(import_path: str):
910
911
  data["module_name"] = abs_path
911
912
  converted_data[abs_path] = data
912
913
  except Exception as err:
913
- console.print(f"索引转换路径失败: {err}", style="bold yellow")
914
+ printer.print_text(Text(f"{rel_path} 索引转换路径失败: {err}", style="dim yellow"))
914
915
  converted_data[rel_path] = data
915
916
  # Backup existing index
916
917
  index_path = os.path.join(project_root, ".auto-coder", "index.json")
917
918
  if os.path.exists(index_path):
918
- console.print(f"原索引文件不存在", style="bold yellow")
919
+ printer.print_text(Text(f"原索引文件不存在", style="bold yellow"))
919
920
  backup_path = index_path + ".bak"
920
921
  shutil.copy2(index_path, backup_path)
921
922
 
@@ -924,7 +925,7 @@ def index_import(import_path: str):
924
925
  json.dump(converted_data, f, indent=2)
925
926
  return True
926
927
  except Exception as err:
927
- console.print(f"索引文件导入失败: {err}", style="bold red")
928
+ printer.print_text(Text(f"索引文件导入失败: {err}", style="bold red"))
928
929
  return False
929
930
 
930
931
 
@@ -970,16 +971,23 @@ def index_query_command(query: str, llm: AutoLLM):
970
971
  final_files.extend(related_fiels.file_list)
971
972
 
972
973
  all_results = list({file.file_path: file for file in final_files}.values())
973
- logger.info(
974
- f"索引过滤级别: {args.index_filter_level},根据查询条件: {args.query}, 过滤后的文件数: {len(all_results)}"
974
+ printer.print_key_value(
975
+ {"索引过滤级别": f"{args.index_filter_level}", "查询条件": f"{args.query}", "过滤后的文件数": f"{len(all_results)}"},
976
+ panel=True
975
977
  )
976
978
 
977
- headers = TargetFile.model_fields.keys()
978
- table_data = wrap_text_in_table(
979
- [[getattr(file_item, name) for name in headers] for file_item in all_results]
979
+ # headers = TargetFile.model_fields.keys()
980
+ # table_data = wrap_text_in_table(
981
+ # [[getattr(file_item, name) for name in headers] for file_item in all_results]
982
+ # )
983
+ # table_output = tabulate.tabulate(table_data, headers, tablefmt="grid")
984
+ # print(table_output, flush=True)
985
+ printer.print_table_compact(
986
+ headers=["文件路径", "原因"],
987
+ data=[[_target_file.file_path, _target_file.reason] for _target_file in all_results],
988
+ title="Index Query 结果",
989
+ show_lines=True,
980
990
  )
981
- table_output = tabulate.tabulate(table_data, headers, tablefmt="grid")
982
- print(table_output, flush=True)
983
991
  return
984
992
 
985
993
 
@@ -1027,7 +1035,7 @@ def convert_config_value(key, value):
1027
1035
  else:
1028
1036
  return value
1029
1037
  else:
1030
- logger.error(f"无效的配置项: {key}")
1038
+ printer.print_text(f"无效的配置项: {key}", style="red")
1031
1039
  return None
1032
1040
 
1033
1041
 
@@ -1069,23 +1077,14 @@ def update_config_to_args(query, delete_execute_file: bool = False):
1069
1077
 
1070
1078
  def print_chat_history(history, max_entries=5):
1071
1079
  recent_history = history[-max_entries:]
1072
- table = Table(show_header=False, padding=(0, 1), expand=True, show_lines=True)
1073
- # 遍历聊天记录
1080
+ data_list = []
1074
1081
  for entry in recent_history:
1075
1082
  role = entry["role"]
1076
1083
  content = entry["content"]
1077
-
1078
- # 根据角色设置样式
1079
1084
  if role == "user":
1080
- role_text = Text("提问")
1085
+ printer.print_text(Text(content, style="bold red"))
1081
1086
  else:
1082
- role_text = Text("模型返回")
1083
- markdown_content = Markdown(content)
1084
- # 将内容和角色添加到表格中
1085
- table.add_row(role_text, markdown_content)
1086
- # 使用 Panel 包裹表格,增加美观性
1087
- panel = Panel(table, title="历史聊天记录", border_style="bold yellow")
1088
- console.print(panel)
1087
+ printer.print_markdown(content, panel=True)
1089
1088
 
1090
1089
 
1091
1090
  @prompt()
@@ -1144,13 +1143,10 @@ def chat(query: str, llm: AutoLLM):
1144
1143
  json_str = json.dumps(chat_history, ensure_ascii=False)
1145
1144
  fp.write(json_str)
1146
1145
 
1147
- console.print(
1148
- Panel(
1149
- "新会话已开始, 之前的聊天历史已存档。",
1150
- title="Session Status",
1151
- expand=False,
1152
- border_style="green",
1153
- )
1146
+ printer.print_panel(
1147
+ Text("新会话已开始, 之前的聊天历史已存档.", style="green"),
1148
+ title="Session Status",
1149
+ center=True
1154
1150
  )
1155
1151
  if not query:
1156
1152
  return
@@ -1209,7 +1205,7 @@ def chat(query: str, llm: AutoLLM):
1209
1205
  assistant_response = ""
1210
1206
 
1211
1207
  try:
1212
- with Live(Panel("", title="Response"), refresh_per_second=12) as live:
1208
+ with Live(Panel("", title="Response", style="cyan"), refresh_per_second=12) as live:
1213
1209
  for chunk in v:
1214
1210
  if chunk.choices and chunk.choices[0].delta.content:
1215
1211
  content = chunk.choices[0].delta.content
@@ -1231,7 +1227,7 @@ def chat(query: str, llm: AutoLLM):
1231
1227
  display_content = '\n'.join(lines_buffer[-MAX_HISTORY_LINES:] + [current_line])
1232
1228
 
1233
1229
  live.update(
1234
- Panel(Markdown(display_content), title="模型返回", border_style="green",
1230
+ Panel(Markdown(display_content), title="模型返回", border_style="cyan",
1235
1231
  height=min(25, live.console.height - 4))
1236
1232
  )
1237
1233
 
@@ -1241,10 +1237,10 @@ def chat(query: str, llm: AutoLLM):
1241
1237
 
1242
1238
  # 最终完整渲染
1243
1239
  live.update(
1244
- Panel(Markdown(assistant_response), title="模型返回", border_style="blue")
1240
+ Panel(Markdown(assistant_response), title="模型返回", border_style="dim blue")
1245
1241
  )
1246
1242
  except Exception as e:
1247
- logger.error(str(e))
1243
+ printer.print_panel(Text(f"{str(e)}", style="red"), title="模型返回", center=True)
1248
1244
 
1249
1245
  chat_history["ask_conversation"].append({"role": "assistant", "content": assistant_response})
1250
1246
 
@@ -1257,8 +1253,8 @@ def chat(query: str, llm: AutoLLM):
1257
1253
 
1258
1254
  def init_project():
1259
1255
  if not args.project_type:
1260
- logger.error(
1261
- "请指定项目类型。可选的项目类型包括:py|ts| 或其他文件扩展名(例如:.java,.scala), 多个扩展名可用逗号分隔。"
1256
+ printer.print_text(
1257
+ f"请指定项目类型。可选的项目类型包括:py|ts| 或文件扩展名(例如:.java,.scala), 多个扩展名逗号分隔.", style="green"
1262
1258
  )
1263
1259
  return
1264
1260
  os.makedirs(os.path.join(args.source_dir, "actions"), exist_ok=True)
@@ -1276,7 +1272,7 @@ def init_project():
1276
1272
  f.write("\nactions/")
1277
1273
  f.write("\noutput.txt")
1278
1274
 
1279
- logger.info(f"已在 {os.path.abspath(args.source_dir)} 成功初始化 autocoder-nano 项目(兼容autocoder)")
1275
+ printer.print_text(f"已在 {os.path.abspath(args.source_dir)} 成功初始化 autocoder-nano 项目", style="green")
1280
1276
  return
1281
1277
 
1282
1278
 
@@ -1311,11 +1307,11 @@ def load_include_files(config, base_path, max_depth=10, current_depth=0):
1311
1307
 
1312
1308
  for include_file in include_files:
1313
1309
  abs_include_path = resolve_include_path(base_path, include_file)
1314
- logger.info(f"正在加载 Include file: {abs_include_path}")
1310
+ printer.print_text(f"正在加载 Include file: {abs_include_path}", style="green")
1315
1311
  with open(abs_include_path, "r") as f:
1316
1312
  include_config = yaml.safe_load(f)
1317
1313
  if not include_config:
1318
- logger.info(f"Include file {abs_include_path} 为空,跳过处理。")
1314
+ printer.print_text(f"Include file {abs_include_path} 为空,跳过处理.", style="green")
1319
1315
  continue
1320
1316
  config.update(
1321
1317
  {
@@ -1331,7 +1327,7 @@ def prepare_chat_yaml():
1331
1327
  # auto_coder_main(["next", "chat_action"]) 准备聊天 yaml 文件
1332
1328
  actions_dir = os.path.join(args.source_dir, "actions")
1333
1329
  if not os.path.exists(actions_dir):
1334
- logger.warning("当前目录中未找到 actions 目录。请执行初始化 AutoCoder Nano")
1330
+ printer.print_text("当前目录中未找到 actions 目录。请执行初始化 AutoCoder Nano", style="yellow")
1335
1331
  return
1336
1332
 
1337
1333
  action_files = [
@@ -1362,7 +1358,7 @@ def prepare_chat_yaml():
1362
1358
  with open(new_file, "w") as f:
1363
1359
  f.write(content)
1364
1360
 
1365
- logger.info(f"已成功创建新的 action 文件: {new_file}")
1361
+ printer.print_text(f"已成功创建新的 action 文件: {new_file}", style="green")
1366
1362
  return
1367
1363
 
1368
1364
 
@@ -1421,9 +1417,8 @@ def coding(query: str, llm: AutoLLM):
1421
1417
  memory_file = os.path.join(memory_dir, "chat_history.json")
1422
1418
 
1423
1419
  def error_message():
1424
- console.print(
1425
- Panel("No chat history found to apply.", title="Chat History",
1426
- expand=False, border_style="yellow",)
1420
+ printer.print_panel(
1421
+ Text("No chat history found to apply.", style="yellow"), title="Chat History", center=True
1427
1422
  )
1428
1423
 
1429
1424
  if not os.path.exists(memory_file):
@@ -1456,7 +1451,7 @@ def coding(query: str, llm: AutoLLM):
1456
1451
  dispacher = Dispacher(args=args, llm=llm)
1457
1452
  dispacher.dispach()
1458
1453
  else:
1459
- logger.warning("创建新的 YAML 文件失败。")
1454
+ printer.print_text(f"创建新的 YAML 文件失败.", style="yellow")
1460
1455
 
1461
1456
  save_memory()
1462
1457
  completer.refresh_files()
@@ -1472,9 +1467,9 @@ def execute_revert():
1472
1467
  revert_result = revert_changes(repo_path, f"auto_coder_{file_name}_{md5}")
1473
1468
  if revert_result:
1474
1469
  os.remove(args.file)
1475
- logger.info(f"已成功回退最后一次 chat action 的更改,并移除 YAML 文件 {args.file}")
1470
+ printer.print_text(f"已成功回退最后一次 chat action 的更改,并移除 YAML 文件 {args.file}", style="green")
1476
1471
  else:
1477
- logger.error(f"回退文件 {args.file} 的更改失败")
1472
+ printer.print_text(f"回退文件 {args.file} 的更改失败", style="red")
1478
1473
  return
1479
1474
 
1480
1475
 
@@ -1485,29 +1480,24 @@ def revert():
1485
1480
  convert_yaml_to_config(file_path)
1486
1481
  execute_revert()
1487
1482
  else:
1488
- logger.warning("No previous chat action found to revert.")
1483
+ printer.print_text(f"No previous chat action found to revert.", style="yellow")
1489
1484
 
1490
1485
 
1491
1486
  def print_commit_info(commit_result: CommitResult):
1492
- table = Table(title="提交信息 (使用 /revert 撤销此提交)", show_header=True, header_style="bold magenta")
1493
- table.add_column("属性", style="cyan", no_wrap=True)
1494
- table.add_column("", style="green")
1495
- table.add_row("提交哈希", commit_result.commit_hash)
1496
- table.add_row("提交信息", commit_result.commit_message)
1497
- table.add_row(
1498
- "更改的文件",
1499
- "\n".join(commit_result.changed_files) if commit_result.changed_files else "No files changed"
1500
- )
1501
-
1502
- console.print(
1503
- Panel(table, expand=False, border_style="green", title="Git 提交摘要")
1487
+ printer.print_table_compact(
1488
+ data=[
1489
+ ["提交哈希", commit_result.commit_hash],
1490
+ ["提交信息", commit_result.commit_message],
1491
+ ["更改的文件", "\n".join(commit_result.changed_files) if commit_result.changed_files else "No files changed"]
1492
+ ],
1493
+ title="提交信息", headers=["属性", "值"], caption="(使用 /revert 撤销此提交)"
1504
1494
  )
1505
1495
 
1506
1496
  if commit_result.diffs:
1507
1497
  for file, diff in commit_result.diffs.items():
1508
- console.print(f"\n[bold blue]File: {file}[/bold blue]")
1498
+ printer.print_text(f"File: {file}", style="green")
1509
1499
  syntax = Syntax(diff, "diff", theme="monokai", line_numbers=True)
1510
- console.print(Panel(syntax, expand=False, border_style="yellow", title="File Diff"))
1500
+ printer.print_panel(syntax, title="File Diff", center=True)
1511
1501
 
1512
1502
 
1513
1503
  def commit_info(query: str, llm: AutoLLM):
@@ -1550,7 +1540,7 @@ def commit_info(query: str, llm: AutoLLM):
1550
1540
  # commit_message = ""
1551
1541
  commit_llm = llm
1552
1542
  commit_llm.setup_default_model_name(args.chat_model)
1553
- console.print(f"Commit 信息生成中...", style="yellow")
1543
+ printer.print_text(f"Commit 信息生成中...", style="green")
1554
1544
 
1555
1545
  try:
1556
1546
  uncommitted_changes = get_uncommitted_changes(repo_path)
@@ -1559,7 +1549,7 @@ def commit_info(query: str, llm: AutoLLM):
1559
1549
  )
1560
1550
  memory["conversation"].append({"role": "user", "content": commit_message.output})
1561
1551
  except Exception as err:
1562
- console.print(f"Commit 信息生成失败: {err}", style="red")
1552
+ printer.print_text(f"Commit 信息生成失败: {err}", style="red")
1563
1553
  return
1564
1554
 
1565
1555
  yaml_config["query"] = commit_message.output
@@ -1573,11 +1563,11 @@ def commit_info(query: str, llm: AutoLLM):
1573
1563
  commit_result = commit_changes(repo_path, f"auto_coder_nano_{file_name}_{md5}\n{commit_message}")
1574
1564
  print_commit_info(commit_result=commit_result)
1575
1565
  if commit_message:
1576
- console.print(f"Commit 成功", style="green")
1566
+ printer.print_text(f"Commit 成功", style="green")
1577
1567
  except Exception as err:
1578
1568
  import traceback
1579
1569
  traceback.print_exc()
1580
- logger.error(f"Commit 失败: {err}")
1570
+ printer.print_text(f"Commit 失败: {err}", style="red")
1581
1571
  if execute_file:
1582
1572
  os.remove(execute_file)
1583
1573
 
@@ -1622,22 +1612,14 @@ def generate_shell_command(input_text: str, llm: AutoLLM) -> str | None:
1622
1612
  update_config_to_args(query=input_text, delete_execute_file=True)
1623
1613
 
1624
1614
  try:
1625
- console.print(
1626
- Panel(
1627
- f"正在根据用户输入 {input_text} 生成 Shell 脚本...",
1628
- title="命令生成",
1629
- border_style="green",
1630
- )
1615
+ printer.print_panel(
1616
+ Text(f"正在根据用户输入 {input_text} 生成 Shell 脚本...", style="green"), title="命令生成",
1631
1617
  )
1632
1618
  llm.setup_default_model_name(args.code_model)
1633
1619
  result = _generate_shell_script.with_llm(llm).run(user_input=input_text)
1634
1620
  shell_script = extract_code(result.output)[0][1]
1635
- console.print(
1636
- Panel(
1637
- shell_script,
1638
- title="Shell 脚本",
1639
- border_style="magenta",
1640
- )
1621
+ printer.print_code(
1622
+ code=shell_script, lexer="shell", panel=True
1641
1623
  )
1642
1624
  return shell_script
1643
1625
  finally:
@@ -1668,31 +1650,31 @@ def execute_shell_command(command: str):
1668
1650
  output.append(output_line.strip())
1669
1651
  live.update(
1670
1652
  Panel(
1671
- Text("\n".join(output[-20:])),
1653
+ Text("\n".join(output[-20:]), style="green"),
1672
1654
  title="Shell 输出",
1673
- border_style="green",
1655
+ border_style="dim blue",
1674
1656
  )
1675
1657
  )
1676
1658
  if error_line:
1677
1659
  output.append(f"ERROR: {error_line.strip()}")
1678
1660
  live.update(
1679
1661
  Panel(
1680
- Text("\n".join(output[-20:])),
1662
+ Text("\n".join(output[-20:]), style="red"),
1681
1663
  title="Shell 输出",
1682
- border_style="red",
1664
+ border_style="dim blue",
1683
1665
  )
1684
1666
  )
1685
1667
  if output_line == "" and error_line == "" and process.poll() is not None:
1686
1668
  break
1687
1669
 
1688
1670
  if process.returncode != 0:
1689
- console.print(f"[bold red]命令执行失败,返回码: {process.returncode}[/bold red]")
1671
+ printer.print_text(f"命令执行失败,返回码: {process.returncode}", style="red")
1690
1672
  else:
1691
- console.print("[bold green]命令执行成功[/bold green]")
1673
+ printer.print_text(f"命令执行成功", style="green")
1692
1674
  except FileNotFoundError:
1693
- console.print(f"[bold red]未找到命令:[/bold red] [yellow]{command}[/yellow]")
1675
+ printer.print_text(f"未找到命令:", style="yellow")
1694
1676
  except subprocess.SubprocessError as e:
1695
- console.print(f"[bold red]命令执行错误:[/bold red] [yellow]{str(e)}[/yellow]")
1677
+ printer.print_text(f"命令执行错误:", style="yellow")
1696
1678
 
1697
1679
 
1698
1680
  def parse_args(input_args: Optional[List[str]] = None):
@@ -1844,10 +1826,10 @@ def configure_project_type() -> str:
1844
1826
  print_info("项目类型支持:")
1845
1827
  print_info(" - 语言后缀(例如:.py, .java, .ts)")
1846
1828
  print_info(" - 预定义类型:py(Python), ts(TypeScript/JavaScript)")
1847
- print_info("对于混合语言项目,使用逗号分隔的值。")
1829
+ print_info("对于混合语言项目,使用逗号分隔的值.")
1848
1830
  print_info("示例:'.java,.scala' 或 '.py,.ts'")
1849
1831
 
1850
- print_warning(f"如果留空,默认为 'py'。\n")
1832
+ print_warning(f"如果留空, 默认为 'py'.\n")
1851
1833
 
1852
1834
  project_type = _toolkit_prompt("请输入项目类型:", default="py", style=style).strip()
1853
1835
 
@@ -1864,45 +1846,34 @@ def configure_project_type() -> str:
1864
1846
  return project_type
1865
1847
 
1866
1848
 
1867
- def print_status(message, status):
1868
- if status == "success":
1869
- print(f"\033[32m✓ {message}\033[0m")
1870
- elif status == "warning":
1871
- print(f"\033[33m! {message}\033[0m")
1872
- elif status == "error":
1873
- print(f"\033[31m✗ {message}\033[0m")
1874
- else:
1875
- print(f" {message}")
1876
-
1877
-
1878
1849
  def initialize_system():
1879
- print(f"\n\033[1;34m🚀 正在初始化系统...\033[0m")
1850
+ printer.print_text(f"🚀 正在初始化系统...", style="green")
1880
1851
 
1881
1852
  def _init_project():
1882
1853
  first_time = False
1883
1854
  if not os.path.exists(os.path.join(args.source_dir, ".auto-coder")):
1884
1855
  first_time = True
1885
- print_status("当前目录未初始化为auto-coder项目。", "warning")
1856
+ printer.print_text("当前目录未初始化为auto-coder项目.", style="yellow")
1886
1857
  init_choice = input(f" 是否现在初始化项目?(y/n): ").strip().lower()
1887
1858
  if init_choice == "y":
1888
1859
  try:
1889
1860
  init_project()
1890
- print_status("项目初始化成功。", "success")
1861
+ printer.print_text("项目初始化成功.", style="green")
1891
1862
  except Exception as e:
1892
- print_status(f"项目初始化失败, {str(e)}", "error")
1863
+ printer.print_text(f"项目初始化失败, {str(e)}.", style="red")
1893
1864
  exit(1)
1894
1865
  else:
1895
- print_status("退出而不初始化。", "warning")
1866
+ printer.print_text("退出而不初始化.", style="yellow")
1896
1867
  exit(1)
1897
1868
 
1898
1869
  if not os.path.exists(base_persist_dir):
1899
1870
  os.makedirs(base_persist_dir, exist_ok=True)
1900
- print_status("创建目录:{}".format(base_persist_dir), "success")
1871
+ printer.print_text("创建目录:{}".format(base_persist_dir), style="green")
1901
1872
 
1902
1873
  if first_time: # 首次启动,配置项目类型
1903
1874
  configure_project_type()
1904
1875
 
1905
- print_status("项目初始化完成。", "success")
1876
+ printer.print_text("项目初始化完成.", style="green")
1906
1877
 
1907
1878
  _init_project()
1908
1879
 
@@ -1918,70 +1889,49 @@ def add_files(add_files_args: List[str]):
1918
1889
  groups_info = memory["current_files"]["groups_info"]
1919
1890
 
1920
1891
  if not add_files_args:
1921
- console.print(
1922
- Panel("请为 /add_files 命令提供参数.", title="错误", border_style="red")
1923
- )
1892
+ printer.print_panel(Text("请为 /add_files 命令提供参数.", style="red"), title="错误", center=True)
1924
1893
  return
1925
1894
 
1926
1895
  if add_files_args[0] == "/refresh": # 刷新
1927
1896
  completer.refresh_files()
1928
1897
  load_memory()
1929
- console.print(
1930
- Panel("已刷新的文件列表.", title="文件刷新", border_style="green")
1931
- )
1898
+ printer.print_panel(Text("已刷新的文件列表.", style="green"), title="文件刷新", center=True)
1932
1899
  return
1933
1900
 
1934
1901
  if add_files_args[0] == "/group":
1935
1902
  # 列出组
1936
1903
  if len(add_files_args) == 1 or (len(add_files_args) == 2 and add_files_args[1] == "list"):
1937
1904
  if not groups:
1938
- console.print(
1939
- Panel("未定义任何文件组.", title="文件组",
1940
- border_style="yellow")
1941
- )
1905
+ printer.print_panel(Text("未定义任何文件组.", style="yellow"), title="文件组", center=True)
1942
1906
  else:
1943
- table = Table(
1944
- title="已定义文件组",
1945
- show_header=True,
1946
- header_style="bold magenta",
1947
- show_lines=True,
1948
- )
1949
- table.add_column("Group Name", style="cyan", no_wrap=True)
1950
- table.add_column("Files", style="green")
1951
- table.add_column("Query Prefix", style="yellow")
1952
- table.add_column("Active", style="magenta")
1953
-
1907
+ data_list = []
1954
1908
  for i, (group_name, files) in enumerate(groups.items()):
1955
1909
  query_prefix = groups_info.get(group_name, {}).get("query_prefix", "")
1956
1910
  is_active = ("✓" if group_name in memory["current_files"]["current_groups"] else "")
1957
- table.add_row(
1911
+ data_list.append([
1958
1912
  group_name,
1959
1913
  "\n".join([os.path.relpath(f, project_root) for f in files]),
1960
1914
  query_prefix,
1961
- is_active,
1962
- end_section=(i == len(groups) - 1),
1963
- )
1964
- console.print(Panel(table, border_style="blue")) #
1915
+ is_active
1916
+ ])
1917
+ printer.print_table_compact(
1918
+ data=data_list,
1919
+ title="已定义文件组",
1920
+ headers=["Group Name", "Files", "Query Prefix", "Active"]
1921
+ )
1965
1922
  # 重置活动组
1966
1923
  elif len(add_files_args) >= 2 and add_files_args[1] == "/reset":
1967
1924
  memory["current_files"]["current_groups"] = []
1968
- console.print(
1969
- Panel(
1970
- "活动组名称已重置。如果你想清除活动文件,可使用命令 /remove_files /all .",
1971
- title="活动组重置",
1972
- border_style="green",
1973
- )
1925
+ printer.print_panel(
1926
+ Text("活动组名称已重置。如果你想清除活动文件,可使用命令 /remove_files /all .", style="green"),
1927
+ title="活动组重置", center=True
1974
1928
  )
1975
1929
  # 新增组
1976
1930
  elif len(add_files_args) >= 3 and add_files_args[1] == "/add":
1977
1931
  group_name = add_files_args[2]
1978
1932
  groups[group_name] = memory["current_files"]["files"].copy()
1979
- console.print(
1980
- Panel(
1981
- f"已将当前文件添加到组 '{group_name}' .",
1982
- title="新增组",
1983
- border_style="green",
1984
- )
1933
+ printer.print_panel(
1934
+ Text(f"已将当前文件添加到组 '{group_name}' .", style="green"), title="新增组", center=True
1985
1935
  )
1986
1936
  # 删除组
1987
1937
  elif len(add_files_args) >= 3 and add_files_args[1] == "/drop":
@@ -1992,20 +1942,12 @@ def add_files(add_files_args: List[str]):
1992
1942
  del memory["current_files"]["groups_info"][group_name]
1993
1943
  if group_name in memory["current_files"]["current_groups"]:
1994
1944
  memory["current_files"]["current_groups"].remove(group_name)
1995
- console.print(
1996
- Panel(
1997
- f"已删除组 '{group_name}'.",
1998
- title="删除组",
1999
- border_style="green",
2000
- )
1945
+ printer.print_panel(
1946
+ Text(f"已删除组 '{group_name}'.", style="green"), title="删除组", center=True
2001
1947
  )
2002
1948
  else:
2003
- console.print(
2004
- Panel(
2005
- f"组 '{group_name}' 未找到.",
2006
- title="Error",
2007
- border_style="red",
2008
- )
1949
+ printer.print_panel(
1950
+ Text(f"组 '{group_name}' 未找到.", style="red"), title="Error", center=True
2009
1951
  )
2010
1952
  # 支持多个组的合并,允许组名之间使用逗号或空格分隔
2011
1953
  elif len(add_files_args) >= 2:
@@ -2018,54 +1960,29 @@ def add_files(add_files_args: List[str]):
2018
1960
  else:
2019
1961
  missing_groups.append(group_name)
2020
1962
  if missing_groups:
2021
- console.print(
2022
- Panel(
2023
- f"未找到组: {', '.join(missing_groups)}",
2024
- title="Error",
2025
- border_style="red",
2026
- )
1963
+ printer.print_panel(
1964
+ Text(f"未找到组: {', '.join(missing_groups)}", style="red"), title="Error", center=True
2027
1965
  )
2028
1966
  if merged_files:
2029
1967
  memory["current_files"]["files"] = list(merged_files)
2030
1968
  memory["current_files"]["current_groups"] = [
2031
1969
  name for name in group_names if name in groups
2032
1970
  ]
2033
- console.print(
2034
- Panel(
2035
- f"合并来自组 {', '.join(group_names)} 的文件 .",
2036
- title="文件合并",
2037
- border_style="green",
2038
- )
1971
+ printer.print_panel(
1972
+ Text(f"合并来自组 {', '.join(group_names)} 的文件 .", style="green"), title="文件合并", center=True
2039
1973
  )
2040
- table = Table(
1974
+ printer.print_table_compact(
1975
+ data=[[os.path.relpath(f, project_root)] for f in memory["current_files"]["files"]],
2041
1976
  title="当前文件",
2042
- show_header=True,
2043
- header_style="bold magenta",
2044
- show_lines=True, # 这会在每行之间添加分割线
1977
+ headers=["File"]
2045
1978
  )
2046
- table.add_column("File", style="green")
2047
- for i, f in enumerate(memory["current_files"]["files"]):
2048
- table.add_row(
2049
- os.path.relpath(f, project_root),
2050
- end_section=(
2051
- i == len(memory["current_files"]["files"]) - 1
2052
- ), # 在最后一行之后不添加分割线
2053
- )
2054
- console.print(Panel(table, border_style="blue"))
2055
- console.print(
2056
- Panel(
2057
- f"当前组: {', '.join(memory['current_files']['current_groups'])}",
2058
- title="当前组",
2059
- border_style="green",
2060
- )
1979
+ printer.print_panel(
1980
+ Text(f"当前组: {', '.join(memory['current_files']['current_groups'])}", style="green"),
1981
+ title="当前组", center=True
2061
1982
  )
2062
1983
  elif not missing_groups:
2063
- console.print(
2064
- Panel(
2065
- "指定组中没有文件.",
2066
- title="未添加任何文件",
2067
- border_style="yellow",
2068
- )
1984
+ printer.print_panel(
1985
+ Text(f"指定组中没有文件.", style="yellow"), title="未添加任何文件", center=True
2069
1986
  )
2070
1987
 
2071
1988
  else:
@@ -2075,26 +1992,14 @@ def add_files(add_files_args: List[str]):
2075
1992
  files_to_add = [f for f in matched_files if f not in existing_files]
2076
1993
  if files_to_add:
2077
1994
  memory["current_files"]["files"].extend(files_to_add)
2078
- table = Table(
1995
+ printer.print_table_compact(
1996
+ data=[[os.path.relpath(f, project_root)] for f in files_to_add],
2079
1997
  title="新增文件",
2080
- show_header=True,
2081
- header_style="bold magenta",
2082
- show_lines=True, # 这会在每行之间添加分割线
1998
+ headers=["文件"]
2083
1999
  )
2084
- table.add_column("File", style="green")
2085
- for i, f in enumerate(files_to_add):
2086
- table.add_row(
2087
- os.path.relpath(f, project_root),
2088
- end_section=(i == len(files_to_add) - 1), # 在最后一行之后不添加分割线
2089
- )
2090
- console.print(Panel(table, border_style="green"))
2091
2000
  else:
2092
- console.print(
2093
- Panel(
2094
- "所有指定文件已存在于当前会话中,或者未找到匹配的文件.",
2095
- title="未新增文件",
2096
- border_style="yellow",
2097
- )
2001
+ printer.print_panel(
2002
+ Text(f"所有指定文件已存在于当前会话中,或者未找到匹配的文件.", style="yellow"), title="未新增文件", center=True
2098
2003
  )
2099
2004
 
2100
2005
  completer.update_current_files(memory["current_files"]["files"])
@@ -2105,7 +2010,7 @@ def remove_files(file_names: List[str]):
2105
2010
  if "/all" in file_names:
2106
2011
  memory["current_files"]["files"] = []
2107
2012
  memory["current_files"]["current_groups"] = []
2108
- console.print(Panel("已移除所有文件。", title="文件移除", border_style="green"))
2013
+ printer.print_panel("已移除所有文件", title="文件移除", center=True)
2109
2014
  else:
2110
2015
  removed_files = []
2111
2016
  for file in memory["current_files"]["files"]:
@@ -2117,13 +2022,13 @@ def remove_files(file_names: List[str]):
2117
2022
  memory["current_files"]["files"].remove(file)
2118
2023
 
2119
2024
  if removed_files:
2120
- table = Table(title="文件移除", show_header=True, header_style="bold magenta")
2121
- table.add_column("File", style="green")
2122
- for f in removed_files:
2123
- table.add_row(os.path.relpath(f, project_root))
2124
- console.print(Panel(table, border_style="green"))
2025
+ printer.print_table_compact(
2026
+ data=[[os.path.relpath(f, project_root)] for f in removed_files],
2027
+ title="文件移除",
2028
+ headers=["File"]
2029
+ )
2125
2030
  else:
2126
- console.print(Panel("未移除任何文件。", title="未移除文件", border_style="yellow"))
2031
+ printer.print_panel("未移除任何文件", title="未移除文件", border_style="dim yellow", center=True)
2127
2032
  completer.update_current_files(memory["current_files"]["files"])
2128
2033
  save_memory()
2129
2034
 
@@ -2132,21 +2037,17 @@ def list_files():
2132
2037
  current_files = memory["current_files"]["files"]
2133
2038
 
2134
2039
  if current_files:
2135
- table = Table(
2136
- title="当前活跃文件", show_header=True, header_style="bold magenta"
2040
+ printer.print_table_compact(
2041
+ data=[[os.path.relpath(file, project_root)] for file in current_files],
2042
+ title="当前活跃文件",
2043
+ headers=["File"]
2137
2044
  )
2138
- table.add_column("File", style="green")
2139
- for file in current_files:
2140
- table.add_row(os.path.relpath(file, project_root))
2141
- console.print(Panel(table, border_style="blue"))
2142
2045
  else:
2143
- console.print(Panel("当前会话中无文件。", title="当前文件", border_style="yellow"))
2046
+ printer.print_panel("当前会话中无文件。", title="当前文件", center=True)
2144
2047
 
2145
2048
 
2146
2049
  def print_conf(content: Dict[str, Any]):
2147
- table = Table(title=f"[italic]使用 /conf <key>:<value> 修改这些设置[/italic]", expand=True, show_lines=True)
2148
- table.add_column("键", style="cyan", justify="right", width=30, no_wrap=True)
2149
- table.add_column("值", style="green", justify="left", width=50, no_wrap=True)
2050
+ data_list = []
2150
2051
  for key in sorted(content.keys()):
2151
2052
  value = content[key]
2152
2053
  # Format value based on type
@@ -2158,31 +2059,32 @@ def print_conf(content: Dict[str, Any]):
2158
2059
  formatted_value = Text(str(value), style="bright_cyan")
2159
2060
  else:
2160
2061
  formatted_value = Text(str(value), style="green")
2161
- table.add_row(str(key), formatted_value)
2162
- console.print(table)
2062
+ data_list.append([str(key), formatted_value])
2063
+ printer.print_table_compact(
2064
+ data=data_list,
2065
+ title="Conf 配置",
2066
+ headers=["键", "值"],
2067
+ caption="使用 /conf <key>:<value> 修改这些设置"
2068
+ )
2163
2069
 
2164
2070
 
2165
2071
  def print_models(content: Dict[str, Any]):
2166
- table = Table(title="模型", expand=True, show_lines=True)
2167
- table.add_column("Name", style="cyan", width=40, no_wrap=False)
2168
- table.add_column("Model Name", style="magenta", width=30, overflow="fold")
2169
- table.add_column("Base URL", style="white", width=50, overflow="fold")
2072
+ data_list = []
2170
2073
  if content:
2171
2074
  for name in content:
2172
- table.add_row(
2173
- name,
2174
- content[name].get("model", ""),
2175
- content[name].get("base_url", "")
2176
- )
2075
+ data_list.append([name, content[name].get("model", ""), content[name].get("base_url", "")])
2177
2076
  else:
2178
- table.add_row("", "", "")
2179
- console.print(table)
2077
+ data_list.append(["", "", ""])
2078
+ printer.print_table_compact(
2079
+ headers=["Name", "Model Name", "Base URL"],
2080
+ title="模型列表",
2081
+ data=data_list,
2082
+ show_lines=True,
2083
+ expand=True
2084
+ )
2180
2085
 
2181
2086
 
2182
2087
  def check_models(content: Dict[str, Any], llm: AutoLLM):
2183
-
2184
- status_info = {}
2185
-
2186
2088
  def _check_single_llm(model):
2187
2089
  _start_time = time.monotonic()
2188
2090
  try:
@@ -2196,25 +2098,21 @@ def check_models(content: Dict[str, Any], llm: AutoLLM):
2196
2098
  except Exception as e:
2197
2099
  return False, str(e)
2198
2100
 
2199
- table = Table(title="模型状态检测", show_header=True, header_style="bold magenta")
2200
- table.add_column("模型", style="cyan")
2201
- table.add_column("状态", justify="center")
2202
- table.add_column("延迟", justify="right", style="green")
2101
+ data_list = []
2203
2102
  if content:
2204
2103
  for name in content:
2205
- logger.info(f"正在测试 {name} 模型")
2206
2104
  attempt_ok, attempt_latency = _check_single_llm(name)
2207
2105
  if attempt_ok:
2208
- table.add_row(
2209
- name, Text("✓", style="green"), f"{attempt_latency:.2f}s"
2210
- )
2106
+ data_list.append([name, Text("✓", style="green"), f"{attempt_latency:.2f}s"])
2211
2107
  else:
2212
- table.add_row(
2213
- "✗", Text("✓", style="red"), "-"
2214
- )
2108
+ data_list.append([name, Text("✗", style="red"), "-"])
2215
2109
  else:
2216
- table.add_row("", "", "")
2217
- console.print(table)
2110
+ data_list.append(["", "", ""])
2111
+ printer.print_table_compact(
2112
+ headers=["模型名称", "状态", "延迟情况"],
2113
+ title="模型状态检测",
2114
+ data=data_list
2115
+ )
2218
2116
 
2219
2117
 
2220
2118
  def manage_models(models_args, models_data, llm: AutoLLM):
@@ -2232,30 +2130,30 @@ def manage_models(models_args, models_data, llm: AutoLLM):
2232
2130
  elif models_args[0] == "/add_model":
2233
2131
  add_model_args = models_args[1:]
2234
2132
  add_model_info = {item.split('=')[0]: item.split('=')[1] for item in add_model_args if item}
2235
- _name = add_model_info["name"]
2236
- logger.info(f"正在为 {_name} 更新缓存信息")
2237
- if _name not in memory["models"]:
2238
- memory["models"][_name] = {
2133
+ mn = add_model_info["name"]
2134
+ printer.print_text(f"正在为 {mn} 更新缓存信息", style="green")
2135
+ if mn not in memory["models"]:
2136
+ memory["models"][mn] = {
2239
2137
  "base_url": add_model_info["base_url"],
2240
2138
  "api_key": add_model_info["api_key"],
2241
2139
  "model": add_model_info["model"]
2242
2140
  }
2243
2141
  else:
2244
- logger.error(f"{_name} 已经存在, 请执行 /models /remove <name> 进行删除")
2245
- logger.info(f"正在部署 {_name} 模型")
2246
- llm.setup_sub_client(_name, add_model_info["api_key"], add_model_info["base_url"], add_model_info["model"])
2142
+ printer.print_text(f"{mn} 已经存在, 请执行 /models /remove <name> 进行删除", style="red")
2143
+ printer.print_text(f"正在部署 {mn} 模型", style="green")
2144
+ llm.setup_sub_client(mn, add_model_info["api_key"], add_model_info["base_url"], add_model_info["model"])
2247
2145
  elif models_args[0] == "/remove":
2248
- remove_model_name = models_args[1]
2249
- logger.info(f"正在清理 {remove_model_name} 缓存信息")
2250
- if remove_model_name in memory["models"]:
2251
- del memory["models"][remove_model_name]
2252
- logger.info(f"正在卸载 {remove_model_name} 模型")
2253
- if llm.get_sub_client(remove_model_name):
2254
- llm.remove_sub_client(remove_model_name)
2255
- if remove_model_name == memory["conf"]["chat_model"]:
2256
- logger.warning(f"当前首选 Chat 模型 {remove_model_name} 已被删除, 请立即 /conf chat_model: 调整 !!!")
2257
- if remove_model_name == memory["conf"]["code_model"]:
2258
- logger.warning(f"当前首选 Code 模型 {remove_model_name} 已被删除, 请立即 /conf code_model: 调整 !!!")
2146
+ rmn = models_args[1]
2147
+ printer.print_text(f"正在清理 {rmn} 缓存信息", style="green")
2148
+ if rmn in memory["models"]:
2149
+ del memory["models"][rmn]
2150
+ printer.print_text(f"正在卸载 {rmn} 模型", style="green")
2151
+ if llm.get_sub_client(rmn):
2152
+ llm.remove_sub_client(rmn)
2153
+ if rmn == memory["conf"]["chat_model"]:
2154
+ printer.print_text(f"当前首选Chat模型 {rmn} 已被删除, 请立即 /conf chat_model: 调整", style="yellow")
2155
+ if rmn == memory["conf"]["code_model"]:
2156
+ printer.print_text(f"当前首选Code模型 {rmn} 已被删除, 请立即 /conf code_model: 调整", style="yellow")
2259
2157
 
2260
2158
 
2261
2159
  def configure_project_model():
@@ -2306,7 +2204,7 @@ def configure_project_model():
2306
2204
  model_num = input(f" 请选择您想使用的模型供应商编号(1-6): ").strip().lower()
2307
2205
 
2308
2206
  if int(model_num) < 1 or int(model_num) > 7:
2309
- print_status(f"请选择 1-7", "error")
2207
+ printer.print_text("请选择 1-7", style="red")
2310
2208
  exit(1)
2311
2209
 
2312
2210
  if model_num == "7":
@@ -2386,7 +2284,7 @@ def is_old_version():
2386
2284
  不再使用 current_chat_model 和 current_chat_model
2387
2285
  """
2388
2286
  if 'current_chat_model' in memory['conf'] and 'current_code_model' in memory['conf']:
2389
- logger.warning(f"您当前版本使用的版本偏低, 正在进行配置兼容性处理")
2287
+ printer.print_text(f"您当前使用的版本偏低 {__version__}, 正在进行配置兼容性处理", style="yellow")
2390
2288
  memory['conf']['chat_model'] = memory['conf']['current_chat_model']
2391
2289
  memory['conf']['code_model'] = memory['conf']['current_code_model']
2392
2290
  del memory['conf']['current_chat_model']
@@ -2408,30 +2306,30 @@ def main():
2408
2306
  _model_pass = input(f" 是否跳过模型配置(y/n): ").strip().lower()
2409
2307
  if _model_pass == "n":
2410
2308
  m1, m2, m3, m4 = configure_project_model()
2411
- print_status(f"正在更新缓存...", "warning")
2309
+ printer.print_text("正在更新缓存...", style="yellow")
2412
2310
  memory["conf"]["chat_model"] = m1
2413
2311
  memory["conf"]["code_model"] = m1
2414
2312
  memory["models"][m1] = {"base_url": m3, "api_key": m4, "model": m2}
2415
- print_status(f"供应商配置已成功完成!后续你可以使用 /models 命令, 查看, 新增和修改所有模型", "success")
2313
+ printer.print_text(f"供应商配置已成功完成!后续你可以使用 /models 命令, 查看, 新增和修改所有模型", style="green")
2416
2314
  else:
2417
- print_status("你已跳过模型配置,后续请使用 /models /add_model 添加模型...", "error")
2418
- print_status("添加示例 /models /add_model name=xxx base_url=xxx api_key=xxxx model=xxxxx", "error")
2315
+ printer.print_text("你已跳过模型配置,后续请使用 /models /add_model 添加模型...", style="yellow")
2316
+ printer.print_text("添加示例 /models /add_model name=& base_url=& api_key=& model=&", style="yellow")
2419
2317
 
2420
2318
  auto_llm = AutoLLM() # 创建模型
2421
2319
  if len(memory["models"]) > 0:
2422
2320
  for _model_name in memory["models"]:
2423
- print_status(f"正在部署 {_model_name} 模型...", "warning")
2321
+ printer.print_text(f"正在部署 {_model_name} 模型...", style="green")
2424
2322
  auto_llm.setup_sub_client(_model_name,
2425
2323
  memory["models"][_model_name]["api_key"],
2426
2324
  memory["models"][_model_name]["base_url"],
2427
2325
  memory["models"][_model_name]["model"])
2428
2326
 
2429
- print_status("初始化完成。", "success")
2327
+ printer.print_text("初始化完成.", style="green")
2430
2328
 
2431
2329
  if memory["conf"]["chat_model"] not in memory["models"].keys():
2432
- print_status("首选 Chat 模型与部署模型不一致, 请使用 /conf chat_model:xxx 设置", "error")
2330
+ printer.print_text("首选 Chat 模型与部署模型不一致, 请使用 /conf chat_model:& 设置", style="red")
2433
2331
  if memory["conf"]["code_model"] not in memory["models"].keys():
2434
- print_status("首选 Code 模型与部署模型不一致, 请使用 /conf code_model:xxx 设置", "error")
2332
+ printer.print_text("首选 Code 模型与部署模型不一致, 请使用 /conf code_model:& 设置", style="red")
2435
2333
 
2436
2334
  MODES = {
2437
2335
  "normal": "正常模式",
@@ -2479,9 +2377,13 @@ def main():
2479
2377
  key_bindings=kb,
2480
2378
  bottom_toolbar=get_bottom_toolbar,
2481
2379
  )
2482
- print(f"""\033[1;32mAutoCoder Nano v{__version__}\033[0m""")
2483
- print("\033[1;34m输入 /help 可以查看可用的命令.\033[0m\n")
2484
- # show_help()
2380
+ printer.print_key_value(
2381
+ {
2382
+ "AutoCoder Nano": f"v{__version__}",
2383
+ "Url": "https://github.com/w4n9H/autocoder-nano",
2384
+ "Help": "输入 /help 可以查看可用的命令."
2385
+ }
2386
+ )
2485
2387
 
2486
2388
  style = Style.from_dict(
2487
2389
  {