Giter Site home page Giter Site logo

novelai-api's People

Contributors

aedial avatar agentd00nut avatar bdavs avatar cikmo avatar fensterbank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

novelai-api's Issues

how to make the generated text always end with a complete sentence?

I find that when I generate text on a web page, the endings are all one complete sentence, starting with "." but when I use the api to generate it, it always ends with an incomplete sentence. I have changed "global_settings.generate_until_sentence = True" in the api, because I find that the request in the web page is "True" here but the api defaults to "false". But I found it didn't work. So I would like to know: how can I make the api generate text that always ends with a complete sentence.Can anyone answer my question? Thanks

Translated with www.DeepL.com/Translator (free version)

Presets props are sent to the API, which are not sent by the official UI.

While debugging my requests against the API and comparing it with the ones from the WebUI, I noticed something weird.
My first thought was that the presets files are outdated, but indeed they do match the ones I can export from the Web UI.

The following properties in red are part of the preset files, but the Web UI does not send them to the API, while this library does.
grafik

I don't know, if this affects the generation (because I seem to have other issues atm) or if the API ignores them, but I think we should make sure our requests matches them from the official Web UI.

Add support for 3.11

Is there a spesific reason for not supporting 3.11, or can it simply be added to the dependencies?

default.preset does not apply.

preset = ImagePreset.from_v3_config()
(from generate_image_test_samplers.py)

return cls.from_file(Path(__file__).parent / "image_presets" / "presets_v3" / "default.preset")
(from ImagePreset.py)

So I modified novelai_api/image_presets/presets_v3/default.preset, but it does not apply. I've tried reinstalling the module, but still does not works.

How to configure loreBook?

I don't find any data about "loreBook" in the parameters of the web request or in the parameters of the api. Is there any usage of loreBook in the api? How can I achieve the effect of loreBook in the web page? Is it possible to search for keywords in the context? If the keyword is found, then the text about the keyword is added to the context. Is there a simpler way to do this? For example, a function that has been wrapped and passed the json data of loreBook directly.
That's my question. Thank you very much.

Translated with www.DeepL.com/Translator (free version)

random tags

I want to use random nai tags. What is their endpoint?

novelai run in class error

I'm trying to create Class for run functions in novella inside of flask application. But I have an error.

Traceback (most recent call last):
  File "/Users/mirhanmac/Desktop/Projects/noveapi/app.py", line 15, in <module>
    webServer = WebServer(flaskLogger, env, novelApi)
  File "/Users/mirhanmac/Desktop/Projects/noveapi/web.py", line 13, in __init__
    self.novelApi.run()
  File "/Users/mirhanmac/Desktop/Projects/noveapi/novel.py", line 26, in run
    asyncio.run(self.main())
  File "/opt/homebrew/Cellar/[email protected]/3.9.13_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/[email protected]/3.9.13_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/Users/mirhanmac/Desktop/Projects/noveapi/novel.py", line 22, in main
    keystore = await api.high_level.get_keystore(key)
  File "/Users/mirhanmac/Desktop/Projects/noveapi/novelapi/lib/python3.9/site-packages/novelai_api/_high_level.py", line 78, in get_keystore
    keystore.decrypt(key)
  File "/Users/mirhanmac/Desktop/Projects/noveapi/novelapi/lib/python3.9/site-packages/novelai_api/Keystore.py", line 90, in decrypt
    keystore = loads(b64decode(self.data["keystore"]).decode())
KeyError: 'keystore'

This is my code:

from novelai_api import NovelAI_API
from novelai_api.utils import get_encryption_key, decrypt_user_data
from aiohttp import ClientSession
import asyncio

class NovelAPI:
    def __init__(self, logger, env):
        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")
        self.logger = logger
        self.username = env["NAI_USERNAME"]
        self.password = env["NAI_PASSWORD"]

    async def main(self):
        async with ClientSession() as session:
            api = NovelAI_API(session, logger = self.logger)
            login = await api.high_level.login(self.username, self.password)
            self.logger.info('Bearer ' + login)

            key = get_encryption_key(self.username, self.password)
            keystore = await api.high_level.get_keystore(key)
            self.logger.info(keystore)

    def run(self):
        asyncio.run(self.main())

ddim sampler using /ai/generation-image API not working properly on nai-diffusion-v3.

If sampler set to ddim for /ai/generation-image with nai-diffusion-v3, it generates noised image.

using_API

On web page, it generates properly. but in EXIF, sampler shows as "Euler a" on parameters and "ddim_v3" on Comment.

using_WEB

It seems using ddim sampler via API needs more settings or something, but I cannot get additional settings or params for ddim from code.

I checked,

  • Euler a sampler generates different image.

I didn't check,

  • sending sampler as "ddim_v3".
  • sending "ddim" with other models.

By the way, on web page, if SMEA+DYN is checked with other sampler then change sampler to DDIM,
the generation costs 28 anlas, not 20 anlas even though DDIM cannot use SMEA or SMEA+DYN.

generate_image return "novelai_api.NovelAIError.NovelAIError: 200 - OK"

I called generate_image with the following code and got a strange error novelai_api.NovelAIError.NovelAIError: 200 - OK.

Traceback:

Traceback (most recent call last):
  File "/root/opt/app.py", line 82, in message_img
    run(genarate(prompt))
  File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/root/opt/app.py", line 55, in genarate
    async for img in api.high_level.generate_image(prompt, ImageModel.Anime_Curated, preset):
  File "/usr/local/lib/python3.9/site-packages/novelai_api/_high_level.py", line 355, in generate_image
    async for e in self._parent.low_level.generate_image(prompt, model, settings):
  File "/usr/local/lib/python3.9/site-packages/novelai_api/_low_level.py", line 657, in generate_image
    self._treat_response_object(rsp, content, 201)
  File "/usr/local/lib/python3.9/site-packages/novelai_api/_low_level.py", line 48, in _treat_response_object
    raise NovelAIError(rsp.status, str(rsp.reason))
novelai_api.NovelAIError.NovelAIError: 200 - OK

Code:

async with API() as api_handler:
     api = api_handler.api
     preset = ImagePreset()
     preset["n_samples"] = 1
     preset["resolution"] = (512, 512)
     preset["quality_toggle"] = False
     async for img in api.high_level.generate_image(prompt, ImageModel.Anime_Curated, preset):
         with open(GENERATED_FILEPATH, "wb") as f:
             f.write(img)

The entire code is at the following URL
https://github.com/sifue/novelai-slackbot/tree/02419d7d735257294478483753486669620cc384

Undesired content no longer set properly on image generation

Since the apparent changes to the NovelAI API a couple of days ago, undesired content no longer seems to be set properly.

All the images I've been able to generate since come back with uc="" (and are notably low quality as a result!). I've confirmed that parameters['uc'] is properly set in _low_level.py when the API call is made. I guess perhaps the naming of the parameters at the NovelAI end has changed?

Some questions I had:

  • Why am I getting this error even though the generation is working as it should?

Screenshot 2023-10-23 173424

  • For the text adventure module, how can I control 'do' or 'say' options, there seems to be no such parameter, there's only prompt.

  • Is there an example of managing context size that I can look at? I wanted to see how to delete context line by line? Currently I have my prompt as just plain text that I append into as you told, should I make it something like an array of sentences instead so that I can remove by index number?

  • How does the memory context that you provide in novelAI webapp work? Is it any different?

Fails to launch

Creating an API object using

from novelai_api import *

api = NovelAI_API(1, 'properUsername', 'properPassword')

fails with this error:

...\venv\lib\site-packages\novelai_api\NovelAI_API.py:42: RuntimeWarning: coroutine 'High_Level.login' was never awaited
  self.high_level.login(username, password)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

I don't have any experience with async, and the lack of documentation makes it hard to figure out what's going on.

Example that includes generate

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!

Got the UnicodeDecodeError: 'utf-8' with /ai/generate-image

  • I used this API and tried to generate_image.
  • But I got the following UnicodeDecodeError.
  • How can I resolve this?
  • Best regards.
D:\gitwork\test>python test.py
Traceback (most recent call last):
  File "D:\gitwork\test\test.py", line 89, in <module>
    run(main())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "D:\gitwork\test\test.py", line 83, in main
    async for _, img in api.high_level.generate_image("1girl", ImageModel.Anime_Full, preset):
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_high_level.py", line 355, in generate_image
    async for e in self._parent.low_level.generate_image(prompt, model, settings):
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_low_level.py", line 621, in generate_image
    async for rsp, content in self.request_stream("post", "/ai/generate-image", args):
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_low_level.py", line 161, in request_stream
    raise e
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_low_level.py", line 158, in request_stream
    async for i in self._request(method, url, session, data, stream):
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_low_level.py", line 136, in _request
    yield rsp, await self._treat_response_stream(rsp, content)
  File "C:\Users\PC_User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\novelai_api\_low_level.py", line 88, in _treat_response_stream
    data = data.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 11: invalid start byte

D:\gitwork\test>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.