diff --git a/.buildinfo b/.buildinfo index 7a4d00a..96bb4e2 100644 --- a/.buildinfo +++ b/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: ce1b3f02132269e3117ff63e34dbbd14 +config: 6a687f250e5c1911bea924197742129c tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/_modules/example/boilerplate.html b/_modules/example/boilerplate.html index 7ae8ee1..0805593 100644 --- a/_modules/example/boilerplate.html +++ b/_modules/example/boilerplate.html @@ -5,7 +5,7 @@
-
import json
from logging import Logger, StreamHandler
from os import environ as env
+from pathlib import Path
from typing import Any, Optional
-import dotenv
from aiohttp import ClientSession
from novelai_api import NovelAIAPI
@@ -96,7 +96,13 @@ Source code for example.boilerplate
api: Optional[NovelAIAPI]
[docs] def __init__(self, base_address: Optional[str] = None):
- dotenv.load_dotenv()
+ dotenv = Path(".env")
+ if dotenv.exists():
+ with dotenv.open("r") as f:
+ for line in f:
+ if "=" in line:
+ key, value = line.strip().split("=", 1)
+ env[key] = value.strip()
if "NAI_USERNAME" not in env or "NAI_PASSWORD" not in env:
raise RuntimeError("Please ensure that NAI_USERNAME and NAI_PASSWORD are set in your environment")
@@ -177,13 +183,13 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
example.boilerplate
diff --git a/_modules/index.html b/_modules/index.html
index 91dcefd..f331c0c 100644
--- a/_modules/index.html
+++ b/_modules/index.html
@@ -5,7 +5,7 @@
- Overview: module code — NovelAI API 0.22.0 documentation
+ Overview: module code — NovelAI API 0.23.1 documentation
@@ -43,7 +43,7 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Overview: module code
@@ -104,12 +104,12 @@ Navigation
name: str
#: Model the preset is for
model: Model
+ #: Enable state of sampling options
+ sampling_options: List[bool]
[docs] def __init__(self, name: str, model: Model, settings: Optional[Dict[str, Any]] = None):
object.__setattr__(self, "name", name)
object.__setattr__(self, "model", model)
object.__setattr__(self, "_settings", {})
- self.update(settings)
+ self.update(settings)
+ self.set_sampling_options_state([True] * len(self._settings["order"]))
def __repr__(self) -> str:
model = self.model.value if self.model is not None else "<?>"
- enabled_keys = ", ".join(f"{ORDER_TO_NAME[o]} = {o in self._settings['order']}" for o in Order)
+ enabled_order = [o for o, enabled in zip(self._settings["order"], self.sampling_options) if enabled]
+ enabled_keys = ", ".join(f"{ORDER_TO_NAME[o]} = {o in enabled_order}" for o in Order)
return f"Preset: '{self.name} ({model}, {enabled_keys})'"
@@ -437,7 +458,11 @@ Source code for novelai_api.Preset
# remove disabled sampling options
if "order" in settings:
- order = [Order(e) if isinstance(e, int) else e for e in settings["order"]]
+ order = [
+ (Order(o) if isinstance(o, int) else o)
+ for o, enabled in zip(settings["order"], self.sampling_options)
+ if enabled
+ ]
for o in Order:
if o not in order:
@@ -473,8 +498,8 @@ Source code for novelai_api.Preset
return settings
def __str__(self):
- settings = {k: self._settings.get(k, v) for k, v in self.DEFAULTS.items()}
- is_default = {k: " (default)" if v == self.DEFAULTS[k] else "" for k, v in settings.items()}
+ settings = self.to_settings() # use the sanitized settings
+ is_default = {k: " (default)" if v == self.DEFAULTS.get(k, None) else "" for k, v in settings.items()}
values = "\n".join(f" {k} = {v}{is_default[k]}" for k, v in settings.items())
@@ -532,7 +557,6 @@ Source code for novelai_api.Preset
name = data["name"] if "name" in data else "<?>"
- # FIXME: collapse model version
model_name = data["model"] if "model" in data else ""
model = collapse_model(Model, model_name)
@@ -547,6 +571,7 @@ Source code for novelai_api.Preset
settings.pop("logit_bias_groups", None) # get rid of unsupported option
c = cls(name, model, settings)
+ c.set_sampling_options_state([o["enabled"] for o in order])
return c
@@ -677,13 +702,13 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
novelai_api.Preset
diff --git a/_modules/novelai_api/SchemaValidator.html b/_modules/novelai_api/SchemaValidator.html
index e004f9e..1dfdd3b 100644
--- a/_modules/novelai_api/SchemaValidator.html
+++ b/_modules/novelai_api/SchemaValidator.html
@@ -5,7 +5,7 @@
- novelai_api.SchemaValidator — NovelAI API 0.22.0 documentation
+ novelai_api.SchemaValidator — NovelAI API 0.23.1 documentation
@@ -43,7 +43,7 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
novelai_api.SchemaValidator
@@ -121,13 +121,13 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
novelai_api.SchemaValidator
diff --git a/_modules/novelai_api/StoryHandler.html b/_modules/novelai_api/StoryHandler.html
index 42d65a3..f70e56c 100644
--- a/_modules/novelai_api/StoryHandler.html
+++ b/_modules/novelai_api/StoryHandler.html
@@ -5,7 +5,7 @@
- novelai_api.StoryHandler — NovelAI API 0.22.0 documentation
+ novelai_api.StoryHandler — NovelAI API 0.23.1 documentation
@@ -43,7 +43,7 @@ Navigation
from novelai_api.Tokenizer import Tokenizer
from novelai_api.utils import tokens_to_b64
-PRINT_WITH_PARAMETERS = os.environ.get("NAI_PRINT", None)
+PRINT_WITH_PARAMETERS = os.environ.get("NAI_PRINT", False)
# === INTERNALS === #
@@ -1002,13 +1002,13 @@ Navigation
import json
from logging import Logger, StreamHandler
from os import environ as env
+from pathlib import Path
from typing import Any, Awaitable, Callable, NoReturn, Optional
import pytest
@@ -79,6 +80,14 @@ Source code for tests.api.boilerplate
api: NovelAIAPI
[docs] def __init__(self, sync: bool = False):
+ dotenv = Path(".env")
+ if dotenv.exists():
+ with dotenv.open("r") as f:
+ for line in f:
+ if "=" in line:
+ key, value = line.strip().split("=", 1)
+ env[key] = value.strip()
+
if "NAI_USERNAME" not in env or "NAI_PASSWORD" not in env:
raise RuntimeError("Please ensure that NAI_USERNAME and NAI_PASSWORD are set in your environment")
@@ -251,13 +260,13 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
tests.api.boilerplate
diff --git a/_modules/tests/api/test_decrypt_encrypt_integrity_check.html b/_modules/tests/api/test_decrypt_encrypt_integrity_check.html
index e3f4320..7eb3b5a 100644
--- a/_modules/tests/api/test_decrypt_encrypt_integrity_check.html
+++ b/_modules/tests/api/test_decrypt_encrypt_integrity_check.html
@@ -5,7 +5,7 @@
- tests.api.test_decrypt_encrypt_integrity_check — NovelAI API 0.22.0 documentation
+ tests.api.test_decrypt_encrypt_integrity_check — NovelAI API 0.23.1 documentation
@@ -43,7 +43,7 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
tests.api.test_decrypt_encrypt_integrity_check
@@ -307,13 +307,13 @@ Navigation
modules |
- NovelAI API 0.22.0 documentation »
+ NovelAI API 0.23.1 documentation »
Module code »
tests.api.test_decrypt_encrypt_integrity_check
diff --git a/_modules/tests/api/test_textgen_presets.html b/_modules/tests/api/test_textgen_presets.html
index 0e02442..6aaf897 100644
--- a/_modules/tests/api/test_textgen_presets.html
+++ b/_modules/tests/api/test_textgen_presets.html
@@ -5,7 +5,7 @@
- tests.api.test_textgen_presets — NovelAI API 0.22.0 documentation
+ tests.api.test_textgen_presets — NovelAI API 0.23.1 documentation
@@ -43,7 +43,7 @@ Navigation
Tests pertaining to the Preset class """ +import asyncio from typing import Tuple import pytest @@ -67,7 +68,7 @@
from novelai_api.Preset import Model, Preset from novelai_api.Tokenizer import Tokenizer from novelai_api.utils import b64_to_tokens -from tests.api.boilerplate import api_handle, error_handler # noqa: F401 # pylint: disable=W0611 +from tests.api.boilerplate import API, api_handle, error_handler # noqa: F401 # pylint: disable=W0611 prompt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at dolor dictum, interdum est sed, consequat arcu. Pellentesque in massa eget lorem fermentum placerat in pellentesque purus. Suspendisse potenti. Integer interdum, felis quis porttitor volutpat, est mi rutrum massa, venenatis viverra neque lectus semper metus. Pellentesque in neque arcu. Ut at arcu blandit purus aliquet finibus. Suspendisse laoreet risus a gravida semper. Aenean scelerisque et sem vitae feugiat. Quisque et interdum diam, eu vehicula felis. Ut tempus quam eros, et sollicitudin ligula auctor at. Integer at tempus dui, quis pharetra purus. Duis venenatis tincidunt tellus nec efficitur. Nam at malesuada ligula." # noqa: E501 # pylint: disable=C0301 models = list(Model) @@ -113,6 +114,24 @@
""" Preset.from_official(model)
diff --git a/example/example.html b/example/example.html index 1cbb962..aed68c4 100644 --- a/example/example.html +++ b/example/example.html @@ -6,7 +6,7 @@ -
+
@@ -52,7 +52,7 @@
-
+
@@ -284,12 +284,12 @@
-
+
diff --git a/genindex.html b/genindex.html index cde8276..77bff0c 100644 --- a/genindex.html +++ b/genindex.html @@ -5,7 +5,7 @@
-
+
@@ -43,7 +43,7 @@
-
+
@@ -1191,6 +1191,8 @@
+
Retired versions: 3.7.2
+Final commit of retired versions can be found with the tag py<version>
(e.g. py3.7.2
).
Model the preset is for
Enable state of sampling options
+Set the state (enabled/disabled) of the sampling options. Set it after setting the order setting. +It should come in the same order as the order setting.
+Preset.get_hidden_states
Preset.name
Preset.model
Preset.sampling_options
Preset.__init__()
Preset.set_sampling_options_state()
Preset.to_settings()
Preset.to_file()
Preset.copy()