diff --git a/playground/generate_image.py b/playground/generate_image.py index 04aa9c1..f943de0 100755 --- a/playground/generate_image.py +++ b/playground/generate_image.py @@ -46,7 +46,7 @@ async def generate( try: agent = GenerateImageInfer.build_generate( prompt=prompt, - model=Model.NAI_DIFFUSION_4_CURATED_PREVIEW, + model=Model.NAI_DIFFUSION_3, character_prompts=[ Character( prompt="1girl", @@ -65,7 +65,7 @@ async def generate( decrisp_mode=False, variety_boost=True, # Checkbox in novelai.net - ) + ).set_mutual_exclusion(True) print(f"charge: {agent.calculate_cost(is_opus=True)} if you are vip3") print(f"charge: {agent.calculate_cost(is_opus=False)} if you are not vip3") result = await agent.request( diff --git a/pyproject.toml b/pyproject.toml index e08584f..2412207 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "novelai-python" -version = "0.7.1" +version = "0.7.2" description = "NovelAI Python Binding With Pydantic" authors = [ { name = "sudoskys", email = "coldlando@hotmail.com" }, diff --git a/src/novelai_python/sdk/ai/generate_image/__init__.py b/src/novelai_python/sdk/ai/generate_image/__init__.py index 1f9fc2f..0b62000 100755 --- a/src/novelai_python/sdk/ai/generate_image/__init__.py +++ b/src/novelai_python/sdk/ai/generate_image/__init__.py @@ -344,6 +344,35 @@ def add_image_to_black_background( class GenerateImageInfer(ApiBaseModel): _endpoint: str = PrivateAttr("https://image.novelai.net") + _mutual_exclusion: bool = PrivateAttr(False) + """Positive words and negative words are mutually exclusive, and conflicting negative words are deleted first.""" + _quality_modifier: bool = PrivateAttr(True) + """Add Quality Modifier To Input""" + + def set_mutual_exclusion(self, value: bool): + """ + **Enable This will modify the negative prompt.** + Default is False. + + Positive words and negative words are mutually exclusive, and conflicting negative words are deleted first. + :param value: bool + :return: self + """ + self._mutual_exclusion = bool(value) + return self + + def set_quality_modifier(self, value: bool): + """ + **Enable This will modify the input prompt.** + Default is True. + + Add Quality Modifier To Input. + Whether to add the quality vocabulary used by the web application. + :param value: + :return: + """ + self._quality_modifier = bool(value) + return self @property def endpoint(self): @@ -429,7 +458,19 @@ def enhance_message(_prompt): ) return _prompt - self.input = enhance_message(self.input) + if self._quality_modifier: + logger.trace("Enhancing input with quality modifier, will modify input prompt.") + self.input = enhance_message(self.input) + + if self._mutual_exclusion: + logger.trace("Mutual exclusion is enabled, will modify negative prompt.") + input_prompt = {x.strip(): x for x in self.input.split(",")} + uc_prompt = {x.strip(): x for x in self.parameters.negative_prompt.split(",")} + # 以 input 为主,如果 uc_prompt 有 input 中的内容,就删除 + for key in input_prompt: + if key in uc_prompt: + uc_prompt.pop(key) + self.parameters.negative_prompt = ",".join(uc_prompt.values()) @model_validator(mode="after") def _build_nai4_prompt(self): @@ -467,7 +508,9 @@ def _build_nai4_prompt(self): @model_validator(mode="after") def _backend_logic(self): """ - Backend logic for GenerateImageInfer. + Calibration results. + + **NOTE: It is forbidden to write logic that does not belong to novelai.net here** :return: self """ if self.action == Action.GENERATE: @@ -949,7 +992,9 @@ async def request(self, override_headers: Optional[dict] = None, ) -> ImageGenerateResp: """ - Generate images using NovelAI's diffusion models. According to our Terms of Service, all generation requests must be initiated by a human action. Automating text or image generation to create excessive load on our systems is not allowed. + **Generate images using NovelAI's diffusion models.** + + According to our Terms of Service, all generation requests must be initiated by a human action. Automating text or image generation to create excessive load on our systems is not allowed. :param override_headers: the headers to override :param session: session