Aedial/novelai-api

Example that includes generate

Closed this issue · 4 comments

Hello. Thanks so much for working on this. I am new and have just a simple request. Could someone show me how to generate text with a simple example? I am able to log in fine, but I have not been able to figure out how to generate at all. Thanks so much!

Hi, you can see examples on how to generate in tests/test_generate.py (should probably organize things better).
The high level interface (novelai_api/_high_level.py#L232) is built on top of the low level one, and supports input, model, preset, global settings, bad words, banlists and module. It would be the the recommended go-to.
The low level interface (novelai_api/_low_level.py#L397) supports input, model and param.

Thank you so much for the response! İ tried using that test_generate file, but I'm not sure what to do. İ tried putting a call to the generate function in one of the other examples, just like how login(email, password) is used, but i don't have all the arguments i need, like Globalsettings, and presets. O also tried calling the generate function in test_generate, just by putting a reference to it at the end of the file, but no luck. How exactly can i use that test_generate file to actually have generated text printed in terminal? Thanks so much, sorry if this is simple, i just have no experience with this and have been stuck for hours. İ really appreciate the help and all your work!

So, first off, this API is purely async, so almost every function has to be called with some form of await'ing (see asyncio).
Secondly, the test_generate.py file is a pytest test file, so each function is intended to be used by pytest. The test_* functions accept a few arguments : model_preset, input (the text you want to send to the AI) and tokenize (if the function should tokenize the text or delegate the job to the generate function).

The input can be tokenized, for better context control, or passed as a string and will be tokenized inside of generate.

Choosing a model is very simple. Models are an enum and choosing Euterpe, for example, is as simple as writing Models.Euterpe.
Models are iterable.

Choosing a Preset is a bit harder, but quite straight forward. There are 2 main functions :

  • Preset.from_file, to which you need to give the path to a .preset file
  • Preset.from_official, to with you give the model and the name of the official preset you want to choose (which are stored in novelai_api/presets/)
    Presets are also iterable, with Preset[model].

For working directly with GlobalSettings, bad words and biases, look into the relevant generate test. There are a few that showcase their use, especially the last few tests.

For prefix (module), the only thing needed is the hash of the module, which you can easily find in the network tab of your browser, when generating with said module.

Wow! Thank you so much! This is beyond helpful, and gives me plenty to work with, thank you so much for taking the time!