novelai-python 0.4.15__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {novelai_python-0.4.15 → novelai_python-0.5.0}/PKG-INFO +27 -3
- {novelai_python-0.4.15 → novelai_python-0.5.0}/README.md +24 -2
- {novelai_python-0.4.15 → novelai_python-0.5.0}/pyproject.toml +3 -1
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/__init__.py +0 -1
- novelai_python-0.5.0/src/novelai_python/_enum.py +94 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/generate.py +6 -3
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/generate_stream.py +6 -3
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/_cost.py +6 -5
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/_enum.py +82 -76
- novelai_python-0.5.0/src/novelai_python/sdk/ai/generate/__init__.py +411 -0
- novelai_python-0.5.0/src/novelai_python/sdk/ai/generate/_const.py +128 -0
- novelai_python-0.5.0/src/novelai_python/sdk/ai/generate/_enum.py +2281 -0
- novelai_python-0.5.0/src/novelai_python/sdk/ai/generate/_schema.py +233 -0
- novelai_python-0.5.0/src/novelai_python/sdk/ai/generate/themes.json +362 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/generate_image/__init__.py +18 -11
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/generate_stream.py +47 -53
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/user/login.py +1 -1
- novelai_python-0.5.0/src/novelai_python/tokenizer/__init__.py +211 -0
- novelai_python-0.4.15/src/novelai_python/tokenizer/simple_tokenizer.py → novelai_python-0.5.0/src/novelai_python/tokenizer/clip_simple_tokenizer.py +31 -24
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/utils/__init__.py +8 -4
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/utils/encode.py +35 -19
- novelai_python-0.4.15/src/novelai_python/sdk/ai/generate/__init__.py +0 -232
- novelai_python-0.4.15/src/novelai_python/sdk/ai/generate/_const.py +0 -136
- novelai_python-0.4.15/src/novelai_python/sdk/ai/generate/_enum.py +0 -77
- novelai_python-0.4.15/src/novelai_python/sdk/ai/generate/_preset.py +0 -225
- novelai_python-0.4.15/src/novelai_python/tokenizer/NOTICE.MD +0 -12
- novelai_python-0.4.15/src/novelai_python/tokenizer/__init__.py +0 -226
- novelai_python-0.4.15/src/novelai_python/tokenizer/bpe_simple_vocab_16e6.txt.gz +0 -0
- novelai_python-0.4.15/src/novelai_python/tokenizer/gpt2-genji_tokenizer.json +0 -1
- novelai_python-0.4.15/src/novelai_python/tokenizer/gpt2_tokenizer.json +0 -1
- novelai_python-0.4.15/src/novelai_python/tokenizer/pile_tokenizer.json +0 -1
- {novelai_python-0.4.15 → novelai_python-0.5.0}/LICENSE +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/NOTICE.MD +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_exceptions.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/generate_image.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/generate_voice.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/upscale.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/schema.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/user/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/user/information.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/user/login.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/user/subscription.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/credential/ApiToken.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/credential/JwtToken.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/credential/UserAuth.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/credential/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/credential/_base.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/LICENSE +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/_const.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/augment_image/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/augment_image/_enum.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/generate_image/suggest_tags.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/generate_voice/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/generate_voice/_enum.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/ai/upscale.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/schema.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/user/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/user/information.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/sdk/user/subscription.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/server.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tokenizer/nerdstash_v1.model +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tokenizer/nerdstash_v2.model +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tokenizer/novelai.model +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tokenizer/novelai_v2.model +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/image_metadata/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/image_metadata/lsb_extractor.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/image_metadata/lsb_injector.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/paint_mask/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/random_prompt/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/random_prompt/tag.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/random_prompt/tag_character.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/tool/random_prompt/tag_nsfw.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/utils/useful.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/__init__.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_generate_voice.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_random_prompt.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_server.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_server_run.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_upscale.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_user_information.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_user_login.py +0 -0
- {novelai_python-0.4.15 → novelai_python-0.5.0}/tests/test_user_subscription.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: novelai-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: NovelAI Python Binding With Pydantic
|
|
5
5
|
Author-Email: sudoskys <coldlando@hotmail.com>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -27,6 +27,8 @@ Requires-Dist: pynacl>=1.5.0
|
|
|
27
27
|
Requires-Dist: ftfy>=6.2.0
|
|
28
28
|
Requires-Dist: regex>=2023.12.25
|
|
29
29
|
Requires-Dist: tokenizers>=0.15.2
|
|
30
|
+
Requires-Dist: json-repair>=0.29.4
|
|
31
|
+
Requires-Dist: robust-downloader>=0.0.2
|
|
30
32
|
Provides-Extra: testing
|
|
31
33
|
Requires-Dist: pytest>=7.4.4; extra == "testing"
|
|
32
34
|
Requires-Dist: pytest-asyncio>=0.23.4; extra == "testing"
|
|
@@ -50,6 +52,7 @@ The goal of this repository is to use Pydantic to build legitimate requests to a
|
|
|
50
52
|
- [x] tool.random_prompt
|
|
51
53
|
- [x] tool.paint_mask
|
|
52
54
|
- [x] tool.image_metadata
|
|
55
|
+
- [x] tokenizer
|
|
53
56
|
- [x] /ai/generate-image
|
|
54
57
|
- [x] /user/subscription
|
|
55
58
|
- [x] /user/login
|
|
@@ -119,7 +122,7 @@ from dotenv import load_dotenv
|
|
|
119
122
|
from pydantic import SecretStr
|
|
120
123
|
|
|
121
124
|
from novelai_python import APIError, LoginCredential
|
|
122
|
-
from novelai_python.sdk.ai.generate import TextLLMModel, LLM
|
|
125
|
+
from novelai_python.sdk.ai.generate import TextLLMModel, LLM, get_default_preset
|
|
123
126
|
|
|
124
127
|
load_dotenv()
|
|
125
128
|
username = os.getenv("NOVELAI_USER", None)
|
|
@@ -133,7 +136,13 @@ login_credential = LoginCredential(
|
|
|
133
136
|
|
|
134
137
|
async def chat(prompt: str):
|
|
135
138
|
try:
|
|
136
|
-
|
|
139
|
+
model = TextLLMModel.ERATO # llama3
|
|
140
|
+
parameters = get_default_preset(model).parameters
|
|
141
|
+
agent = LLM.build(
|
|
142
|
+
prompt=prompt,
|
|
143
|
+
model=model,
|
|
144
|
+
parameters=None # Auto Select or get from preset
|
|
145
|
+
)
|
|
137
146
|
result = await agent.request(session=login_credential)
|
|
138
147
|
except APIError as e:
|
|
139
148
|
raise Exception(f"Error: {e.message}")
|
|
@@ -160,6 +169,21 @@ pip install novelai_python
|
|
|
160
169
|
python3 -m novelai_python.server -h '127.0.0.1' -p 7888
|
|
161
170
|
```
|
|
162
171
|
|
|
172
|
+
#### Tokenizer
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from novelai_python._enum import get_tokenizer_model, TextLLMModel
|
|
176
|
+
from novelai_python.tokenizer import NaiTokenizer
|
|
177
|
+
|
|
178
|
+
tokenizer_package = NaiTokenizer(get_tokenizer_model(TextLLMModel.ERATO))
|
|
179
|
+
t_text = "a fox jumped over the lazy dog"
|
|
180
|
+
encode_tokens = tokenizer_package.encode(t_text)
|
|
181
|
+
print(tokenizer_package.tokenize_text(t_text))
|
|
182
|
+
print(f"Tokenized text: {encode_tokens}")
|
|
183
|
+
print(tokenizer_package.decode(tokenizer_package.encode(t_text)))
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
|
|
163
187
|
## Acknowledgements 🙏
|
|
164
188
|
|
|
165
189
|
[BackEnd](https://api.novelai.net/docs)
|
|
@@ -16,6 +16,7 @@ The goal of this repository is to use Pydantic to build legitimate requests to a
|
|
|
16
16
|
- [x] tool.random_prompt
|
|
17
17
|
- [x] tool.paint_mask
|
|
18
18
|
- [x] tool.image_metadata
|
|
19
|
+
- [x] tokenizer
|
|
19
20
|
- [x] /ai/generate-image
|
|
20
21
|
- [x] /user/subscription
|
|
21
22
|
- [x] /user/login
|
|
@@ -85,7 +86,7 @@ from dotenv import load_dotenv
|
|
|
85
86
|
from pydantic import SecretStr
|
|
86
87
|
|
|
87
88
|
from novelai_python import APIError, LoginCredential
|
|
88
|
-
from novelai_python.sdk.ai.generate import TextLLMModel, LLM
|
|
89
|
+
from novelai_python.sdk.ai.generate import TextLLMModel, LLM, get_default_preset
|
|
89
90
|
|
|
90
91
|
load_dotenv()
|
|
91
92
|
username = os.getenv("NOVELAI_USER", None)
|
|
@@ -99,7 +100,13 @@ login_credential = LoginCredential(
|
|
|
99
100
|
|
|
100
101
|
async def chat(prompt: str):
|
|
101
102
|
try:
|
|
102
|
-
|
|
103
|
+
model = TextLLMModel.ERATO # llama3
|
|
104
|
+
parameters = get_default_preset(model).parameters
|
|
105
|
+
agent = LLM.build(
|
|
106
|
+
prompt=prompt,
|
|
107
|
+
model=model,
|
|
108
|
+
parameters=None # Auto Select or get from preset
|
|
109
|
+
)
|
|
103
110
|
result = await agent.request(session=login_credential)
|
|
104
111
|
except APIError as e:
|
|
105
112
|
raise Exception(f"Error: {e.message}")
|
|
@@ -126,6 +133,21 @@ pip install novelai_python
|
|
|
126
133
|
python3 -m novelai_python.server -h '127.0.0.1' -p 7888
|
|
127
134
|
```
|
|
128
135
|
|
|
136
|
+
#### Tokenizer
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from novelai_python._enum import get_tokenizer_model, TextLLMModel
|
|
140
|
+
from novelai_python.tokenizer import NaiTokenizer
|
|
141
|
+
|
|
142
|
+
tokenizer_package = NaiTokenizer(get_tokenizer_model(TextLLMModel.ERATO))
|
|
143
|
+
t_text = "a fox jumped over the lazy dog"
|
|
144
|
+
encode_tokens = tokenizer_package.encode(t_text)
|
|
145
|
+
print(tokenizer_package.tokenize_text(t_text))
|
|
146
|
+
print(f"Tokenized text: {encode_tokens}")
|
|
147
|
+
print(tokenizer_package.decode(tokenizer_package.encode(t_text)))
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
129
151
|
## Acknowledgements 🙏
|
|
130
152
|
|
|
131
153
|
[BackEnd](https://api.novelai.net/docs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "novelai-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "NovelAI Python Binding With Pydantic"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "sudoskys", email = "coldlando@hotmail.com" },
|
|
@@ -26,6 +26,8 @@ dependencies = [
|
|
|
26
26
|
"ftfy>=6.2.0",
|
|
27
27
|
"regex>=2023.12.25",
|
|
28
28
|
"tokenizers>=0.15.2",
|
|
29
|
+
"json-repair>=0.29.4",
|
|
30
|
+
"robust-downloader>=0.0.2",
|
|
29
31
|
]
|
|
30
32
|
requires-python = ">=3.9"
|
|
31
33
|
readme = "README.md"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Optional, Union
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TextLLMModel(Enum):
|
|
6
|
+
NEO_2B = "2.7B"
|
|
7
|
+
J_6B = "6B"
|
|
8
|
+
J_6B_V3 = "6B-v3"
|
|
9
|
+
J_6B_V4 = "6B-v4"
|
|
10
|
+
GENJI_PYTHON_6B = "genji-python-6b"
|
|
11
|
+
GENJI_JP_6B = "genji-jp-6b"
|
|
12
|
+
GENJI_JP_6B_V2 = "genji-jp-6b-v2"
|
|
13
|
+
EUTERPE_V0 = "euterpe-v0"
|
|
14
|
+
EUTERPE_V2 = "euterpe-v2"
|
|
15
|
+
KRAKE_V1 = "krake-v1"
|
|
16
|
+
KRAKE_V2 = "krake-v2"
|
|
17
|
+
BLUE = "blue"
|
|
18
|
+
RED = "red"
|
|
19
|
+
GREEN = "green"
|
|
20
|
+
PURPLE = "purple"
|
|
21
|
+
PINK = "pink"
|
|
22
|
+
YELLOW = "yellow"
|
|
23
|
+
WHITE = "white"
|
|
24
|
+
BLACK = "black"
|
|
25
|
+
CASSANDRA = "cassandra"
|
|
26
|
+
COMMENT_BOT = "hypebot"
|
|
27
|
+
INFILL = "infillmodel"
|
|
28
|
+
CLIO = "clio-v1"
|
|
29
|
+
KAYRA = "kayra-v1"
|
|
30
|
+
ERATO = "llama-3-erato-v1"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TextTokenizerGroup(object):
|
|
34
|
+
GENJI = "genji_tokenizer.def"
|
|
35
|
+
PILE = "pile_tokenizer.def"
|
|
36
|
+
PILE_NAI = "pile_tokenizer.def"
|
|
37
|
+
NAI_INLINE = "gpt2_tokenizer.def"
|
|
38
|
+
NERDSTASH_V2 = "nerdstash_tokenizer_v2.def"
|
|
39
|
+
NERDSTASH = "nerdstash_tokenizer.def"
|
|
40
|
+
LLAMA3 = "llama3_tokenizer.def"
|
|
41
|
+
GPT2 = "gpt2_tokenizer.def"
|
|
42
|
+
CLIP = "clip_tokenizer.def"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
TextLLMModelTypeAlias = Union[TextLLMModel, str]
|
|
46
|
+
|
|
47
|
+
TOKENIZER_MODEL_MAP = {
|
|
48
|
+
TextLLMModel.GENJI_JP_6B_V2: TextTokenizerGroup.GENJI,
|
|
49
|
+
TextLLMModel.CASSANDRA: TextTokenizerGroup.PILE,
|
|
50
|
+
TextLLMModel.KRAKE_V2: TextTokenizerGroup.PILE,
|
|
51
|
+
TextLLMModel.INFILL: TextTokenizerGroup.NAI_INLINE,
|
|
52
|
+
TextLLMModel.KAYRA: TextTokenizerGroup.NERDSTASH_V2,
|
|
53
|
+
TextLLMModel.BLUE: TextTokenizerGroup.NERDSTASH_V2,
|
|
54
|
+
TextLLMModel.PINK: TextTokenizerGroup.NERDSTASH_V2,
|
|
55
|
+
TextLLMModel.YELLOW: TextTokenizerGroup.NERDSTASH_V2,
|
|
56
|
+
TextLLMModel.RED: TextTokenizerGroup.NERDSTASH_V2,
|
|
57
|
+
TextLLMModel.GREEN: TextTokenizerGroup.NERDSTASH_V2,
|
|
58
|
+
TextLLMModel.BLACK: TextTokenizerGroup.NERDSTASH_V2,
|
|
59
|
+
TextLLMModel.CLIO: TextTokenizerGroup.NERDSTASH,
|
|
60
|
+
TextLLMModel.PURPLE: TextTokenizerGroup.LLAMA3,
|
|
61
|
+
TextLLMModel.WHITE: TextTokenizerGroup.LLAMA3,
|
|
62
|
+
TextLLMModel.ERATO: TextTokenizerGroup.LLAMA3,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
COLORS_LLM = [
|
|
66
|
+
TextLLMModel.BLUE,
|
|
67
|
+
TextLLMModel.RED,
|
|
68
|
+
TextLLMModel.GREEN,
|
|
69
|
+
TextLLMModel.PURPLE,
|
|
70
|
+
TextLLMModel.PINK,
|
|
71
|
+
TextLLMModel.YELLOW,
|
|
72
|
+
TextLLMModel.WHITE,
|
|
73
|
+
TextLLMModel.BLACK,
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_llm_group(model: TextLLMModel) -> Optional[TextTokenizerGroup]:
|
|
78
|
+
if isinstance(model, str):
|
|
79
|
+
model = TextLLMModel(model)
|
|
80
|
+
return TOKENIZER_MODEL_MAP.get(model, None)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def get_tokenizer_model(model: TextLLMModel) -> str:
|
|
84
|
+
if isinstance(model, str):
|
|
85
|
+
model = TextLLMModel(model)
|
|
86
|
+
group = TOKENIZER_MODEL_MAP.get(model, TextTokenizerGroup.GPT2)
|
|
87
|
+
return group
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get_tokenizer_model_url(model: TextLLMModel) -> str:
|
|
91
|
+
model_name = get_tokenizer_model(model)
|
|
92
|
+
if not model_name.endswith(".def"):
|
|
93
|
+
model_name = f"{model_name}.def"
|
|
94
|
+
return f"https://novelai.net/tokenizer/compressed/{model_name}?v=2&static=true"
|
|
@@ -2,8 +2,8 @@ from typing import TYPE_CHECKING
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict
|
|
4
4
|
|
|
5
|
-
from novelai_python.
|
|
6
|
-
from novelai_python.tokenizer import
|
|
5
|
+
from novelai_python._enum import get_tokenizer_model, TextLLMModel
|
|
6
|
+
from novelai_python.tokenizer import NaiTokenizer
|
|
7
7
|
from novelai_python.utils.encode import b64_to_tokens
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
@@ -20,4 +20,7 @@ class LLMResp(BaseModel):
|
|
|
20
20
|
|
|
21
21
|
@staticmethod
|
|
22
22
|
def decode_token(token_str, model: TextLLMModel) -> str:
|
|
23
|
-
|
|
23
|
+
dtype = 'uint32' if model in [TextLLMModel.ERATO] else 'uint16'
|
|
24
|
+
return NaiTokenizer(model=get_tokenizer_model(model)).decode(
|
|
25
|
+
b64_to_tokens(token_str, dtype=dtype)
|
|
26
|
+
)
|
{novelai_python-0.4.15 → novelai_python-0.5.0}/src/novelai_python/_response/ai/generate_stream.py
RENAMED
|
@@ -2,8 +2,8 @@ from typing import Optional, Any
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict
|
|
4
4
|
|
|
5
|
-
from novelai_python.
|
|
6
|
-
from novelai_python.tokenizer import
|
|
5
|
+
from novelai_python._enum import get_tokenizer_model, TextLLMModel
|
|
6
|
+
from novelai_python.tokenizer import NaiTokenizer
|
|
7
7
|
from novelai_python.utils.encode import b64_to_tokens
|
|
8
8
|
|
|
9
9
|
|
|
@@ -20,4 +20,7 @@ class LLMStreamResp(BaseModel):
|
|
|
20
20
|
|
|
21
21
|
@staticmethod
|
|
22
22
|
def decode(token_str, model: TextLLMModel) -> str:
|
|
23
|
-
|
|
23
|
+
dtype = 'uint32' if model in [TextLLMModel.ERATO] else 'uint16'
|
|
24
|
+
return NaiTokenizer(model=get_tokenizer_model(model)).decode(
|
|
25
|
+
b64_to_tokens(token_str, dtype=dtype)
|
|
26
|
+
)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import math
|
|
2
2
|
import random
|
|
3
|
-
from typing import List, Optional
|
|
3
|
+
from typing import List, Optional, Union
|
|
4
4
|
|
|
5
5
|
from pydantic import BaseModel
|
|
6
6
|
|
|
7
7
|
from novelai_python.sdk.ai._const import map, initialN, initial_n, step, newN
|
|
8
|
-
from novelai_python.sdk.ai._enum import Sampler, Model, ModelGroups, get_model_group
|
|
8
|
+
from novelai_python.sdk.ai._enum import Sampler, Model, ModelGroups, get_model_group, ModelTypeAlias
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class Args(BaseModel):
|
|
@@ -43,9 +43,10 @@ class CostCalculator:
|
|
|
43
43
|
is_sm_dynamic: bool,
|
|
44
44
|
is_account_active: bool,
|
|
45
45
|
sampler: Optional[Sampler],
|
|
46
|
-
model:
|
|
46
|
+
model: ModelTypeAlias,
|
|
47
47
|
tool: str = None,
|
|
48
|
-
is_tool_active: bool = False
|
|
48
|
+
is_tool_active: bool = False
|
|
49
|
+
) -> int:
|
|
49
50
|
return CostCalculator.calculate_cost(
|
|
50
51
|
Args(
|
|
51
52
|
height=height,
|
|
@@ -59,7 +60,7 @@ class CostCalculator:
|
|
|
59
60
|
sampler=sampler,
|
|
60
61
|
tool=tool
|
|
61
62
|
),
|
|
62
|
-
model_group=get_model_group(model
|
|
63
|
+
model_group=get_model_group(model) if model else None,
|
|
63
64
|
is_account_active=is_account_active,
|
|
64
65
|
account_tier=account_tier,
|
|
65
66
|
is_tool_active=is_tool_active
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# @File : _enum.py
|
|
5
5
|
# @Software: PyCharm
|
|
6
6
|
from enum import Enum, IntEnum
|
|
7
|
-
from typing import List
|
|
7
|
+
from typing import List, Optional, Union
|
|
8
8
|
|
|
9
9
|
from pydantic.dataclasses import dataclass
|
|
10
10
|
|
|
@@ -36,56 +36,6 @@ class NoiseSchedule(Enum):
|
|
|
36
36
|
POLYEXPONENTIAL = "polyexponential"
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def get_supported_noise_schedule(sample_type: Sampler) -> List[NoiseSchedule]:
|
|
40
|
-
"""
|
|
41
|
-
Get supported noise schedule for a given sample type
|
|
42
|
-
:param sample_type: Sampler
|
|
43
|
-
:return: List[NoiseSchedule]
|
|
44
|
-
"""
|
|
45
|
-
if sample_type in [
|
|
46
|
-
Sampler.K_EULER_ANCESTRAL,
|
|
47
|
-
Sampler.K_DPMPP_2S_ANCESTRAL,
|
|
48
|
-
Sampler.K_DPMPP_2M,
|
|
49
|
-
Sampler.K_DPMPP_2M_SDE,
|
|
50
|
-
Sampler.K_DPMPP_SDE,
|
|
51
|
-
Sampler.K_EULER
|
|
52
|
-
]:
|
|
53
|
-
return [
|
|
54
|
-
NoiseSchedule.NATIVE,
|
|
55
|
-
NoiseSchedule.KARRAS,
|
|
56
|
-
NoiseSchedule.EXPONENTIAL,
|
|
57
|
-
NoiseSchedule.POLYEXPONENTIAL
|
|
58
|
-
]
|
|
59
|
-
elif sample_type in [Sampler.K_DPM_2]:
|
|
60
|
-
return [
|
|
61
|
-
NoiseSchedule.EXPONENTIAL,
|
|
62
|
-
NoiseSchedule.POLYEXPONENTIAL
|
|
63
|
-
]
|
|
64
|
-
else:
|
|
65
|
-
return []
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def get_default_noise_schedule(sample_type: Sampler) -> NoiseSchedule:
|
|
69
|
-
"""
|
|
70
|
-
Get default noise schedule for a given sample type
|
|
71
|
-
:param sample_type: Sampler
|
|
72
|
-
:return: NoiseSchedule
|
|
73
|
-
"""
|
|
74
|
-
if sample_type in [
|
|
75
|
-
Sampler.K_EULER_ANCESTRAL,
|
|
76
|
-
Sampler.K_DPMPP_2S_ANCESTRAL,
|
|
77
|
-
Sampler.K_DPMPP_2M,
|
|
78
|
-
Sampler.K_DPMPP_2M_SDE,
|
|
79
|
-
Sampler.K_DPMPP_SDE,
|
|
80
|
-
Sampler.K_EULER
|
|
81
|
-
]:
|
|
82
|
-
return NoiseSchedule.KARRAS
|
|
83
|
-
elif sample_type in [Sampler.K_DPM_2]:
|
|
84
|
-
return NoiseSchedule.EXPONENTIAL
|
|
85
|
-
else:
|
|
86
|
-
return NoiseSchedule.NATIVE
|
|
87
|
-
|
|
88
|
-
|
|
89
39
|
class UCPreset(IntEnum):
|
|
90
40
|
TYPE0 = 0
|
|
91
41
|
TYPE1 = 1
|
|
@@ -171,30 +121,6 @@ class ModelGroups(Enum):
|
|
|
171
121
|
STABLE_DIFFUSION_XL_FURRY = "stable_diffusion_xl_furry"
|
|
172
122
|
|
|
173
123
|
|
|
174
|
-
def get_model_group(model: str) -> ModelGroups:
|
|
175
|
-
if isinstance(model, Enum):
|
|
176
|
-
model = model.value
|
|
177
|
-
mapping = {
|
|
178
|
-
"stable-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
179
|
-
"nai-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
180
|
-
"safe-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
181
|
-
"waifu-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
182
|
-
"nai-diffusion-furry": ModelGroups.STABLE_DIFFUSION,
|
|
183
|
-
"curated-diffusion-test": ModelGroups.STABLE_DIFFUSION,
|
|
184
|
-
"nai-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
185
|
-
"safe-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
186
|
-
"furry-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
187
|
-
"nai-diffusion-2": ModelGroups.STABLE_DIFFUSION_GROUP_2,
|
|
188
|
-
"nai-diffusion-xl": ModelGroups.STABLE_DIFFUSION_XL,
|
|
189
|
-
"nai-diffusion-3": ModelGroups.STABLE_DIFFUSION_XL,
|
|
190
|
-
"nai-diffusion-3-inpainting": ModelGroups.STABLE_DIFFUSION_XL,
|
|
191
|
-
"custom": ModelGroups.STABLE_DIFFUSION_XL,
|
|
192
|
-
"nai-diffusion-furry-3": ModelGroups.STABLE_DIFFUSION_XL_FURRY,
|
|
193
|
-
"nai-diffusion-furry-3-inpainting": ModelGroups.STABLE_DIFFUSION_XL_FURRY,
|
|
194
|
-
}
|
|
195
|
-
return mapping.get(model, ModelGroups.STABLE_DIFFUSION)
|
|
196
|
-
|
|
197
|
-
|
|
198
124
|
INPAINTING_MODEL_LIST = [
|
|
199
125
|
Model.NAI_DIFFUSION_3_INPAINTING,
|
|
200
126
|
Model.NAI_DIFFUSION_INPAINTING,
|
|
@@ -224,8 +150,88 @@ PROMOTION = {
|
|
|
224
150
|
"Stable Diffusion XL 9CC2F394": Model.NAI_DIFFUSION_FURRY_3,
|
|
225
151
|
}
|
|
226
152
|
|
|
153
|
+
ModelTypeAlias = Optional[Union[Model, str]]
|
|
154
|
+
ImageBytesTypeAlias = Optional[Union[str, bytes]]
|
|
155
|
+
UCPresetTypeAlias = Optional[Union[UCPreset, int]]
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def get_supported_noise_schedule(sample_type: Sampler) -> List[NoiseSchedule]:
|
|
159
|
+
"""
|
|
160
|
+
Get supported noise schedule for a given sample type
|
|
161
|
+
:param sample_type: Sampler
|
|
162
|
+
:return: List[NoiseSchedule]
|
|
163
|
+
"""
|
|
164
|
+
if sample_type in [
|
|
165
|
+
Sampler.K_EULER_ANCESTRAL,
|
|
166
|
+
Sampler.K_DPMPP_2S_ANCESTRAL,
|
|
167
|
+
Sampler.K_DPMPP_2M,
|
|
168
|
+
Sampler.K_DPMPP_2M_SDE,
|
|
169
|
+
Sampler.K_DPMPP_SDE,
|
|
170
|
+
Sampler.K_EULER
|
|
171
|
+
]:
|
|
172
|
+
return [
|
|
173
|
+
NoiseSchedule.NATIVE,
|
|
174
|
+
NoiseSchedule.KARRAS,
|
|
175
|
+
NoiseSchedule.EXPONENTIAL,
|
|
176
|
+
NoiseSchedule.POLYEXPONENTIAL
|
|
177
|
+
]
|
|
178
|
+
elif sample_type in [Sampler.K_DPM_2]:
|
|
179
|
+
return [
|
|
180
|
+
NoiseSchedule.EXPONENTIAL,
|
|
181
|
+
NoiseSchedule.POLYEXPONENTIAL
|
|
182
|
+
]
|
|
183
|
+
else:
|
|
184
|
+
return []
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def get_default_noise_schedule(sample_type: Sampler) -> NoiseSchedule:
|
|
188
|
+
"""
|
|
189
|
+
Get default noise schedule for a given sample type
|
|
190
|
+
:param sample_type: Sampler
|
|
191
|
+
:return: NoiseSchedule
|
|
192
|
+
"""
|
|
193
|
+
if sample_type in [
|
|
194
|
+
Sampler.K_EULER_ANCESTRAL,
|
|
195
|
+
Sampler.K_DPMPP_2S_ANCESTRAL,
|
|
196
|
+
Sampler.K_DPMPP_2M,
|
|
197
|
+
Sampler.K_DPMPP_2M_SDE,
|
|
198
|
+
Sampler.K_DPMPP_SDE,
|
|
199
|
+
Sampler.K_EULER
|
|
200
|
+
]:
|
|
201
|
+
return NoiseSchedule.KARRAS
|
|
202
|
+
elif sample_type in [Sampler.K_DPM_2]:
|
|
203
|
+
return NoiseSchedule.EXPONENTIAL
|
|
204
|
+
else:
|
|
205
|
+
return NoiseSchedule.NATIVE
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def get_model_group(model: ModelTypeAlias) -> ModelGroups:
|
|
209
|
+
if isinstance(model, Enum):
|
|
210
|
+
model = model.value
|
|
211
|
+
else:
|
|
212
|
+
model = str(model)
|
|
213
|
+
mapping = {
|
|
214
|
+
"stable-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
215
|
+
"nai-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
216
|
+
"safe-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
217
|
+
"waifu-diffusion": ModelGroups.STABLE_DIFFUSION,
|
|
218
|
+
"nai-diffusion-furry": ModelGroups.STABLE_DIFFUSION,
|
|
219
|
+
"curated-diffusion-test": ModelGroups.STABLE_DIFFUSION,
|
|
220
|
+
"nai-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
221
|
+
"safe-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
222
|
+
"furry-diffusion-inpainting": ModelGroups.STABLE_DIFFUSION,
|
|
223
|
+
"nai-diffusion-2": ModelGroups.STABLE_DIFFUSION_GROUP_2,
|
|
224
|
+
"nai-diffusion-xl": ModelGroups.STABLE_DIFFUSION_XL,
|
|
225
|
+
"nai-diffusion-3": ModelGroups.STABLE_DIFFUSION_XL,
|
|
226
|
+
"nai-diffusion-3-inpainting": ModelGroups.STABLE_DIFFUSION_XL,
|
|
227
|
+
"custom": ModelGroups.STABLE_DIFFUSION_XL,
|
|
228
|
+
"nai-diffusion-furry-3": ModelGroups.STABLE_DIFFUSION_XL_FURRY,
|
|
229
|
+
"nai-diffusion-furry-3-inpainting": ModelGroups.STABLE_DIFFUSION_XL_FURRY,
|
|
230
|
+
}
|
|
231
|
+
return mapping.get(model, ModelGroups.STABLE_DIFFUSION)
|
|
232
|
+
|
|
227
233
|
|
|
228
|
-
def get_default_uc_preset(model:
|
|
234
|
+
def get_default_uc_preset(model: ModelTypeAlias, uc_preset: int) -> str:
|
|
229
235
|
if isinstance(model, Enum):
|
|
230
236
|
model = model.value
|
|
231
237
|
if isinstance(uc_preset, Enum):
|