Bladeren bron

支持复杂的多行命令

xiongweixp 8 maanden geleden
bovenliggende
commit
6c628dd3f0
2 gewijzigde bestanden met toevoegingen van 16 en 6 verwijderingen
  1. 1 1
      .vscode/launch.json
  2. 15 5
      erniecli.py

+ 1 - 1
.vscode/launch.json

@@ -9,7 +9,7 @@
             "type": "debugpy",
             "request": "launch",
             "program": "erniecli.py",
-            "args": ["command","显示当前时间"],
+            "args": ["command","建立一个图标文件abc.desktop,运行/opt/abc/abc.sh"],
             "console": "integratedTerminal"
         },
         {

+ 15 - 5
erniecli.py

@@ -206,11 +206,21 @@ def parse(answer):
     elif BACKEND=="openai":
         result = answer['choices'][0]['message']['content']
     lines = result.split('\n')
-    # 获取lines中的```bash项编号
-    try:
-        index = lines.index('```bash')
-        return lines[index+1]
-    except ValueError:
+    # 获取lines中的```bash项到```项,并拼成一个字符串
+    cmd = ''
+    start = False
+    for line in lines:
+        if line.strip() == '```bash':
+            start = True
+            continue
+        if start:
+            if line.strip() == '```':
+                break
+            cmd += line+'\n'
+    
+    if cmd != '':
+        return cmd
+    else:
         print("\033[1;31mAI没有找到可执行的命令\033[0m")
         sys.exit(0)