mirror of
https://github.com/Yanyutin753/RefreshToV1Api.git
synced 2025-12-20 01:03:02 +08:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a26235aba2 | ||
|
|
c6c3a6d93a | ||
|
|
00fbda47c7 | ||
|
|
8b9c44b285 | ||
|
|
27b9591723 | ||
|
|
e7f97f4104 | ||
|
|
36bd2901fc | ||
|
|
c10d11e6d2 | ||
|
|
7bd55e3468 | ||
|
|
5a40b35df1 | ||
|
|
509b233694 | ||
|
|
129bbafe08 | ||
|
|
0214512b13 | ||
|
|
46d2b9cb43 | ||
|
|
e3d8cc2139 | ||
|
|
1fc6fa7784 | ||
|
|
aae4fd64d7 | ||
|
|
cd983f0a0c | ||
|
|
76993fcce8 | ||
|
|
fa645a80d8 | ||
|
|
1e3e233adc | ||
|
|
002ff558b0 | ||
|
|
6f66431bb5 | ||
|
|
d815bf991e | ||
|
|
10488aeaa5 | ||
|
|
97f1c4f45f | ||
|
|
0d0ae4a95a | ||
|
|
37b0dd7c36 | ||
|
|
4a852bd070 | ||
|
|
0ca230a853 | ||
|
|
6eeadb49ac |
@@ -1,4 +1,4 @@
|
|||||||
name: Build and Push Docker Image
|
name: ninja Build and Push Docker Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
@@ -42,6 +42,6 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
yangclivia/pandora-to-api:${{ steps.tag_name.outputs.tag }}
|
yangclivia/pandora-to-api:${{ steps.tag_name.outputs.tag }}
|
||||||
yangclivia/pandora-to-api:latest
|
yangclivia/pandora-to-api:0.7.7
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
build-args: TARGETPLATFORM=${{ matrix.platform }}
|
build-args: TARGETPLATFORM=${{ matrix.platform }}
|
||||||
@@ -10,15 +10,13 @@ COPY . /app
|
|||||||
# 设置环境变量
|
# 设置环境变量
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
RUN chmod +x /app/start.sh
|
RUN chmod +x /app/main.py
|
||||||
|
|
||||||
RUN apt update && apt install -y jq
|
|
||||||
|
|
||||||
# # 设置 pip 源为清华大学镜像
|
# # 设置 pip 源为清华大学镜像
|
||||||
# RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
# RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
|
||||||
# 安装任何所需的依赖项
|
# 安装任何所需的依赖项
|
||||||
RUN pip install --no-cache-dir flask flask_apscheduler gunicorn requests Pillow flask-cors tiktoken fake_useragent redis websocket-client pysocks requests[socks] websocket-client[optional]
|
RUN pip install --no-cache-dir flask flask_apscheduler requests Pillow flask-cors tiktoken fake_useragent redis websocket-client pysocks requests[socks] websocket-client[optional]
|
||||||
|
|
||||||
# 在容器启动时运行 Flask 应用
|
# 在容器启动时运行 Flask 应用
|
||||||
CMD ["/app/start.sh"]
|
CMD ["python3", "main.py"]
|
||||||
|
|||||||
37
Readme.md
37
Readme.md
@@ -1,5 +1,5 @@
|
|||||||
## 项目简介
|
## 0.7.7 ninja版本项目简介
|
||||||
|
[](https://github.com/Yanyutin753/refresh-gpt-chat/stargazers)
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
>
|
>
|
||||||
> Respect Zhile大佬 , Respect Wizerd!
|
> Respect Zhile大佬 , Respect Wizerd!
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
- [x] 支持 gpt-3.5-turbo
|
- [x] 支持 gpt-3.5-turbo
|
||||||
|
|
||||||
- [x] 支持 gpts
|
- [x] 支持 动态gpts
|
||||||
|
|
||||||
- [x] 支持 流式输出
|
- [x] 支持 流式输出
|
||||||
|
|
||||||
@@ -157,7 +157,9 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
|||||||
|
|
||||||
## GPTS配置说明
|
## GPTS配置说明
|
||||||
|
|
||||||
如果需要使用 GPTS,需要修改 `gpts.json` 文件,其中每个对象的key即为调用对应 GPTS 的时候使用的模型名称,而 `id` 则为对应的模型id,该 `id` 对应每个 GPTS 的链接的后缀。配置多个GPTS的时候用逗号隔开。
|
### 使用 GPTS
|
||||||
|
|
||||||
|
1. 可修改 `gpts.json` 文件,其中每个对象的key即为调用对应 GPTS 的时候使用的模型名称,而 `id` 则为对应的模型id,该 `id` 对应每个 GPTS 的链接的后缀。配置多个GPTS的时候用逗号隔开。
|
||||||
|
|
||||||
例如:PandoraNext的官方 GPTS 的链接为:`https://chat.oaifree.com/g/g-CFsXuTRfy-pandoranextzhu-shou`,则该模型的 `id` 的值应为 `g-CFsXuTRfy-pandoranextzhu-shou`,而模型名可以自定义。
|
例如:PandoraNext的官方 GPTS 的链接为:`https://chat.oaifree.com/g/g-CFsXuTRfy-pandoranextzhu-shou`,则该模型的 `id` 的值应为 `g-CFsXuTRfy-pandoranextzhu-shou`,而模型名可以自定义。
|
||||||
|
|
||||||
@@ -174,7 +176,16 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
注意:使用该配置的时候需要保证正确填写 `docker-compose.yml` 的环境变量 `KEY_FOR_GPTS_INFO`,同时该变量设置的 `key` 允许访问所有配置的 GPTS。
|
2. 直接请求的时候加上相应的gpt-4-gizmo-XXX,XXX等同于上面的id的值
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"stream":true,
|
||||||
|
"model":"gpt-4-gizmo-XXXX",
|
||||||
|
"messages": [{"role": "user", "content": "你是什么模型"}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
注意:使用该配置的时候需要保证正确填写 `config.json` 文件的环境变量 `KEY_FOR_GPTS_INFO`,同时该变量设置的 `key` 允许访问所有配置的 GPTS。
|
||||||
|
|
||||||
## 绘图接口使用说明
|
## 绘图接口使用说明
|
||||||
|
|
||||||
@@ -315,19 +326,20 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
|||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
|
|
||||||
以ChatGPT-Next-Web项目的docker-compose部署为例,这里提供一个简单的部署配置文件示例:
|
以[ChatGPT-Next-Web](https://github.com/Yanyutin753/ChatGPT-Next-Web-LangChain-Gpt-4-All)项目插件版的docker-compose部署为例,支持完全适配项目,这里提供一个简单的部署配置文件示例:
|
||||||
|
|
||||||
```
|
```
|
||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
chatgpt-next-web:
|
chatgpt-next-web:
|
||||||
image: yidadaa/chatgpt-next-web
|
image: yangclivia/chatgpt-next-web-langchain
|
||||||
ports:
|
ports:
|
||||||
- "50013:3000"
|
- "50013:3000"
|
||||||
environment:
|
environment:
|
||||||
|
- CUSTOM_MODELS=-all,+gpt-3.5-turbo,+gpt-4-s,+gpt-4-mobile,+gpt-4-vision-preview,+gpt-4-gizmo-XXX
|
||||||
- OPENAI_API_KEY=<正确的refresh_token>
|
- OPENAI_API_KEY=<正确的refresh_token>
|
||||||
- BASE_URL=<backend-to-api容器地址>
|
- BASE_URL=<backend-to-api容器地址>
|
||||||
- CUSTOM_MODELS=+gpt-4-s,+gpt-4-mobile,+<gpts.json 中的模型名>
|
- CUSTOM_MODELS=-gpt-4-0613,-gpt-4-32k,-gpt-4-32k-0613,-gpt-4-turbo-preview,-gpt-4-1106-preview,-gpt-4-0125-preview,-gpt-3.5-turbo-0125,-gpt-3.5-turbo-0613,-gpt-3.5-turbo-1106,-gpt-3.5-turbo-16k,-gpt-3.5-turbo-16k-0613,+gpt-3.5-turbo,+gpt-4,+gpt-4-mobile,+gpt-4-vision-preview,+gpt-4-mobile,+<gpts.json 中的模型名>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -342,17 +354,20 @@ services:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### 读文件
|
||||||
|

|
||||||
|
|
||||||
### 绘图
|
### 绘图
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### GPT-4-Mobile
|
### GPT-4-Mobile
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### GPTS
|
### GPTS
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Bot 模式
|
### Bot 模式
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ version: '3'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
backend-to-api:
|
backend-to-api:
|
||||||
image: yangclivia/pandora-to-api:latest
|
image: yangclivia/pandora-to-api:0.7.7
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "50011:33333"
|
- "50011:33333"
|
||||||
|
|||||||
119
main.py
119
main.py
@@ -48,6 +48,7 @@ if PROXY_API_PREFIX != '':
|
|||||||
PROXY_API_PREFIX = "/" + PROXY_API_PREFIX
|
PROXY_API_PREFIX = "/" + PROXY_API_PREFIX
|
||||||
UPLOAD_BASE_URL = CONFIG.get('backend_container_url', '')
|
UPLOAD_BASE_URL = CONFIG.get('backend_container_url', '')
|
||||||
KEY_FOR_GPTS_INFO = CONFIG.get('key_for_gpts_info', '')
|
KEY_FOR_GPTS_INFO = CONFIG.get('key_for_gpts_info', '')
|
||||||
|
KEY_FOR_GPTS_INFO_ACCESS_TOKEN = CONFIG.get('key_for_gpts_info', '')
|
||||||
API_PREFIX = CONFIG.get('backend_container_api_prefix', '')
|
API_PREFIX = CONFIG.get('backend_container_api_prefix', '')
|
||||||
GPT_4_S_New_Names = CONFIG.get('gpt_4_s_new_name', 'gpt-4-s').split(',')
|
GPT_4_S_New_Names = CONFIG.get('gpt_4_s_new_name', 'gpt-4-s').split(',')
|
||||||
GPT_4_MOBILE_NEW_NAMES = CONFIG.get('gpt_4_mobile_new_name', 'gpt-4-mobile').split(',')
|
GPT_4_MOBILE_NEW_NAMES = CONFIG.get('gpt_4_mobile_new_name', 'gpt-4-mobile').split(',')
|
||||||
@@ -198,7 +199,7 @@ def oaiGetAccessToken(refresh_token):
|
|||||||
|
|
||||||
|
|
||||||
# ninja获得access_token
|
# ninja获得access_token
|
||||||
def ninjaGetAccessToken(refresh_token, getAccessTokenUrl):
|
def ninjaGetAccessToken(getAccessTokenUrl, refresh_token):
|
||||||
try:
|
try:
|
||||||
logger.info("将通过这个网址请求access_token:" + getAccessTokenUrl)
|
logger.info("将通过这个网址请求access_token:" + getAccessTokenUrl)
|
||||||
headers = {"Authorization": "Bearer " + refresh_token}
|
headers = {"Authorization": "Bearer " + refresh_token}
|
||||||
@@ -221,22 +222,22 @@ def ninjaGetAccessToken(refresh_token, getAccessTokenUrl):
|
|||||||
|
|
||||||
def updateGptsKey():
|
def updateGptsKey():
|
||||||
global KEY_FOR_GPTS_INFO
|
global KEY_FOR_GPTS_INFO
|
||||||
|
global KEY_FOR_GPTS_INFO_ACCESS_TOKEN
|
||||||
if not KEY_FOR_GPTS_INFO == '' and not KEY_FOR_GPTS_INFO.startswith("eyJhb"):
|
if not KEY_FOR_GPTS_INFO == '' and not KEY_FOR_GPTS_INFO.startswith("eyJhb"):
|
||||||
if REFRESH_TOACCESS_ENABLEOAI:
|
if REFRESH_TOACCESS_ENABLEOAI:
|
||||||
access_token = oaiGetAccessToken(KEY_FOR_GPTS_INFO)
|
access_token = oaiGetAccessToken(KEY_FOR_GPTS_INFO)
|
||||||
else:
|
else:
|
||||||
access_token = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, KEY_FOR_GPTS_INFO)
|
access_token = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, KEY_FOR_GPTS_INFO)
|
||||||
if access_token.startswith("eyJhb"):
|
if access_token.startswith("eyJhb"):
|
||||||
KEY_FOR_GPTS_INFO = access_token
|
KEY_FOR_GPTS_INFO_ACCESS_TOKEN = access_token
|
||||||
logging.info("KEY_FOR_GPTS_INFO被更新:" + KEY_FOR_GPTS_INFO)
|
logging.info("KEY_FOR_GPTS_INFO_ACCESS_TOKEN被更新:" + KEY_FOR_GPTS_INFO_ACCESS_TOKEN)
|
||||||
|
|
||||||
|
|
||||||
# 根据 ID 发送请求并获取配置信息
|
# 根据 ID 发送请求并获取配置信息
|
||||||
def fetch_gizmo_info(base_url, proxy_api_prefix, model_id):
|
def fetch_gizmo_info(base_url, proxy_api_prefix, model_id):
|
||||||
url = f"{base_url}{proxy_api_prefix}/backend-api/gizmos/{model_id}"
|
url = f"{base_url}{proxy_api_prefix}/backend-api/gizmos/{model_id}"
|
||||||
updateGptsKey()
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {KEY_FOR_GPTS_INFO}"
|
"Authorization": f"Bearer {KEY_FOR_GPTS_INFO_ACCESS_TOKEN}"
|
||||||
}
|
}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
# logger.debug(f"fetch_gizmo_info_response: {response.text}")
|
# logger.debug(f"fetch_gizmo_info_response: {response.text}")
|
||||||
@@ -251,6 +252,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()
|
||||||
# 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}")
|
||||||
@@ -272,16 +274,16 @@ def add_config_to_global_list(base_url, proxy_api_prefix, gpts_data):
|
|||||||
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 gizmo_info and not any(d['name'] == model_name for d in gpts_configurations):
|
||||||
if not any(d['name'] == model_name for d in gpts_configurations):
|
gpts_configurations.append({
|
||||||
gpts_configurations.append({
|
'name': model_name,
|
||||||
'name': model_name,
|
'id': model_id,
|
||||||
'id': model_id,
|
'config': gizmo_info
|
||||||
'config': gizmo_info
|
})
|
||||||
})
|
else:
|
||||||
else:
|
logger.info(f"Model already exists in the list, skipping...")
|
||||||
logger.info(f"Model already exists in the list, skipping...")
|
|
||||||
|
|
||||||
|
|
||||||
def generate_gpts_payload(model, messages):
|
def generate_gpts_payload(model, messages):
|
||||||
@@ -319,9 +321,9 @@ scheduler.start()
|
|||||||
# PANDORA_UPLOAD_URL = 'files.pandoranext.com'
|
# PANDORA_UPLOAD_URL = 'files.pandoranext.com'
|
||||||
|
|
||||||
|
|
||||||
VERSION = '0.7.7'
|
VERSION = '0.7.7.3'
|
||||||
# VERSION = 'test'
|
# VERSION = 'test'
|
||||||
# UPDATE_INFO = '增加Arkose请求头'
|
UPDATE_INFO = 'flask直接启动,解决部分机cpu占用过大问题'
|
||||||
# UPDATE_INFO = '【仅供临时测试使用】 '
|
# UPDATE_INFO = '【仅供临时测试使用】 '
|
||||||
|
|
||||||
# 解析响应中的信息
|
# 解析响应中的信息
|
||||||
@@ -859,10 +861,14 @@ 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:
|
||||||
logger.info(f"原模型名: {ori_model_name}")
|
ori_model_name = model_config.get('ori_name', model)
|
||||||
|
logger.info(f"原模型名: {ori_model_name}")
|
||||||
|
else:
|
||||||
|
logger.info(f"请求模型名: {model}")
|
||||||
|
ori_model_name = model
|
||||||
if ori_model_name == 'gpt-4-s':
|
if ori_model_name == 'gpt-4-s':
|
||||||
payload = {
|
payload = {
|
||||||
# 构建 payload
|
# 构建 payload
|
||||||
@@ -913,6 +919,53 @@ 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:
|
||||||
|
payload = {
|
||||||
|
# 构建 payload
|
||||||
|
"action": "next",
|
||||||
|
"messages": formatted_messages,
|
||||||
|
"parent_message_id": str(uuid.uuid4()),
|
||||||
|
"model": "text-davinci-002-render-sha",
|
||||||
|
"timezone_offset_min": -480,
|
||||||
|
"suggestions": [
|
||||||
|
"What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter.",
|
||||||
|
"I want to cheer up my friend who's having a rough day. Can you suggest a couple short and sweet text messages to go with a kitten gif?",
|
||||||
|
"Come up with 5 concepts for a retro-style arcade game.",
|
||||||
|
"I have a photoshoot tomorrow. Can you recommend me some colors and outfit options that will look good on camera?"
|
||||||
|
],
|
||||||
|
"history_and_training_disabled": False,
|
||||||
|
"arkose_token": None,
|
||||||
|
"conversation_mode": {
|
||||||
|
"kind": "primary_assistant"
|
||||||
|
},
|
||||||
|
"force_paragen": False,
|
||||||
|
"force_rate_limit": False
|
||||||
|
}
|
||||||
|
logger.debug('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:
|
||||||
@@ -926,7 +979,7 @@ def send_text_prompt_and_get_response(messages, api_key, stream, model):
|
|||||||
token = get_token()
|
token = get_token()
|
||||||
payload["arkose_token"] = token
|
payload["arkose_token"] = token
|
||||||
# 在headers中添加新字段
|
# 在headers中添加新字段
|
||||||
headers["Openai-Sentinel-Arkose-Token"] = token
|
headers["Openai-Sentinel-Arkose-Token"] = token
|
||||||
logger.debug(f"headers: {headers}")
|
logger.debug(f"headers: {headers}")
|
||||||
logger.debug(f"payload: {payload}")
|
logger.debug(f"payload: {payload}")
|
||||||
response = requests.post(url, headers=headers, json=payload, stream=True)
|
response = requests.post(url, headers=headers, json=payload, stream=True)
|
||||||
@@ -1156,7 +1209,7 @@ def generate_actions_allow_payload(author_role, author_name, target_message_id,
|
|||||||
"action": "next",
|
"action": "next",
|
||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"id": generate_custom_uuid_v4(),
|
"id": str(uuid.uuid4()),
|
||||||
"author": {
|
"author": {
|
||||||
"role": author_role,
|
"role": author_role,
|
||||||
"name": author_name
|
"name": author_name
|
||||||
@@ -2007,7 +2060,7 @@ def old_data_fetcher(upstream_response, data_queue, stop_event, last_data_time,
|
|||||||
"id": chat_message_id,
|
"id": chat_message_id,
|
||||||
"object": "chat.completion.chunk",
|
"object": "chat.completion.chunk",
|
||||||
"created": timestamp,
|
"created": timestamp,
|
||||||
"model": message.get("metadata", {}).get("model_slug"),
|
"model": model,
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -2243,7 +2296,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)
|
||||||
@@ -2257,8 +2310,8 @@ def chat_completions():
|
|||||||
logger.info(f"从缓存读取到api_key.........。")
|
logger.info(f"从缓存读取到api_key.........。")
|
||||||
api_key = refresh_dict.get(api_key)
|
api_key = refresh_dict.get(api_key)
|
||||||
else:
|
else:
|
||||||
|
refresh_token = api_key
|
||||||
if REFRESH_TOACCESS_ENABLEOAI:
|
if REFRESH_TOACCESS_ENABLEOAI:
|
||||||
refresh_token = api_key
|
|
||||||
api_key = oaiGetAccessToken(api_key)
|
api_key = oaiGetAccessToken(api_key)
|
||||||
else:
|
else:
|
||||||
api_key = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, api_key)
|
api_key = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, api_key)
|
||||||
@@ -2401,7 +2454,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', '')
|
||||||
@@ -2602,8 +2655,8 @@ def updateRefresh_dict():
|
|||||||
logger.info(f"==========================================")
|
logger.info(f"==========================================")
|
||||||
logging.info("开始更新access_token.........")
|
logging.info("开始更新access_token.........")
|
||||||
for key in refresh_dict:
|
for key in refresh_dict:
|
||||||
|
refresh_token = key
|
||||||
if REFRESH_TOACCESS_ENABLEOAI:
|
if REFRESH_TOACCESS_ENABLEOAI:
|
||||||
refresh_token = key
|
|
||||||
access_token = oaiGetAccessToken(key)
|
access_token = oaiGetAccessToken(key)
|
||||||
else:
|
else:
|
||||||
access_token = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, key)
|
access_token = ninjaGetAccessToken(REFRESH_TOACCESS_NINJA_REFRESHTOACCESS_URL, key)
|
||||||
@@ -2614,21 +2667,17 @@ def updateRefresh_dict():
|
|||||||
success_num += 1
|
success_num += 1
|
||||||
logging.info("更新成功: " + str(success_num) + ", 失败: " + str(error_num))
|
logging.info("更新成功: " + str(success_num) + ", 失败: " + str(error_num))
|
||||||
logger.info(f"==========================================")
|
logger.info(f"==========================================")
|
||||||
logging.info("开始更新KEY_FOR_GPTS_INFO.........")
|
logging.info("开始更新KEY_FOR_GPTS_INFO_ACCESS_TOKEN和GPTS配置信息......")
|
||||||
updateGptsKey()
|
|
||||||
# 配置GPTS
|
|
||||||
logger.info(f"GPTS 配置信息.....................")
|
|
||||||
# 加载配置并添加到全局列表
|
# 加载配置并添加到全局列表
|
||||||
gpts_data = load_gpts_config("./data/gpts.json")
|
gpts_data = load_gpts_config("./data/gpts.json")
|
||||||
add_config_to_global_list(BASE_URL, PROXY_API_PREFIX, gpts_data)
|
add_config_to_global_list(BASE_URL, PROXY_API_PREFIX, gpts_data)
|
||||||
|
|
||||||
accessible_model_list = get_accessible_model_list()
|
accessible_model_list = get_accessible_model_list()
|
||||||
logger.info(f"当前可用 GPTS 列表: {accessible_model_list}")
|
|
||||||
|
|
||||||
# 检查列表中是否有重复的模型名称
|
# 检查列表中是否有重复的模型名称
|
||||||
if len(accessible_model_list) != len(set(accessible_model_list)):
|
if len(accessible_model_list) != len(set(accessible_model_list)):
|
||||||
raise Exception("检测到重复的模型名称,请检查环境变量或配置文件。")
|
raise Exception("检测到重复的模型名称,请检查环境变量或配置文件。")
|
||||||
|
logging.info("更新KEY_FOR_GPTS_INFO_ACCESS_TOKEN和GPTS配置信息成功......")
|
||||||
|
logger.info(f"当前可用 GPTS 列表: {accessible_model_list}")
|
||||||
logger.info(f"==========================================")
|
logger.info(f"==========================================")
|
||||||
|
|
||||||
|
|
||||||
@@ -2637,4 +2686,4 @@ scheduler.add_job(id='updateRefresh_run', func=updateRefresh_dict, trigger='cron
|
|||||||
|
|
||||||
# 运行 Flask 应用
|
# 运行 Flask 应用
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0', port=33333, threaded=True)
|
||||||
|
|||||||
2
start.sh
2
start.sh
@@ -31,4 +31,4 @@ echo "PROCESS_WORKERS: ${PROCESS_WORKERS}"
|
|||||||
echo "PROCESS_THREADS: ${PROCESS_THREADS}"
|
echo "PROCESS_THREADS: ${PROCESS_THREADS}"
|
||||||
|
|
||||||
# 启动 Gunicorn 并使用 tee 命令同时输出日志到文件和控制台
|
# 启动 Gunicorn 并使用 tee 命令同时输出日志到文件和控制台
|
||||||
exec gunicorn -w ${PROCESS_WORKERS} --threads ${PROCESS_THREADS} --bind 0.0.0.0:33333 main:app --access-logfile - --error-logfile -
|
exec gunicorn -w ${PROCESS_WORKERS} --threads ${PROCESS_THREADS} --bind 0.0.0.0:33333 main:app --access-logfile - --error-logfile - --timeout 60
|
||||||
|
|||||||
Reference in New Issue
Block a user