-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathllm.py
29 lines (27 loc) · 1.1 KB
/
llm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import traceback
from app.pkgs.tools.llm_pro import LLMPro
from app.pkgs.tools.llm_basic import LLMBase
from config import GRADE
def chatCompletion(context, fackData="", bill: bool = True):
if GRADE == "base":
obj = LLMBase()
else:
obj = LLMPro()
message = ""
success = False
try:
message, total_tokens, success = obj.chatCompletion(context, fackData, False, bill)
except Exception as e:
print("chatCompletion failed 1 time:" + str(e))
try:
message, total_tokens, success = obj.chatCompletion(context, fackData, False, bill)
except Exception as e:
print("chatCompletion failed 2 time:" + str(e))
traceback.print_exc()
try:
message, total_tokens, success = obj.chatCompletion(context, fackData, True, bill)
except Exception as e:
print("chatCompletion failed 2 time:" + str(e))
traceback.print_exc()
raise Exception("服务异常,请重试。Service exception, please try again.")
return message, total_tokens, success