利用chatglm生成ai绘画tag,中国人就用中国ai!

声明:此功能还在开发中,没有正式发布到插件市场

利用chatglm生成绘画tag,就像利用chatgpt生成绘画tag一样
A@BO4FK`YBCZ2T{}BS67O@X

这个想法最早是由群友smzh(QQ:1042667215)提出并初步实现的,效果如图:

但是在实际运行中还会遇到很多问题;
比如glm会莫名夹杂一些中文:


生成的产物比起tag更像自然语言

会出现一些多余的句子

总之就是bug还很多

核心代码如下





ctx
    .command(
      "glmmtg <text:text>",
      "输入你想画的画面,发送给ChatGLM,让ChatGLM来帮你写tag"
    )
    .action(async ({ session }, text) => {
      const apiAddress = config.myServerUrl + "chatglm?msg=";
      const defaultText =
        "chatglm?msg=用尽可能多的英文标签详细的描述一幅画面,用碎片化的单词标签而不是句子去描述这幅画,描述词尽量丰富,每个单词之间用逗号分隔,例如在描述白发猫娘的时候,你应该用:white hair,cat girl,cat ears,cute,girl,beautiful,lovely等英文标签词汇。你现在要描述的是:";
      const userText = defaultText + text;
      let local_memory_id = Math.floor(Math.random() * 1000000) + 1;
      let user_id =
        "&usrid=|t4wefan's public" +
        String(
          "|channel_id=" +
            String(
              String(session.channelId) +
                String(
                  "|usr_id=" +
                    String(
                      String(session.userId) +
                        String("|secret=" + String(local_memory_id) + "|")
                    )
                )
            )
        );
      const response = await ctx.http.get(apiAddress + userText + user_id);
      if (config.send_glmmtg_response) {
        await session.send(`${config.prefix} ${response}`);
      }
      await session.execute(`config.prefix "${response}"`);
      await ctx.http.get(apiAddress + "chatglm?msg=clear" + user_id, {
        responseType: "text",
      });
    });

配置项是

export interface Config {
  myServerUrl: string;
  send_glmmtg_response: boolean;
  prefix: string;
}

export const Config: Schema<Config> = Schema.object({
  myServerUrl: Schema.string().description("后端服务器地址").default(""),
  send_glmmtg_response: Schema.boolean()
    .description("使用glmmtg的时候是否会发送tag到会话框")
    .default(false),
  prefix: Schema.string().description("跑图机器人的前缀").default("rr"),
});

ps:
这段代码是群友smzh写的,我在这个基础上加入了可自定义前缀。
而smzh是在glm-testbot插件和咩咩咩(miemiemie)的gpt-girlfriend的基础上写出的,glm-testbot插件的前身是t4wefan的blockly插件,而gpt-girlfriend的execute这段也取材于42的插件。

不知不觉glm-testbot已经是多个作者联合开发的插件了呢

快说谢谢42

3 个赞

但是实际运用中不能直接调用rryth/novelai,即对自己发出画图命令,就是说必须需要两个机器人在场时才能实现,在这里也请教一下这段代码在哪里出现了问题。

const response = await ctx.http.get(apiAddress + userText + user_id);
      if (config.send_glmmtg_response) {
        await session.send(`${config.prefix} ${response}`);
      }
      await session.execute(`config.prefix "${response}"`);
      await ctx.http.get(apiAddress + "chatglm?msg=clear" + user_id, {
        responseType: "text",
      });
    });

这里 await session.send(${config.prefix} ${response});是可以正常运行的;
但是await session.execute(config.prefix "${response}");不行

1 个赞

这就是石头汤的故事!

1 个赞

最新效果:
插件和版本:koishi-plugin-glm-testbot 1.2.4-test


1 个赞

看上去效果很不错!

没关系的,自然语言也可以正确处理

可以过滤掉他们,只留下英文字符,标点,以及空格

1 个赞

如果直接生成中文tag好像会报错(这里用的画图插件是rryth),如图:

1 个赞