|
@@ -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)
|
|
|
|