change get_conf
This commit is contained in:
@@ -56,7 +56,7 @@ if not AZURE_ENDPOINT.endswith('/'): AZURE_ENDPOINT += '/'
|
||||
azure_endpoint = AZURE_ENDPOINT + f'openai/deployments/{AZURE_ENGINE}/chat/completions?api-version=2023-05-15'
|
||||
# 兼容旧版的配置
|
||||
try:
|
||||
API_URL, = get_conf("API_URL")
|
||||
API_URL = get_conf("API_URL")
|
||||
if API_URL != "https://api.openai.com/v1/chat/completions":
|
||||
openai_endpoint = API_URL
|
||||
print("警告!API_URL配置选项将被弃用,请更换为API_URL_REDIRECT配置")
|
||||
@@ -501,7 +501,7 @@ if "zhipuai" in AVAIL_LLM_MODELS: # zhipuai
|
||||
print(trimmed_format_exc())
|
||||
|
||||
# <-- 用于定义和切换多个azure模型 -->
|
||||
AZURE_CFG_ARRAY, = get_conf("AZURE_CFG_ARRAY")
|
||||
AZURE_CFG_ARRAY = get_conf("AZURE_CFG_ARRAY")
|
||||
if len(AZURE_CFG_ARRAY) > 0:
|
||||
for azure_model_name, azure_cfg_dict in AZURE_CFG_ARRAY.items():
|
||||
# 可能会覆盖之前的配置,但这是意料之中的
|
||||
|
||||
@@ -63,7 +63,7 @@ class GetGLMFTHandle(Process):
|
||||
# if not os.path.exists(conf): raise RuntimeError('找不到微调模型信息')
|
||||
# with open(conf, 'r', encoding='utf8') as f:
|
||||
# model_args = json.loads(f.read())
|
||||
CHATGLM_PTUNING_CHECKPOINT, = get_conf('CHATGLM_PTUNING_CHECKPOINT')
|
||||
CHATGLM_PTUNING_CHECKPOINT = get_conf('CHATGLM_PTUNING_CHECKPOINT')
|
||||
assert os.path.exists(CHATGLM_PTUNING_CHECKPOINT), "找不到微调模型检查点"
|
||||
conf = os.path.join(CHATGLM_PTUNING_CHECKPOINT, "config.json")
|
||||
with open(conf, 'r', encoding='utf8') as f:
|
||||
|
||||
@@ -52,7 +52,7 @@ class GetInternlmHandle(LocalLLMHandle):
|
||||
# 🏃♂️🏃♂️🏃♂️ 子进程执行
|
||||
import torch
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
device, = get_conf('LOCAL_MODEL_DEVICE')
|
||||
device = get_conf('LOCAL_MODEL_DEVICE')
|
||||
if self._model is None:
|
||||
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
|
||||
if device=='cpu':
|
||||
|
||||
@@ -53,7 +53,7 @@ class GetGLMHandle(Process):
|
||||
import types
|
||||
try:
|
||||
if self.jittorllms_model is None:
|
||||
device, = get_conf('LOCAL_MODEL_DEVICE')
|
||||
device = get_conf('LOCAL_MODEL_DEVICE')
|
||||
from .jittorllms.models import get_model
|
||||
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
|
||||
args_dict = {'model': 'llama'}
|
||||
|
||||
@@ -53,7 +53,7 @@ class GetGLMHandle(Process):
|
||||
import types
|
||||
try:
|
||||
if self.jittorllms_model is None:
|
||||
device, = get_conf('LOCAL_MODEL_DEVICE')
|
||||
device = get_conf('LOCAL_MODEL_DEVICE')
|
||||
from .jittorllms.models import get_model
|
||||
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
|
||||
args_dict = {'model': 'pangualpha'}
|
||||
|
||||
@@ -53,7 +53,7 @@ class GetGLMHandle(Process):
|
||||
import types
|
||||
try:
|
||||
if self.jittorllms_model is None:
|
||||
device, = get_conf('LOCAL_MODEL_DEVICE')
|
||||
device = get_conf('LOCAL_MODEL_DEVICE')
|
||||
from .jittorllms.models import get_model
|
||||
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
|
||||
args_dict = {'model': 'chatrwkv'}
|
||||
|
||||
@@ -62,7 +62,7 @@ class NewBingHandle(Process):
|
||||
|
||||
async def async_run(self):
|
||||
# 读取配置
|
||||
NEWBING_STYLE, = get_conf('NEWBING_STYLE')
|
||||
NEWBING_STYLE = get_conf('NEWBING_STYLE')
|
||||
from request_llms.bridge_all import model_info
|
||||
endpoint = model_info['newbing']['endpoint']
|
||||
while True:
|
||||
|
||||
@@ -146,14 +146,14 @@ class ClaudeHandle(Process):
|
||||
self.local_history = []
|
||||
if (self.claude_model is None) or (not self.success):
|
||||
# 代理设置
|
||||
proxies, = get_conf('proxies')
|
||||
proxies = get_conf('proxies')
|
||||
if proxies is None:
|
||||
self.proxies_https = None
|
||||
else:
|
||||
self.proxies_https = proxies['https']
|
||||
|
||||
try:
|
||||
SLACK_CLAUDE_USER_TOKEN, = get_conf('SLACK_CLAUDE_USER_TOKEN')
|
||||
SLACK_CLAUDE_USER_TOKEN = get_conf('SLACK_CLAUDE_USER_TOKEN')
|
||||
self.claude_model = SlackClient(token=SLACK_CLAUDE_USER_TOKEN, proxy=self.proxies_https)
|
||||
print('Claude组件初始化成功。')
|
||||
except:
|
||||
|
||||
@@ -5,7 +5,7 @@ from toolbox import update_ui, get_conf, update_ui_lastest_msg
|
||||
model_name = '智谱AI大模型'
|
||||
|
||||
def validate_key():
|
||||
ZHIPUAI_API_KEY, = get_conf("ZHIPUAI_API_KEY")
|
||||
ZHIPUAI_API_KEY = get_conf("ZHIPUAI_API_KEY")
|
||||
if ZHIPUAI_API_KEY == '': return False
|
||||
return True
|
||||
|
||||
|
||||
29
request_llms/key_manager.py
Normal file
29
request_llms/key_manager.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import random
|
||||
|
||||
def Singleton(cls):
|
||||
_instance = {}
|
||||
|
||||
def _singleton(*args, **kargs):
|
||||
if cls not in _instance:
|
||||
_instance[cls] = cls(*args, **kargs)
|
||||
return _instance[cls]
|
||||
|
||||
return _singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
class OpenAI_ApiKeyManager():
|
||||
def __init__(self, mode='blacklist') -> None:
|
||||
# self.key_avail_list = []
|
||||
self.key_black_list = []
|
||||
|
||||
def add_key_to_blacklist(self, key):
|
||||
self.key_black_list.append(key)
|
||||
|
||||
def select_avail_key(self, key_list):
|
||||
# select key from key_list, but avoid keys also in self.key_black_list, raise error if no key can be found
|
||||
available_keys = [key for key in key_list if key not in self.key_black_list]
|
||||
if not available_keys:
|
||||
raise KeyError("No available key found.")
|
||||
selected_key = random.choice(available_keys)
|
||||
return selected_key
|
||||
Reference in New Issue
Block a user