Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: openai>=1.0时绘图命令不兼容 #628

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions config-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,13 @@
}

# OpenAI的Image API的参数
# 具体请查看OpenAI的文档: https://beta.openai.com/docs/api-reference/images/create
# 具体请查看OpenAI的文档: https://platform.openai.com/docs/api-reference/images/create
image_api_params = {
"size": "256x256", # 图片尺寸,支持256x256, 512x512, 1024x1024
"model": "dall-e-2", # 默认使用 dall-e-2 模型,也可以改为 dall-e-3
# 图片尺寸
# dall-e-2 模型支持 256x256, 512x512, 1024x1024
# dall-e-3 模型支持 1024x1024, 1792x1024, 1024x1792
"size": "256x256",
}

# 跟踪函数调用
Expand Down
1 change: 1 addition & 0 deletions override-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"temperature": 0.9
},
"image_api_params": {
"model": "dall-e-2",
"size": "256x256"
},
"trace_function_calls": false,
Expand Down
5 changes: 3 additions & 2 deletions pkg/openai/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import openai
from openai.types import images_response

from ..openai import keymgr
from ..utils import context
Expand Down Expand Up @@ -65,7 +66,7 @@ def request_completion(self, messages: list):

yield resp

def request_image(self, prompt) -> dict:
def request_image(self, prompt) -> images_response.ImagesResponse:
"""请求图片接口回复

Parameters:
Expand All @@ -77,7 +78,7 @@ def request_image(self, prompt) -> dict:
config = context.get_config_manager().data
params = config['image_api_params']

response = openai.Image.create(
response = self.client.images.generate(
prompt=prompt,
n=1,
**params
Expand Down
2 changes: 1 addition & 1 deletion pkg/qqbot/cmds/funcs/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def process(cls, ctx: aamgr.Context) -> tuple[bool, list]:
res = session.draw_image(" ".join(ctx.params))

logging.debug("draw_image result:{}".format(res))
reply = [mirai.Image(url=res['data'][0]['url'])]
reply = [mirai.Image(url=res.data[0].url)]
config = context.get_config_manager().data
if config['include_image_description']:
reply.append(" ".join(ctx.params))
Expand Down
Loading