赞
踩
最近chatgpt火热,chatgpt也能根据文本生成图片
- exports.getimg = async (types, id, propmt) => {
- try {
- propmt = propmt.slice(propmt.indexOf("图"), propmt.length - 1)
- const resonse = await openai.createImage({
- prompt: propmt,
- n: 1,
- size: "512x512",
- });
- image_url = response.data.data[0].url;
- await SendMessage.SendMessage(types, `[CQ:image,file=${image_url}]`, id)
- } catch (e) {
- if (e) {
- await SendMessage.SendMessage(types, `图片出错了${e}`, id)
- }
- }
-
- }
其中n是返回的图片数目,size是尺寸,propmt是输入的文本
npm insatll openai
const {Configuration, OpenAIApi} = require("openai");
- const {Configuration, OpenAIApi} = require("openai");
- const configuration = new Configuration({
- apiKey: token.apikey, //自己的apikey,要有openai账号
- });
- const openai = new OpenAIApi(configuration);
- exports.getimg = async (types, id, propmt) => {
- try {
- propmt = propmt.slice(propmt.indexOf("图"), propmt.length - 1)
- const resonse = await openai.createImage({
- prompt: propmt,
- n: 1,
- size: "512x512",
- });
- image_url = response.data.data[0].url;
- // console.log(image_url)
- // fs.writeFileSync("chatgpt.txt", "Human:" + propmt + "\n" + image_url)
- await SendMessage.SendMessage(types, `[CQ:image,file=${image_url}]`, id)
-
- } catch (e) {
- if (e) {
- await SendMessage.SendMessage(types, `图片出错了${e}`, id)
- }
- }
-
- }
- //只有管理才能调用此方法
- if (data.user_id === config.manager[0]) {
- if (data.message.includes("画图")) {
- chatgpt.getimg("group", data.group_id, data.message)
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。