mirror of
https://github.com/Yanyutin753/RefreshToV1Api.git
synced 2025-12-19 01:01:31 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cc275502a | ||
|
|
21fd5b81be | ||
|
|
9017ec892f | ||
|
|
12f7d616d7 | ||
|
|
10782fbe1f | ||
|
|
8a9932b18d | ||
|
|
4b706bfb8d | ||
|
|
7a1d7541bf | ||
|
|
39d394e28b | ||
|
|
816e78ab81 |
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.8 (pythonProject7)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (pythonProject7)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
38
Readme.md
38
Readme.md
@@ -17,7 +17,7 @@
|
||||
|
||||
3. 支持直接把refresh_token作为请求key,方便接入one_api
|
||||
|
||||
4. 支持 gpt-4-mobile 、gpt-4-s 、基本所有的GPTS
|
||||
4. 支持 gpt-4o 、gpt-4-s 、基本所有的GPTS
|
||||
|
||||
* **oaiFree 的 backend-api 接口,无需打码**
|
||||
|
||||
@@ -39,11 +39,11 @@
|
||||
|
||||
- [x] 支持 gpt-4-s
|
||||
|
||||
- [x] 支持 gpt-4-mobile
|
||||
- [x] 支持 gpt-4o
|
||||
|
||||
- [x] 支持 gpt-3.5-turbo
|
||||
|
||||
- [x] 暂不 支持 gpts
|
||||
- [x] 支持 gpts
|
||||
|
||||
- [x] 支持 流式输出
|
||||
|
||||
@@ -90,11 +90,14 @@
|
||||
|
||||
4. gpt-3.5-turbo
|
||||
|
||||
## Docker-Compose 部署
|
||||
## 部署说明
|
||||
<details>
|
||||
|
||||
### Docker-Compose 部署
|
||||
|
||||
仓库内已包含相关文件和目录,拉到本地后修改 docker-compose.yml 文件里的环境变量后运行`docker-compose up -d`即可。
|
||||
|
||||
## config.json 变量说明:
|
||||
### config.json 变量说明:
|
||||
|
||||
- `log_level`: 用于设置日志等级,可选值为:`DEBUG`、`INFO`、`WARNING`、`ERROR`,默认为 `DEBUG`
|
||||
|
||||
@@ -148,7 +151,7 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
||||
|
||||
- `enableOai`:用于设置是否使用官网通过refresh_token刷新access_token,仅在 `enableOai` 为 `true` 时生效。
|
||||
|
||||
- `oaiFree_refreshToAccess_Url`:用于设置使用oaiFree来进行使用refresh_token刷新access_token,enableOai为false的时候必填
|
||||
- `oaifree_refreshToAccess_Url`:用于设置使用oaiFree来进行使用refresh_token刷新access_token,enableOai为false的时候必填
|
||||
- 默认为"https://token.oaifree.com/api/auth/refresh"
|
||||
|
||||
- `redis`
|
||||
@@ -161,7 +164,7 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
||||
|
||||
- `db`: Redis的数据库,默认:0,如有特殊需求,你可以将此值设置为其他数据库
|
||||
|
||||
## GPTS配置说明
|
||||
### GPTS配置说明
|
||||
|
||||
如果需要使用 GPTS,需要修改 `gpts.json` 文件,其中每个对象的key即为调用对应 GPTS 的时候使用的模型名称,而 `id` 则为对应的模型id,该 `id` 对应每个 GPTS 的链接的后缀。配置多个GPTS的时候用逗号隔开。
|
||||
|
||||
@@ -182,7 +185,7 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
||||
|
||||
注意:使用该配置的时候需要保证正确填写 `docker-compose.yml` 的环境变量 `KEY_FOR_GPTS_INFO`,同时该变量设置的 `key` 允许访问所有配置的 GPTS。
|
||||
|
||||
## 绘图接口使用说明
|
||||
### 绘图接口使用说明
|
||||
|
||||
接口URI:`/v1/images/generations`
|
||||
|
||||
@@ -219,7 +222,7 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
||||
}
|
||||
```
|
||||
|
||||
## 文件识别接口使用说明
|
||||
### 文件识别接口使用说明
|
||||
|
||||
调用方式同官方 `gpt-4-vision-preview` API
|
||||
|
||||
@@ -318,8 +321,18 @@ PS. 注意,arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
|
||||
}
|
||||
}
|
||||
```
|
||||
### 获取ChatGPT-Account-ID接口
|
||||
|
||||
## 示例
|
||||
接口URI:`/getAccountID`
|
||||
|
||||
请求方式:`POST`
|
||||
|
||||
```
|
||||
请求头加上
|
||||
Authorization:Bearer refresh_token 或 access_token
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
以ChatGPT-Next-Web项目的docker-compose部署为例,这里提供一个简单的部署配置文件示例:
|
||||
|
||||
@@ -336,6 +349,8 @@ services:
|
||||
- CUSTOM_MODELS=+gpt-4-s,+gpt-4-mobile,+<gpts.json 中的模型名>
|
||||
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
## 功能演示
|
||||
<details>
|
||||
@@ -378,9 +393,6 @@ services:
|
||||
> * 本项目只提供转发接口🥰
|
||||
> * 开源项目不易,请点个星星吧!!!
|
||||
|
||||
### 新增群聊,点了⭐️可以进群讨论部署,我把你们拉进群,无广,广子踢掉
|
||||
<img src="https://github.com/Yanyutin753/PandoraNext-TokensTool/assets/132346501/6544e8ed-6673-48f9-95a6-c13255acbab1" width="300" height="300">
|
||||
|
||||
## Sponsor
|
||||
|
||||
### 如果你觉得我的开源项目对你有帮助,可以赞助我一杯咖啡嘛,十分感谢!!!
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"gpt_4_s_new_name": "gpt-4-s",
|
||||
"gpt_4_mobile_new_name": "gpt-4-mobile,dall-e-3",
|
||||
"gpt_3_5_new_name": "gpt-3.5-turbo",
|
||||
"gpt_4_o_new_name": "gpt-4-o,gpt-4o",
|
||||
"need_delete_conversation_after_response": "true",
|
||||
"use_oaiusercontent_url": "false",
|
||||
"custom_arkose_url": "false",
|
||||
|
||||
103
main.py
103
main.py
@@ -1,32 +1,21 @@
|
||||
# 导入所需的库
|
||||
from flask import Flask, request, jsonify, Response, send_from_directory
|
||||
from flask_cors import CORS, cross_origin
|
||||
import requests
|
||||
import uuid
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
from datetime import datetime
|
||||
from PIL import Image
|
||||
import io
|
||||
import re
|
||||
import threading
|
||||
from queue import Queue, Empty
|
||||
import logging
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
import uuid
|
||||
import hashlib
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
import base64
|
||||
from fake_useragent import UserAgent
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from queue import Queue
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
from fake_useragent import UserAgent
|
||||
from flask import Flask, request, jsonify, Response, send_from_directory
|
||||
from flask_apscheduler import APScheduler
|
||||
from flask_cors import CORS, cross_origin
|
||||
|
||||
|
||||
# 读取配置文件
|
||||
@@ -51,6 +40,7 @@ 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_MOBILE_NEW_NAMES = CONFIG.get('gpt_4_mobile_new_name', 'gpt-4-mobile').split(',')
|
||||
GPT_3_5_NEW_NAMES = CONFIG.get('gpt_3_5_new_name', 'gpt-3.5-turbo').split(',')
|
||||
GPT_4_O_NEW_NAMES = CONFIG.get('gpt_4_o_new_name', 'gpt-4-o').split(',')
|
||||
|
||||
BOT_MODE = CONFIG.get('bot_mode', {})
|
||||
BOT_MODE_ENABLED = BOT_MODE.get('enabled', 'false').lower() == 'true'
|
||||
@@ -132,7 +122,6 @@ logger.addHandler(stream_handler)
|
||||
# 创建FakeUserAgent对象
|
||||
ua = UserAgent()
|
||||
|
||||
import random
|
||||
import threading
|
||||
|
||||
# 开启线程锁
|
||||
@@ -335,9 +324,9 @@ scheduler.start()
|
||||
# PANDORA_UPLOAD_URL = 'files.pandoranext.com'
|
||||
|
||||
|
||||
VERSION = '0.7.9.1'
|
||||
VERSION = '0.7.9.3'
|
||||
# VERSION = 'test'
|
||||
UPDATE_INFO = '适配调用team对话,提供查询ChatGPT-Account-ID的/getAccountID接口'
|
||||
UPDATE_INFO = '支持最新的gpt-4-o模型,并重定向gpt-4-mobile到gpt-4-s'
|
||||
# UPDATE_INFO = '【仅供临时测试使用】 '
|
||||
|
||||
with app.app_context():
|
||||
@@ -448,7 +437,11 @@ with app.app_context():
|
||||
"name": name.strip(),
|
||||
"ori_name": "gpt-3.5-turbo"
|
||||
})
|
||||
|
||||
for name in GPT_4_O_NEW_NAMES:
|
||||
gpts_configurations.append({
|
||||
"name": name.strip(),
|
||||
"ori_name": "gpt-4-o"
|
||||
})
|
||||
logger.info(f"GPTS 配置信息")
|
||||
|
||||
# 加载配置并添加到全局列表
|
||||
@@ -719,7 +712,7 @@ def send_text_prompt_and_get_response(messages, api_key, account_id, stream, mod
|
||||
message_id = str(uuid.uuid4())
|
||||
content = message.get("content")
|
||||
|
||||
if isinstance(content, list) and ori_model_name != 'gpt-3.5-turbo':
|
||||
if isinstance(content, list) and ori_model_name not in ['gpt-3.5-turbo']:
|
||||
logger.debug(f"gpt-vision 调用")
|
||||
new_parts = []
|
||||
attachments = []
|
||||
@@ -847,13 +840,9 @@ def send_text_prompt_and_get_response(messages, api_key, account_id, stream, mod
|
||||
"action": "next",
|
||||
"messages": formatted_messages,
|
||||
"parent_message_id": str(uuid.uuid4()),
|
||||
"model": "gpt-4-mobile",
|
||||
"model": "gpt-4",
|
||||
"timezone_offset_min": -480,
|
||||
"suggestions": [
|
||||
"Give me 3 ideas about how to plan good New Years resolutions. Give me some that are personal, family, and professionally-oriented.",
|
||||
"Write a text asking a friend to be my plus-one at a wedding next month. I want to keep it super short and casual, and offer an out.",
|
||||
"Design a database schema for an online merch store.",
|
||||
"Compare Gen Z and Millennial marketing strategies for sunglasses."],
|
||||
"suggestions": [],
|
||||
"history_and_training_disabled": False,
|
||||
"conversation_mode": {"kind": "primary_assistant"}, "force_paragen": False, "force_rate_limit": False
|
||||
}
|
||||
@@ -879,6 +868,28 @@ def send_text_prompt_and_get_response(messages, api_key, account_id, stream, mod
|
||||
"force_paragen": False,
|
||||
"force_rate_limit": False
|
||||
}
|
||||
elif ori_model_name == 'gpt-4-o':
|
||||
payload = {
|
||||
# 构建 payload
|
||||
"action": "next",
|
||||
"messages": formatted_messages,
|
||||
"parent_message_id": str(uuid.uuid4()),
|
||||
"model": "gpt-4o",
|
||||
"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
|
||||
}
|
||||
elif 'gpt-4-gizmo-' in model:
|
||||
payload = generate_gpts_payload(model, formatted_messages)
|
||||
if not payload:
|
||||
@@ -913,7 +924,7 @@ def send_text_prompt_and_get_response(messages, api_key, account_id, stream, mod
|
||||
if NEED_DELETE_CONVERSATION_AFTER_RESPONSE:
|
||||
logger.debug(f"是否保留会话: {NEED_DELETE_CONVERSATION_AFTER_RESPONSE == False}")
|
||||
payload['history_and_training_disabled'] = True
|
||||
if ori_model_name != 'gpt-3.5-turbo':
|
||||
if ori_model_name not in ['gpt-3.5-turbo', 'gpt-4-o']:
|
||||
if CUSTOM_ARKOSE:
|
||||
token = get_token()
|
||||
payload["arkose_token"] = token
|
||||
@@ -1492,7 +1503,8 @@ def data_fetcher(upstream_response, data_queue, stop_event, last_data_time, api_
|
||||
execution_output_image_url_buffer = f"{UPLOAD_BASE_URL}/{today_image_url}"
|
||||
|
||||
else:
|
||||
logger.error(f"下载图片失败: {image_download_response.text}")
|
||||
logger.error(
|
||||
f"下载图片失败: {image_download_response.text}")
|
||||
|
||||
execution_output_image_id_buffer = image_file_id
|
||||
|
||||
@@ -2363,7 +2375,22 @@ def catch_all(path):
|
||||
logger.debug(f"请求头: {request.headers}")
|
||||
logger.debug(f"请求体: {request.data}")
|
||||
|
||||
return jsonify({"message": "Welcome to Inker's World"}), 200
|
||||
html_string = f"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<p> Thanks for using RefreshToV1Api {VERSION}</p>
|
||||
<p> 感谢Ink-Osier大佬的付出,敬礼!!!</p>
|
||||
<p><a href="https://github.com/Yanyutin753/RefreshToV1Api">项目地址</a></p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return html_string, 500
|
||||
|
||||
|
||||
@app.route('/images/<filename>')
|
||||
|
||||
Reference in New Issue
Block a user