novelai_api.high_level¶
- class HighLevel[source]¶
Bases:
object
High level API for NovelAI. This class is not meant to be used directly, but rather through
NovelAIAPI.high_level
.The most relevant methods are:
- __init__(parent: NovelAIAPI)[source]¶
- async register(recapcha: str, email: str, password: str, send_mail: bool = True, giftkey: str | None = None) bool [source]¶
Register a new account
- Parameters:
recapcha – Recapcha of the NovelAI website
email – Email of the account (username)
password – Password of the account
send_mail – Send the mail (hashed and used for recovery)
giftkey – Giftkey
- Returns:
True if success
- async login(email: str, password: str) str [source]¶
Log in to the account
- Parameters:
email – Email of the account (username)
password – Password of the account
- Returns:
User’s access token
- async login_with_token(access_token: str)[source]¶
Log in with the access token, instead of email and password
- Parameters:
access_token – Access token of the account (persistent token or gotten from login)
- async login_from_key(access_key: str)[source]¶
Log in with the access key, instead of email and password
- Parameters:
access_key – Access key of the account (pre-computed via email and password)
- Returns:
User’s access token
- async get_keystore(key: bytes) novelai_api.Keystore.Keystore [source]¶
Retrieve the keystore and decrypt it in a readable manner.
The keystore is the mapping of meta -> encryption key of each object. If this function throws errors repeatedly at you, check your internet connection or the integrity of your keystore. Losing your keystore, or overwriting it means losing all content on the account.
- Parameters:
key – Account’s encryption key
- Returns:
Keystore object
- async set_keystore(keystore: novelai_api.Keystore.Keystore, key: bytes) bytes [source]¶
Encrypt and upload the keystore.
The keystore is the mapping of meta -> encryption key of each object. If this function throws errors repeatedly at you, check your internet connection or the integrity of your keystore. Losing your keystore, or overwriting it means losing all content on the account.
- Parameters:
keystore – Keystore object to upload
key – Account’s encryption key
- Returns:
raw data of the serialized Keystore object
- async download_user_stories() List[Dict[str, Dict[str, str | int]]] [source]¶
Download all the objects of type ‘stories’ stored on the account
- async download_user_story_contents() List[Dict[str, Dict[str, str | int]]] [source]¶
Download all the objects of type ‘storycontent’ stored on the account
- async download_user_presets() List[Dict[str, str | int]] [source]¶
Download all the objects of type ‘presets’ stored on the account
- async download_user_modules() List[Dict[str, str | int]] [source]¶
Download all the objects of type ‘aimodules’ stored on the account
- async download_user_shelves() List[Dict[str, str | int]] [source]¶
Download all the objects of type ‘shelf’ stored on the account
- async upload_user_content(data: Dict[str, Any], encrypt: bool = False, keystore: novelai_api.Keystore.Keystore | None = None) bool [source]¶
Upload user content
- Parameters:
data – Object to upload
encrypt – Re-encrypt/re-compress the data, if True
keystore – Keystore to encrypt the data, if encrypt is True
- Returns:
True if the upload succeeded, False otherwise
- async upload_user_contents(datas: Iterable[Dict[str, Any]], encrypt: bool = False, keystore: novelai_api.Keystore.Keystore | None = None) List[Tuple[str, novelai_api.NovelAIError.NovelAIError | None]] [source]¶
Upload multiple user contents. If the content has been decrypted with decrypt_user_data, it should be re-encrypted with encrypt_user_data, even if the decryption failed
- Parameters:
datas – Objects to upload
encrypt – Re-encrypt/re-compress the data, if True
keystore – Keystore to encrypt the data, if encrypt is True
- Returns:
A list of (id, error) of all the objects that failed to be uploaded
- async generate(prompt: List[int] | str, model: novelai_api.Preset.Model, preset: novelai_api.Preset.Preset, global_settings: novelai_api.GlobalSettings.GlobalSettings, bad_words: Iterable[novelai_api.BanList.BanList] | novelai_api.BanList.BanList | None = None, biases: Iterable[novelai_api.BiasGroup.BiasGroup] | novelai_api.BiasGroup.BiasGroup | None = None, prefix: str | None = None, stop_sequences: List[int] | str | None = None, **kwargs) Dict[str, Any] [source]¶
Generate text. The b64-encoded text is returned at once, when generation is finished. To decode the text, the
novelai_api.utils.b64_to_tokens()
andnovelai_api.Tokenizer.Tokenizer.decode()
methods should be used.As the model accepts a complete prompt, the context building must be done before calling this function. Any content going beyond the tokens limit will be truncated, starting from the top.
- Parameters:
prompt – Context to give to the AI (raw text or list of tokens)
model – Model to use for the AI
preset – Preset to use for the generation settings
global_settings – Global settings (used for generation)
bad_words – Tokens to ban for this generation
biases – Tokens to bias (up or down) for this generation
prefix – Module to use for this generation (see list of modules)
stop_sequences – List of strings or tokens to stop the generation at
kwargs – Additional parameters to pass to the requests. Can also be used to overwrite existing parameters
- Returns:
Content that has been generated
- async generate_stream(prompt: List[int] | str, model: novelai_api.Preset.Model, preset: novelai_api.Preset.Preset, global_settings: novelai_api.GlobalSettings.GlobalSettings, bad_words: Iterable[novelai_api.BanList.BanList] | novelai_api.BanList.BanList | None = None, biases: Iterable[novelai_api.BiasGroup.BiasGroup] | novelai_api.BiasGroup.BiasGroup | None = None, prefix: str | None = None, stop_sequences: List[int] | str | None = None, **kwargs) AsyncIterable[Dict[str, Any]] [source]¶
Generate text. The text is returned one token at a time, as it is generated.
As the model accepts a complete prompt, the context building must be done before calling this function. Any content going beyond the tokens limit will be truncated, starting from the top.
- Parameters:
prompt – Context to give to the AI (raw text or list of tokens)
model – Model to use for the AI
preset – Preset to use for the generation settings
global_settings – Global settings (used for generation)
bad_words – Tokens to ban for this generation
biases – Tokens to bias (up or down) for this generation
prefix – Module to use for this generation (see list of modules)
stop_sequences – List of strings or tokens to stop the generation at
kwargs – Additional parameters to pass to the requests. Can also be used to overwrite existing parameters
- Returns:
Content that has been generated
- async generate_image(prompt: str, model: novelai_api.ImagePreset.ImageModel, preset: novelai_api.ImagePreset.ImagePreset, action: novelai_api.ImagePreset.ImageGenerationType = ImageGenerationType.NORMAL, **kwargs) AsyncIterable[str | bytes] [source]¶
Generate one or multiple image(s)
- Parameters:
prompt – Prompt to give to the AI (raw text describing the wanted image)
model – Model to use for the AI
preset – Preset to use for the generation settings
action – Type of image generation to use
kwargs – Additional parameters to pass to the requests. Can also be used to overwrite existing parameters
- Returns:
Pair(s) (name, image) that have been generated
- async remove_background(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Remove the background of an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64
- Returns:
Processed image
- async line_art(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Generate a line art of an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64
- Returns:
Processed image
- async sketch(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Generate a sketch of an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64
- Returns:
Processed image
- async colorize(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Colorize a sketch of an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64 * prompt: Prompt for the image * defry: Strength of the colorization
- Returns:
Processed image
- async emotion(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Generate an emotion of an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64 * prompt: Prompt for the image * emotion: Emotion for the image
- Returns:
Processed image
- async declutter(preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) bytes [source]¶
Declutter an image
- Parameters:
preset – Preset to use for the generation settings. It should contain: * height: Height of the image * width: Width of the image * image: Image encoded in base64
- Returns:
Processed image
List of modules¶
Calliope, Snek, and Genji have no module support. “special_openings” is a module specifically trained to replace the previously used preamble. It is used at the beginning of the story, under certain conditions.
Name |
API id |
Model |
---|---|---|
No module |
vanilla |
All |
Special: Text Adventure |
theme_textadventure |
All |
General: Prose Augmenter |
special_proseaugmenter |
Sigurd, Euterpe, Clio, Kayra |
General: Instruct (Experimental) |
special_instruct |
Clio, Kayra |
- |
special_openings |
Clio, Kayra |
General: Cross-Genre |
general_crossgenre |
Sigurd, Euterpe, Krake |
Style: Algernon Blackwood |
style_algernonblackwood |
Sigurd, Euterpe, Krake |
Style: Arthur Conan Doyle |
style_arthurconandoyle |
Sigurd, Euterpe, Krake |
Style: Edgar Allan Poe |
style_edgarallanpoe |
Sigurd, Euterpe, Krake |
Style: H.P. Lovecraft |
style_hplovecraft |
Sigurd, Euterpe, Krake |
Style: Sheridan Le Fanu |
style_shridanlefanu |
Sigurd, Euterpe, Krake |
Style: Jane Austen |
style_janeausten |
Sigurd, Euterpe |
Style: Jules Verne |
style_julesverne |
Sigurd, Euterpe, Krake |
Style: William Shakespeare |
style_williamshakespeare |
Sigurd, Euterpe |
Theme: 19th Century Romance |
theme_19thcenturyromance |
Sigurd, Euterpe, Krake |
Theme: Action Archeology |
theme_actionarcheology |
Sigurd, Euterpe, Krake |
Theme: Artificial Intelligence |
theme_ai |
Sigurd, Euterpe, Krake |
Theme: Ancient China |
theme_ancientchina |
Sigurd, Euterpe |
Theme: Ancient Greece |
theme_ancientgreek |
Sigurd, Euterpe |
Theme: Ancient India |
theme_india |
Sigurd, Euterpe |
Theme: Animal Fiction |
theme_animalfiction |
Sigurd, Euterpe, Krake |
Theme: Anthropomorphic Animals |
theme_anthropomorphicanimals |
Sigurd, Euterpe |
Theme: Children’s Fiction |
theme_childrens |
Sigurd, Euterpe, Krake |
Theme: Christmas |
theme_christmas |
Sigurd, Euterpe, Krake |
Theme: Comedic Fantasy |
theme_comedicfantasy |
Sigurd, Euterpe, Krake |
Theme: Contemporary |
theme_contemporary |
Sigurd, Euterpe |
Theme: Cyberpunk |
theme_cyberpunk |
Sigurd, Euterpe, Krake |
Theme: Dark Fantasy |
theme_darkfantasy |
Sigurd, Euterpe, Krake |
Theme: Dragons |
theme_dragons |
Sigurd, Euterpe, Krake |
Theme: Egypt |
theme_egypt |
Sigurd, Euterpe, Krake |
Theme: Feudal Japan |
theme_feudaljapan |
Sigurd, Euterpe, Krake |
Theme: Gaming |
theme_gaming |
Sigurd, Euterpe |
Theme: General Fantasy |
theme_generalfantasy |
Sigurd, Euterpe, Krake |
Theme: Golden Age Scifi |
theme_goldenagescifi |
Sigurd, Euterpe |
Theme: Hard SF |
theme_hardsf |
Sigurd, Euterpe |
Theme: History |
theme_history |
Sigurd, Euterpe, Krake |
Theme: Horror |
theme_horror |
Sigurd, Euterpe, Krake |
Theme: Hunter Gatherer |
theme_huntergatherer |
Sigurd, Euterpe, Krake |
Theme: LitRPG |
theme_litrpg |
Sigurd, Euterpe, Krake |
Theme: Magic Academy |
theme_magicacademy |
Sigurd, Euterpe, Krake |
Theme: Magic Library |
theme_libraries |
Sigurd, Euterpe, Krake |
Theme: Light Novels |
theme_lightnovels |
Sigurd, Euterpe |
Theme: Mars Colonization |
theme_mars |
Sigurd, Euterpe, Krake |
Theme: Medieval |
theme_medieval |
Sigurd, Euterpe, Krake |
Theme: Military SciFi |
theme_militaryscifi |
Sigurd, Euterpe, Krake |
Theme: Music |
theme_music |
Sigurd, Euterpe |
Theme: Mystery |
theme_mystery |
Sigurd, Euterpe, Krake |
Theme: Nature |
theme_nature |
Sigurd, Euterpe |
Theme: Naval Age of Discovery |
theme_naval |
Sigurd, Euterpe, Krake |
Theme: Noir |
theme_noir |
Sigurd, Euterpe |
Theme: Philosophy |
theme_philosophy |
Sigurd, Euterpe, Krake |
Theme: Pirates |
theme_pirates |
Sigurd, Euterpe, Krake |
Theme: Poetic Fantasy |
theme_poeticfantasy |
Sigurd, Euterpe, Krake |
Theme: Post-Apocalyptic |
theme_postapocalyptic |
Sigurd, Euterpe, Krake |
Theme: Rats |
theme_rats |
Sigurd, Euterpe, Krake |
Theme: Roman Empire |
theme_romanempire |
Sigurd, Euterpe, Krake |
Theme: Science Fantasy |
theme_sciencefantasy |
Sigurd, Euterpe, Krake |
Theme: Space Opera |
theme_spaceopera |
Sigurd, Euterpe, Krake |
Theme: Superheroes |
theme_superheroes |
Sigurd, Euterpe, Krake |
Theme: Steampunk |
theme_airships |
Sigurd, Euterpe, Krake |
Theme: Travel |
theme_travel |
Sigurd, Euterpe, Krake |
Theme: Urban Fantasy |
theme_urbanfantasy |
Sigurd, Euterpe, Krake |
Theme: Valentines |
theme_valentines |
Sigurd, Euterpe, Krake |
Theme: Vikings |
theme_vikings |
Sigurd, Euterpe, Krake |
Theme: Weird West |
theme_weirdwest |
Sigurd, Euterpe |
Theme: Western Romance |
theme_westernromance |
Sigurd, Euterpe, Krake |
Inspiration: Crab, Snail, and Monkey |
inspiration_crabsnailandmonkey |
Sigurd, Euterpe, Krake |
Inspiration: Mercantile Wolfgirl Romance |
inspiration_mercantilewolfgirlromance |
Sigurd, Euterpe, Krake |
Inspiration: Nervegear |
inspiration_nervegear |
Sigurd, Euterpe, Krake |
Inspiration: Romance of the Three Kingdoms |
theme_romanceofthreekingdoms |
Euterpe, Krake |
Inspiration: Throne Wars |
inspiration_thronewars |
Sigurd, Euterpe, Krake |
Inspiration: Witch at Level Cap |
inspiration_witchatlevelcap |
Sigurd, Euterpe, Krake |