[feat] 增加对 GPT-4-Mobile 模型的支持

This commit is contained in:
Wizerd
2023-12-15 09:46:42 +08:00
parent ac8068bc23
commit 5cb6e29732
3 changed files with 37 additions and 5 deletions

View File

@@ -8,6 +8,10 @@
# 更新日志 # 更新日志
### 0.0.8
- 增加了对 GPT-4-Mobile 模型的支持,模型名为 `gpt-4-mobile`
### 0.0.7 ### 0.0.7
- 一定程度上修复图片无法正常生成的问题 - 一定程度上修复图片无法正常生成的问题
@@ -51,7 +55,7 @@ services:
environment: environment:
- OPENAI_API_KEY=<Pandora-Next 的 fk> - OPENAI_API_KEY=<Pandora-Next 的 fk>
- BASE_URL=<backend-to-api容器地址> - BASE_URL=<backend-to-api容器地址>
- CUSTOM_MODELS=+gpt-4-s,+gpt-4-classic - CUSTOM_MODELS=+gpt-4-s,+gpt-4-classic,+gpt-4-mobile
``` ```
@@ -67,4 +71,8 @@ services:
### 绘图 ### 绘图
![api-3](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/58d140fb-56b2-445c-946d-2d5c5c6a2ec0) ![api-3](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/8eea9436-12ee-46b1-86c1-67e7e97da83a)
### GPT-4-Mobile
![api-4](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/537422fc-ef7a-4896-b2f9-750f7fe1334d)

View File

@@ -2,7 +2,7 @@ version: '3'
services: services:
backend-to-api: backend-to-api:
image: wizerd/pandora-to-api:0.0.7 image: wizerd/pandora-to-api:0.0.8
restart: always restart: always
ports: ports:
- "50011:33333" - "50011:33333"
@@ -16,7 +16,7 @@ services:
uploader: uploader:
image: wizerd/pandora-to-api:0.0.7 image: wizerd/pandora-to-api:0.0.8
restart: always restart: always
entrypoint: ["python3", "/app/upload.py"] entrypoint: ["python3", "/app/upload.py"]
volumes: volumes:

26
main.py
View File

@@ -26,7 +26,16 @@ BASE_URL = os.getenv('BASE_URL', '')
PROXY_API_PREFIX = os.getenv('PROXY_API_PREFIX', '') PROXY_API_PREFIX = os.getenv('PROXY_API_PREFIX', '')
UPLOAD_BASE_URL = os.getenv('UPLOAD_BASE_URL', '') UPLOAD_BASE_URL = os.getenv('UPLOAD_BASE_URL', '')
VERSION = '0.0.8'
UPDATE_INFO = '增加了对 GPT-4 Mobile 的支持'
with app.app_context(): with app.app_context():
# 输出版本信息
print(f"==========================================")
print(f"Version: {VERSION}")
print(f"Update Info: {UPDATE_INFO}")
if not BASE_URL: if not BASE_URL:
raise Exception('BASE_URL is not set') raise Exception('BASE_URL is not set')
else: else:
@@ -35,6 +44,9 @@ with app.app_context():
raise Exception('PROXY_API_PREFIX is not set') raise Exception('PROXY_API_PREFIX is not set')
else: else:
print(f"PROXY_API_PREFIX: {PROXY_API_PREFIX}") print(f"PROXY_API_PREFIX: {PROXY_API_PREFIX}")
print(f"==========================================")
# 定义获取 token 的函数 # 定义获取 token 的函数
def get_token(): def get_token():
@@ -47,6 +59,7 @@ def get_token():
return None return None
import os import os
accessable_model_list = ['gpt-4-classic', 'gpt-4-s', 'gpt-4-mobile']
# 定义发送请求的函数 # 定义发送请求的函数
def send_text_prompt_and_get_response(messages, api_key, stream, model): def send_text_prompt_and_get_response(messages, api_key, stream, model):
@@ -177,6 +190,18 @@ def send_text_prompt_and_get_response(messages, api_key, stream, model):
"history_and_training_disabled": False, "history_and_training_disabled": False,
"conversation_mode":{"kind":"primary_assistant"},"force_paragen":False,"force_rate_limit":False "conversation_mode":{"kind":"primary_assistant"},"force_paragen":False,"force_rate_limit":False
} }
elif model == 'gpt-4-mobile':
payload = {
# 构建 payload
"action": "next",
"messages": formatted_messages,
"parent_message_id": str(uuid.uuid4()),
"model":"gpt-4-mobile",
"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."],
"history_and_training_disabled": False,
"conversation_mode":{"kind":"primary_assistant"},"force_paragen":False,"force_rate_limit":False
}
response = requests.post(url, headers=headers, json=payload, stream=stream) response = requests.post(url, headers=headers, json=payload, stream=stream)
# print(response) # print(response)
return response return response
@@ -293,7 +318,6 @@ def replace_complete_citation(text, citations):
return replaced_text, remaining_text, is_potential_citation return replaced_text, remaining_text, is_potential_citation
accessable_model_list = ['gpt-4-classic', 'gpt-4-s']
# 定义 Flask 路由 # 定义 Flask 路由
@app.route('/v1/chat/completions', methods=['POST']) @app.route('/v1/chat/completions', methods=['POST'])
def chat_completions(): def chat_completions():