Skip to content

Commit

Permalink
[EXAMPLE] Slightly adjust the text example and add .env by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Aedial committed May 21, 2023
1 parent 547b06e commit 2977a13
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Empty file added example/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions example/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os import environ as env
from typing import Any, Optional

import dotenv
from aiohttp import ClientSession

from novelai_api import NovelAIAPI
Expand All @@ -22,6 +23,8 @@ class API:
api: Optional[NovelAIAPI]

def __init__(self):
dotenv.load_dotenv()

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")

Expand Down
11 changes: 7 additions & 4 deletions example/generate_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from novelai_api.BanList import BanList
from novelai_api.BiasGroup import BiasGroup
from novelai_api.GlobalSettings import GlobalSettings
from novelai_api.Preset import Model, Preset
from novelai_api.Preset import PREAMBLE, Model, Preset
from novelai_api.Tokenizer import Tokenizer
from novelai_api.utils import b64_to_tokens

Expand All @@ -29,19 +29,22 @@ async def main():
# model = Model.Krake

# NOTE: plain text prompt
prompt = "***"
prompt = PREAMBLE[model]
# NOTE: prompt encoded in tokens
# prompt = Tokenizer.encode(model, "***")
# prompt = Tokenizer.encode(model, PREAMBLE[model])

# NOTE: empty preset
preset = Preset("preset", model, {})
# NOTE: instantiation from default (presets/presets_6B_v4/default.txt)
preset = Preset.from_default(model)
# preset = Preset.from_default(model)
# NOTE: instantiation from official file (presets/presets_6B_v4)
# preset = Preset.from_official(model, "Storywriter")
# NOTE: instantiation from file
# preset = Preset.from_file("novelai_api/presets/presets_6B_v4/Storywriter.txt")
# NOTE: instantiation of a new reset
# preset = Preset("new preset", model)
# NOTE: modification of the preset
preset.min_length = 1
preset.max_length = 20

# NOTE: instantiate with arguments
Expand Down

0 comments on commit 2977a13

Please sign in to comment.