Skip to content

Commit d6d8395

Browse files
committed
chore(llm): add backup key
1 parent 7635681 commit d6d8395

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

backend/app/pkgs/tools/llm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ def chatCompletion(context, fackData="", bill: bool = True):
1212
message = ""
1313
success = False
1414
try:
15-
message, total_tokens, success = obj.chatCompletion(context, fackData, bill)
15+
message, total_tokens, success = obj.chatCompletion(context, fackData, False, bill)
1616
except Exception as e:
1717
print("chatCompletion failed 1 time:" + str(e))
1818
try:
19-
message, total_tokens, success = obj.chatCompletion(context, fackData, bill)
19+
message, total_tokens, success = obj.chatCompletion(context, fackData, False, bill)
2020
except Exception as e:
2121
print("chatCompletion failed 2 time:" + str(e))
2222
traceback.print_exc()
2323
try:
24-
message, total_tokens, success = obj.chatCompletion(context, fackData, bill)
24+
message, total_tokens, success = obj.chatCompletion(context, fackData, True, bill)
2525
except Exception as e:
2626
print("chatCompletion failed 2 time:" + str(e))
2727
traceback.print_exc()

backend/app/pkgs/tools/llm_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_next_api_key():
3838
return get_next_api_key()
3939

4040
class LLMBase(LLMInterface):
41-
def chatCompletion(self, context, fackData, bill):
41+
def chatCompletion(self, context, fackData, use_backup_keys, bill):
4242
# Test frontend
4343
if MODE == "FAKE" and len(fackData) > 0:
4444
time.sleep(5)

backend/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def read_config(key):
6969
SQLALCHEMY_DATABASE_URI = read_config("SQLALCHEMY_DATABASE_URI")
7070
GPT_KEYS = json.loads(read_config("GPT_KEYS"))
7171
LLM_MODEL = read_config("LLM_MODEL")
72+
GPT_KEYS_BACKUP = json.loads(read_config("GPT_KEYS_BACKUP"))
7273
MODE = read_config("MODE")
7374
GRADE = read_config("GRADE")
7475
AUTO_LOGIN = read_config("AUTO_LOGIN")

env.yaml.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ GPT_KEYS: |
2424
}
2525
}
2626

27+
GPT_KEYS_BACKUP: |
28+
{
29+
"openai": {
30+
"keys": [
31+
{"sk-xxxx": {"count": 0, "timestamp": 0}}
32+
],
33+
"api_type": "open_ai",
34+
"api_base": "https://api.openai.com/v1",
35+
"api_version": "2020-11-07",
36+
"proxy": "None"
37+
}
38+
,
39+
"azure": {
40+
"keys": [
41+
{"sk-xxxx": {"count": 0, "timestamp": 0}}
42+
],
43+
"api_type": "azure",
44+
"api_base": "https://example-gpt.openai.azure.com/",
45+
"api_version": "2023-05-15",
46+
"deployment_id": "deployment-name",
47+
"proxy": "None"
48+
}
49+
}
50+
2751
# Configure the model used (do not use less than 16k token model), [note] openai plus members and API members are different, you opena plus member does not mean that you can use gpt4 model, specifically consult the official documentation of openai
2852
# 配置使用的模型(不要使用小于16k token的模型),【注意】openai的plus会员和API会员是不同的,你开通了plus会员不代表可以用gpt4的模型,具体查阅openai的官方文档
2953
LLM_MODEL: "gpt-3.5-turbo-16k-0613"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy