koishijs/novelai-bot

Feature: 关于增加类似dynamic-prompts插件的or语法功能

cacan180 opened this issue · 18 comments

Scope

Stable Diffusion WebUI (AUTOMATIC1111)

Describe the problem related to the feature request

在调用NAI时,有时需要切换绘画风格,或者增加一些随机性,但是SD webui的内部可以实现的插件(SD-dynamic_prompts,stable-diffusion-webui-wildcards)NAI调用不到,所以希望NAI也能支持这个功能。
增加随机性是指(借用dynamic_prompts的语法表述):
an {red|yellow} apple
会随机生成 an red apple或者an yellow apple的两种提示词之一

Describe the solution you'd like

在NAI的语法中增加对or语法的支持

Describe alternatives you've considered

是否可以从API调度SD webui中的插件实现语法支持?

Additional context

另外就是,如果在prompts里写这种or的条件句,可能会导致发送图片和关键信息)时候的信息过长编写prompts时候输入过于复杂,是否可以同时考虑后续增加类似SD-dynamic_prompts的wildcard功能。
将prompts写入command.txt中,当使用__command__作为提示词时,在command.txt中随机提取一行填充为提示词。
当然,如果能从API调度插件的话,这个问题就已经解决了。

Currently, we DON'T support ANY extensions or scripts of sd-webui, so even if we add this syntax support, you'll not still be able to use that feature the extension provided.

In the meantime, novelai plugin knows nothing about the backend, it doesn't know which model the WebUI running, which scripts could be used, or even whether the payload is correct (which broke our plugin several times because WebUI changed their API), there should be always an extra effort for the user to remember and type these different things that you mentioned above.

那我认为如果在您精力允许的情况下,可以在NAI的层面对这个语法进行一种实现。让or的语法在koishi中完成,并将结果发送到webUI进行处理会比较好(实质上webui只是接受了一个固定的结果,对现有和webui的交互不会有任何改动)。当然,我不知道这个功能的重要性是否值得去进行更新支持。
我可以描绘一个环境使用它,比如我在Stable diffusion中已经固定下来了一个大家都很喜欢的风格,在大家进行创作的时候加入or的随机性来增加趣味性。有些时候,用户只是想要一张好看的图,但是你让他去确定发色,确定体征,确定pose,会拉高使用难度。

Yeah, supporting this syntax is not a difficult thing. But what I pointed out above is that even if we have supported this syntax, WebUI would not just magically enable the script and generate those images you want. Not only there is a property in the API payload called script_name that should be passed, but many scripts also require arguments.

Once we support this, that means, let me take your example here, you should write something like:
Yeah, you should pass all of the arguments here and the correct script title
In this case, the title is also dynamically updated between version bumps!

nai --script "Dynamic Prompts v2.5.6"
    --script-args "
        is_enabled=true,
        is_combinatorial=false,
        combinatorial_batches=1,
        is_magic_prompt=false,
        is_feeling_lucky=false,
        is_attention_grabber=false,
        min_attention=1.1,
        max_attention=1.5,
        magic_prompt_length=100,
        magic_temp_value=0.7,
        use_fixed_seed=false,
        unlink_seed_from_prompt=false,
        disable_negative_prompt=true,
        enable_jinja_templates=false,
        no_image_generation=false,
        max_generations=0,
        magic_model=Gustavosta/MagicPrompt-Stable-Diffusion,
        magic_blocklist_regex=
    "
    an (yellow|red) apple

Okay, you might say, what about adding a new configuration for this feature?
Well, it could be a configuration, too. But would you like to modify the configuration every time that you want to change the script you're using, or when there's an update that causes the script name or arguments to no longer be usable?

Why talk about this is that I want to show you that the script support is complicated and user-unfriendly, so it would not be in our plan currently. But if there are kind people who want to deal with these bananas, I would appreciate the who.

In a nutshell, it is implementable and wonderful. But considering our schedule and abilities, it's a pity that I cannot list this in our plan. Sorry!

Sorry to hear that, but it's ok and thanks for the detailed explanation.

@MaikoTan
我认为因为我功能的描述不太准确而导致您对此功能思考的过于复杂,我个人的想法并不是要将SD-dynamic_prompts这个脚本移植到koishi中去完全实现。而是主要希望实现其中的random prompts功能和wildcard功能,这样做的意义就像上面表述的那样,能降低用户使用门槛,让管理员做出方便的preset让用户进行调用。

实际上逻辑层面我想跟您表述的功能是类似于这样的

NAI 接受到 an {red|yellow} apple

NAI 识别为 an red apple

SDwebUI prompts:an red apple

我觉得这样做的好处就是,因为模型训练素材来源的问题,大部分模型生成的图会普遍趋向于一个定式。例如我画 1 girl的时候,极大的概率会出现黑色头发或者黄色头发的角色。而我需要其他发色的时候我就需要进行强调,当我需要概率基本相同时出现不同的发色的case时就可以发挥作用。于是在随机的将可控提示词进行组合,可以在保证质量的前提下得出尽可能多的不重复内容的结果。

我个人的想法,将这些打包好的随机数写到baseprompt属性中作为preset(当然如果做一个类似wildcard功能的东西进行变量的管理应该会更好),用户要做的仅仅是执行一个nai 1girl就可以得出质量可控的多样化结果。
为什么我尝试继续解释这件事,我个人的理解在于,novelai的初衷就是为了降低使用门槛,复杂的事情由您这样的开发者,和我们这类给他们提供算力和bot的人来完成,用户面对的应该是尽可能符合他们使用习惯和便利的东西。

Sorry I am confused. So you are referring to the dynamic extension, but we implement part of its features on our side?
In my opinion, the preset feature seems like be covered by #58 recipe feature, or at least could be implemented in the same thread. Is it what you mean?
If so, it is a doable feature now.

BTW, Although the issue #58 was closed, but I would work on this when anyone open a new issue to talk about the details of it.

OK,let me check the issue #58 and give you a feedback again. btw, I know it is quiet impolite to continue to leave comments in closed issues, thank you for your tolerance.

I hav read the function description of presets in the issue #58.It's what I want, but I think it should be more functional. These functions are exactly what I described 'wildcard' and 'or command' in this issue.
1.The preset should be used as a collection of prompts, which can be called with other prompts.
2.Like the concept of wildcard, preset can have multiple lines, and a line will be randomly selected when executing it (is equivalent to ‘or‘ command)

In this way, it is more convenient to input and combine in use.

Here is an example:
preset1

((((realistic hair)))),((((realistic))))

preset2

looking at viewer
looking to the side
looking at another
looking away

And when i use this command
nai 1girl,__preset1__,standing,__preset2__

Then novelai will get four results

nai 1girl,((((realistic hair)))),((((realistic)))),standing,looking at viewer
nai 1girl,((((realistic hair)))),((((realistic)))),standing,looking to the side
nai 1girl,((((realistic hair)))),((((realistic)))),standing,looking at another
nai 1girl,((((realistic hair)))),((((realistic)))),standing,looking away

Then select one and send it to webui

@MaikoTan

I do a research for this feature and also recipe that mentioned in #58 these days. I think this is a bit complicated to merge into our plugin, sorry I could not implement it in our side.
BUT, I could make it a new plugin which could parse the syntax that you described above and then programmatically invoke novelai to generate the image(s).

Thank you for your efforts, no matter which node implements this function.

This issue is stale because it has been open 15 days with no activity.
Remove stale label or comment or this will be closed in 5 days.

@shigma Is there a way to mark an issue never stale?

@MaikoTan Issues only with certain labels can be marked as stale.

ai-tag中已实现此功能,故关闭这个comment。

ai-tag中已实现此功能,故关闭这个comment。

It is not exactly the feature described in this issue, and I didn't say I would not implement this.
So I wanna leave this issue keeping open until it is got implemented.

使用 5c8a76c 可以一定程度上实现该功能,虽然不是非常优雅