mirror of
https://github.com/Yanyutin753/RefreshToV1Api.git
synced 2025-10-19 01:43:53 +00:00
支持动态适配gpts
This commit is contained in:
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/log/access.log" charset="GBK" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@@ -26,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"refresh_ToAccess": {
|
"refresh_ToAccess": {
|
||||||
"stream_sleep_time": 0,
|
"stream_sleep_time": 0,
|
||||||
"enableOai":"true",
|
"enableOai":"false",
|
||||||
"xyhelper_refreshToAccess_Url": "https://demo.xyhelper.cn/applelogin"
|
"xyhelper_refreshToAccess_Url": "https://demo.xyhelper.cn/applelogin"
|
||||||
},
|
},
|
||||||
"redis": {
|
"redis": {
|
||||||
|
1162
log/access.log
Normal file
1162
log/access.log
Normal file
File diff suppressed because it is too large
Load Diff
61
main.py
61
main.py
@@ -255,7 +255,7 @@ def fetch_gizmo_info(base_url, proxy_api_prefix, model_id):
|
|||||||
# 将配置添加到全局列表
|
# 将配置添加到全局列表
|
||||||
def add_config_to_global_list(base_url, proxy_api_prefix, gpts_data):
|
def add_config_to_global_list(base_url, proxy_api_prefix, gpts_data):
|
||||||
global gpts_configurations
|
global gpts_configurations
|
||||||
updateGptsKey()
|
updateGptsKey() # cSpell:ignore Gpts
|
||||||
# print(f"gpts_data: {gpts_data}")
|
# print(f"gpts_data: {gpts_data}")
|
||||||
for model_name, model_info in gpts_data.items():
|
for model_name, model_info in gpts_data.items():
|
||||||
# print(f"model_name: {model_name}")
|
# print(f"model_name: {model_name}")
|
||||||
@@ -276,17 +276,15 @@ def add_config_to_global_list(base_url, proxy_api_prefix, gpts_data):
|
|||||||
if gizmo_info:
|
if gizmo_info:
|
||||||
redis_client.set(model_id, str(gizmo_info))
|
redis_client.set(model_id, str(gizmo_info))
|
||||||
logger.info(f"Cached gizmo info for {model_name}, {model_id}")
|
logger.info(f"Cached gizmo info for {model_name}, {model_id}")
|
||||||
|
# 检查模型名称是否已经在列表中
|
||||||
if gizmo_info:
|
if not any(d['name'] == model_name for d in gpts_configurations):
|
||||||
# 检查模型名称是否已经在列表中
|
gpts_configurations.append({
|
||||||
if not any(d['name'] == model_name for d in gpts_configurations):
|
'name': model_name,
|
||||||
gpts_configurations.append({
|
'id': model_id,
|
||||||
'name': model_name,
|
'config': gizmo_info
|
||||||
'id': model_id,
|
})
|
||||||
'config': gizmo_info
|
else:
|
||||||
})
|
logger.info(f"Model already exists in the list, skipping...")
|
||||||
else:
|
|
||||||
logger.info(f"Model already exists in the list, skipping...")
|
|
||||||
|
|
||||||
|
|
||||||
def generate_gpts_payload(model, messages):
|
def generate_gpts_payload(model, messages):
|
||||||
@@ -864,9 +862,13 @@ def send_text_prompt_and_get_response(messages, api_key, stream, model):
|
|||||||
|
|
||||||
# 查找模型配置
|
# 查找模型配置
|
||||||
model_config = find_model_config(model)
|
model_config = find_model_config(model)
|
||||||
if model_config:
|
if model_config or 'gpt-4-gizmo-' in model:
|
||||||
# 检查是否有 ori_name
|
# 检查是否有 ori_name
|
||||||
ori_model_name = model_config.get('ori_name', model)
|
if model_config:
|
||||||
|
ori_model_name = model_config.get('ori_name', model)
|
||||||
|
else:
|
||||||
|
ori_model_name = model
|
||||||
|
logger.info(f"原模型名: {model}")
|
||||||
logger.info(f"原模型名: {ori_model_name}")
|
logger.info(f"原模型名: {ori_model_name}")
|
||||||
if ori_model_name == 'gpt-4-s':
|
if ori_model_name == 'gpt-4-s':
|
||||||
payload = {
|
payload = {
|
||||||
@@ -918,6 +920,33 @@ def send_text_prompt_and_get_response(messages, api_key, stream, model):
|
|||||||
"force_paragen": False,
|
"force_paragen": False,
|
||||||
"force_rate_limit": False
|
"force_rate_limit": False
|
||||||
}
|
}
|
||||||
|
elif 'gpt-4-gizmo-' in model:
|
||||||
|
payload = generate_gpts_payload(model, formatted_messages)
|
||||||
|
if not payload:
|
||||||
|
global gpts_configurations
|
||||||
|
# 假设 model是 'gpt-4-gizmo-123'
|
||||||
|
split_name = model.split('gpt-4-gizmo-')
|
||||||
|
model_id = split_name[1] if len(split_name) > 1 else None
|
||||||
|
gizmo_info = fetch_gizmo_info(BASE_URL, PROXY_API_PREFIX, model_id)
|
||||||
|
logging.info(gizmo_info)
|
||||||
|
|
||||||
|
# 如果成功获取到数据,则将其存入 Redis
|
||||||
|
if gizmo_info:
|
||||||
|
redis_client.set(model_id, str(gizmo_info))
|
||||||
|
logger.info(f"Cached gizmo info for {model}, {model_id}")
|
||||||
|
# 检查模型名称是否已经在列表中
|
||||||
|
if not any(d['name'] == model for d in gpts_configurations):
|
||||||
|
gpts_configurations.append({
|
||||||
|
'name': model,
|
||||||
|
'id': model_id,
|
||||||
|
'config': gizmo_info
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
logger.info(f"Model already exists in the list, skipping...")
|
||||||
|
payload = generate_gpts_payload(model, formatted_messages)
|
||||||
|
else:
|
||||||
|
raise Exception('KEY_FOR_GPTS_INFO is not accessible')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
payload = generate_gpts_payload(model, formatted_messages)
|
payload = generate_gpts_payload(model, formatted_messages)
|
||||||
if not payload:
|
if not payload:
|
||||||
@@ -2248,7 +2277,7 @@ def chat_completions():
|
|||||||
messages = data.get('messages')
|
messages = data.get('messages')
|
||||||
model = data.get('model')
|
model = data.get('model')
|
||||||
accessible_model_list = get_accessible_model_list()
|
accessible_model_list = get_accessible_model_list()
|
||||||
if model not in accessible_model_list:
|
if model not in accessible_model_list and not 'gpt-4-gizmo-' in model:
|
||||||
return jsonify({"error": "model is not accessible"}), 401
|
return jsonify({"error": "model is not accessible"}), 401
|
||||||
|
|
||||||
stream = data.get('stream', False)
|
stream = data.get('stream', False)
|
||||||
@@ -2410,7 +2439,7 @@ def images_generations():
|
|||||||
# messages = data.get('messages')
|
# messages = data.get('messages')
|
||||||
model = data.get('model')
|
model = data.get('model')
|
||||||
accessible_model_list = get_accessible_model_list()
|
accessible_model_list = get_accessible_model_list()
|
||||||
if model not in accessible_model_list:
|
if model not in accessible_model_list and not 'gpt-4-gizmo-' in model:
|
||||||
return jsonify({"error": "model is not accessible"}), 401
|
return jsonify({"error": "model is not accessible"}), 401
|
||||||
|
|
||||||
prompt = data.get('prompt', '')
|
prompt = data.get('prompt', '')
|
||||||
|
Reference in New Issue
Block a user