From 0299b0f95f6c264ca4dbf8809fb1e09c00702ec4 Mon Sep 17 00:00:00 2001
From: qingxu fu <505030475@qq.com>
Date: Fri, 10 Nov 2023 20:59:08 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81DALLE3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
crazy_functional.py | 17 +++++++++++---
crazy_functions/图片生成.py | 31 ++++++++++++++++++++++++--
docs/translate_english.json | 2 +-
docs/translate_japanese.json | 2 +-
docs/translate_traditionalchinese.json | 2 +-
5 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/crazy_functional.py b/crazy_functional.py
index 2d7fa74..60c8569 100644
--- a/crazy_functional.py
+++ b/crazy_functional.py
@@ -349,18 +349,29 @@ def get_crazy_functions():
print('Load function plugin failed')
try:
- from crazy_functions.图片生成 import 图片生成
+ from crazy_functions.图片生成 import 图片生成, 图片生成_DALLE3
function_plugins.update({
"图片生成(先切换模型到openai或api2d)": {
"Group": "对话",
"Color": "stop",
"AsButton": False,
"AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
- "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示
- "Info": "图片生成 | 输入参数字符串,提供图像的内容",
+ "ArgsReminder": "在这里输入分辨率, 如1024x1024(默认)", # 高级参数输入区的显示提示
+ "Info": "使用DALLE2生成图片 | 输入参数字符串,提供图像的内容",
"Function": HotReload(图片生成)
},
})
+ function_plugins.update({
+ "图片生成_DALLE3(先切换模型到openai或api2d)": {
+ "Group": "对话",
+ "Color": "stop",
+ "AsButton": False,
+ "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
+ "ArgsReminder": "在这里输入分辨率, 如1024x1024(默认)", # 高级参数输入区的显示提示
+ "Info": "使用DALLE3生成图片 | 输入参数字符串,提供图像的内容",
+ "Function": HotReload(图片生成_DALLE3)
+ },
+ })
except:
print('Load function plugin failed')
diff --git a/crazy_functions/图片生成.py b/crazy_functions/图片生成.py
index 1b7dff5..95b4481 100644
--- a/crazy_functions/图片生成.py
+++ b/crazy_functions/图片生成.py
@@ -3,7 +3,7 @@ from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
import datetime
-def gen_image(llm_kwargs, prompt, resolution="256x256"):
+def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2"):
import requests, json, time, os
from request_llms.bridge_all import model_info
@@ -23,6 +23,7 @@ def gen_image(llm_kwargs, prompt, resolution="256x256"):
'prompt': prompt,
'n': 1,
'size': resolution,
+ 'model': model,
'response_format': 'url'
}
response = requests.post(url, headers=headers, json=data, proxies=proxies)
@@ -58,7 +59,7 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 ....."))
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
- resolution = plugin_kwargs.get("advanced_arg", '256x256')
+ resolution = plugin_kwargs.get("advanced_arg", '1024x1024')
image_url, image_path = gen_image(llm_kwargs, prompt, resolution)
chatbot.append([prompt,
f'图像中转网址:
`{image_url}`
'+
@@ -67,3 +68,29 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
f'本地文件预览: