|
@@ -6,6 +6,7 @@ import time
|
|
import _thread
|
|
import _thread
|
|
import os
|
|
import os
|
|
import subprocess
|
|
import subprocess
|
|
|
|
+import socket
|
|
|
|
|
|
ERNIE_API_KEY = ""
|
|
ERNIE_API_KEY = ""
|
|
ERNIE_SECRET_KEY = ""
|
|
ERNIE_SECRET_KEY = ""
|
|
@@ -208,6 +209,16 @@ def askOpenAI(quest):
|
|
|
|
|
|
return response.text
|
|
return response.text
|
|
|
|
|
|
|
|
+# 检查端口是否可用
|
|
|
|
+def check_port_available(port):
|
|
|
|
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
+ sock.settimeout(1)
|
|
|
|
+ result = sock.connect_ex(('localhost', port))
|
|
|
|
+ if result == 0:
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ return False
|
|
|
|
+
|
|
# 查询本地
|
|
# 查询本地
|
|
def askLocal(quest):
|
|
def askLocal(quest):
|
|
res = requests.post(
|
|
res = requests.post(
|
|
@@ -346,10 +357,12 @@ erniecli version : show version")
|
|
#使用绿色字体
|
|
#使用绿色字体
|
|
cli = ""
|
|
cli = ""
|
|
if USE_LOCAL:
|
|
if USE_LOCAL:
|
|
- # 本地ollama
|
|
|
|
- lock[1] ="\033[1;32m终端助理正在本地思考...\033[0m"
|
|
|
|
- answer = askLocal(question)
|
|
|
|
- cli = parse(answer, True)
|
|
|
|
|
|
+ # 检查11434端口是否可用
|
|
|
|
+ if check_port_available(LOCAL_PORT):
|
|
|
|
+ # 本地ollama
|
|
|
|
+ lock[1] ="\033[1;32m终端助理正在本地思考...\033[0m"
|
|
|
|
+ answer = askLocal(question)
|
|
|
|
+ cli = parse(answer, True)
|
|
if cli== "":
|
|
if cli== "":
|
|
lock[1] ="\033[1;32m终端助理正在云端思考...\033[0m"
|
|
lock[1] ="\033[1;32m终端助理正在云端思考...\033[0m"
|
|
|
|
|