Skip to content

Commit

Permalink
[API] Fix Quality Tags for v2 and v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Aedial committed Nov 17, 2023
1 parent 7e699d6 commit 146ba3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion novelai_api/_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,19 @@ async def generate_image(

quality_toggle = settings["qualityToggle"]
if quality_toggle:
prompt = f"masterpiece, best quality, {prompt}"
if model in (
ImageModel.Anime_Full,
ImageModel.Anime_Curated,
ImageModel.Furry,
ImageModel.Inpainting_Anime_Full,
ImageModel.Inainting_Anime_Curated,
ImageModel.Inpainting_Furry,
):
prompt = f"masterpiece, best quality, {prompt}"
elif model is ImageModel.Anime_v2:
prompt = f"very aesthetic, best quality, absurdres, {prompt}"
elif model in (ImageModel.Anime_v3, ImageModel.Inpainting_Anime_v3):
prompt = f"{prompt}, best quality, amazing quality, very aesthetic, absurdres"

async for e in self._parent.low_level.generate_image(prompt, model, action, settings):
yield e
10 changes: 9 additions & 1 deletion novelai_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from base64 import b64decode, b64encode, urlsafe_b64encode
from hashlib import blake2b
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
from typing import Any, AsyncGenerator, AsyncIterable, Dict, Iterable, List, Optional, Tuple, Union
from zlib import MAX_WBITS, Z_BEST_COMPRESSION
from zlib import compressobj as deflate_obj
from zlib import decompress as inflate
Expand Down Expand Up @@ -367,4 +367,12 @@ def tokenize_if_not(model: Model, o: Union[str, List[int]]) -> List[int]:
return Tokenizer.encode(model, o)


async def gather_asyncgenerator(agen: Union[AsyncGenerator[Any, None], AsyncIterable[Any]]) -> List[Any]:
"""
Gather all the items of an async generator into a list
"""

return [item async for item in agen]


# TODO: story tree builder

0 comments on commit 146ba3d

Please sign in to comment.