diff --git a/README.md b/README.md index 589075f..a32a709 100755 --- a/README.md +++ b/README.md @@ -77,8 +77,9 @@ loop.run_until_complete(main()) ```python import asyncio import os -from pydantic import SecretStr + from dotenv import load_dotenv +from pydantic import SecretStr from novelai_python import APIError, LoginCredential from novelai_python.sdk.ai.generate import TextLLMModel, LLM diff --git a/playground/generate.py b/playground/generate.py index 95cdc43..21ea21e 100644 --- a/playground/generate.py +++ b/playground/generate.py @@ -5,7 +5,7 @@ from loguru import logger from pydantic import SecretStr -from novelai_python import APIError, Login +from novelai_python import APIError, LoginCredential from novelai_python import JwtCredential from novelai_python.sdk.ai.generate import TextLLMModel, LLM @@ -18,9 +18,9 @@ async def chat(prompt="Hello"): """Or you can use the login credential to get the renewable jwt token""" - _login_credential = Login.build( - user_name=os.getenv("NOVELAI_USER"), - password=os.getenv("NOVELAI_PASS") + _login_credential = LoginCredential( + username=os.getenv("NOVELAI_USER"), + password=SecretStr(os.getenv("NOVELAI_PASS")) ) # await _login_credential.request() # print(f"Model List:{enum_to_list(TextLLMModel)}") diff --git a/playground/generate_image.py b/playground/generate_image.py index 4767225..be46782 100755 --- a/playground/generate_image.py +++ b/playground/generate_image.py @@ -6,10 +6,11 @@ import asyncio import os import pathlib + from dotenv import load_dotenv from pydantic import SecretStr -from novelai_python import APIError, Login +from novelai_python import APIError, LoginCredential from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential from novelai_python.sdk.ai.generate_image import Action, Sampler, Model from novelai_python.utils.useful import enum_to_list @@ -21,9 +22,9 @@ async def generate(prompt="1girl, year 2023, dynamic angle, best quality, amazin raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it") credential = JwtCredential(jwt_token=SecretStr(jwt)) """Or you can use the login credential to get the renewable jwt token""" - _login_credential = Login.build( - user_name=os.getenv("NOVELAI_USER"), - password=os.getenv("NOVELAI_PASS") + _login_credential = LoginCredential( + username=os.getenv("NOVELAI_USER"), + password=SecretStr(os.getenv("NOVELAI_PASS")) ) # await _login_credential.request() print(f"Action List:{enum_to_list(Action)}") diff --git a/playground/generate_image_img2img.py b/playground/generate_image_img2img.py index 19c836d..fe58766 100755 --- a/playground/generate_image_img2img.py +++ b/playground/generate_image_img2img.py @@ -11,7 +11,7 @@ from loguru import logger from pydantic import SecretStr -from novelai_python import APIError, Login +from novelai_python import APIError, Login, LoginCredential from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential from novelai_python.sdk.ai.generate_image import Action, Sampler from novelai_python.utils.useful import enum_to_list @@ -26,9 +26,9 @@ async def generate( raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it") credential = JwtCredential(jwt_token=SecretStr(jwt)) """Or you can use the login credential to get the jwt token""" - _login_credential = Login.build( - user_name=os.getenv("NOVELAI_USER"), - password=os.getenv("NOVELAI_PASS") + _login_credential = LoginCredential( + username=os.getenv("NOVELAI_USER"), + password=SecretStr(os.getenv("NOVELAI_PASS")) ) # await _login_credential.request() print(f"Action List:{enum_to_list(Action)}") diff --git a/playground/generate_stream.py b/playground/generate_stream.py index 09212ae..731c6bb 100644 --- a/playground/generate_stream.py +++ b/playground/generate_stream.py @@ -5,7 +5,7 @@ from loguru import logger from pydantic import SecretStr -from novelai_python import APIError, Login +from novelai_python import APIError, Login, LoginCredential from novelai_python import JwtCredential from novelai_python.sdk.ai.generate_stream import TextLLMModel, LLMStream, LLMStreamResp @@ -25,9 +25,9 @@ def loop_connect(resp: list): async def stream(prompt="Hello"): """Or you can use the login credential to get the renewable jwt token""" - _login_credential = Login.build( - user_name=os.getenv("NOVELAI_USER"), - password=os.getenv("NOVELAI_PASS") + _login_credential = LoginCredential( + username=os.getenv("NOVELAI_USER"), + password=SecretStr(os.getenv("NOVELAI_PASS")) ) # await _login_credential.request() # print(f"Model List:{enum_to_list(TextLLMModel)}") diff --git a/playground/vibe_img2img.py b/playground/vibe_img2img.py index 4c6948a..f06e111 100644 --- a/playground/vibe_img2img.py +++ b/playground/vibe_img2img.py @@ -2,10 +2,11 @@ import asyncio import os import pathlib + from dotenv import load_dotenv from pydantic import SecretStr -from novelai_python import APIError, Login +from novelai_python import APIError, LoginCredential from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential from novelai_python.sdk.ai.generate_image import Action, Sampler from novelai_python.utils.useful import enum_to_list @@ -21,9 +22,9 @@ async def generate( raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it") credential = JwtCredential(jwt_token=SecretStr(jwt)) """Or you can use the login credential to get the jwt token""" - _login_credential = Login.build( - user_name=os.getenv("NOVELAI_USER"), - password=os.getenv("NOVELAI_PASS") + _login_credential = LoginCredential( + username=os.getenv("NOVELAI_USER"), + password=SecretStr(os.getenv("NOVELAI_PASS")) ) # await _login_credential.request() print(f"Action List:{enum_to_list(Action)}") diff --git a/src/novelai_python/sdk/ai/generate/__init__.py b/src/novelai_python/sdk/ai/generate/__init__.py index 8cffbe0..75f8b9c 100644 --- a/src/novelai_python/sdk/ai/generate/__init__.py +++ b/src/novelai_python/sdk/ai/generate/__init__.py @@ -24,7 +24,7 @@ class LLM(ApiBaseModel): """ - LLM Stream for /ai/generate-stream + LLM for /ai/generate """ _endpoint: str = PrivateAttr("https://api.novelai.net") input: str = Field(..., description="Base64 encoded token text") @@ -184,28 +184,28 @@ async def request(self, message = _msg.get("message", "Unknown error") if status_code == 400: raise APIError( - "A validation error occured.", + f"A validation error occured. {message}", request=request_data, code=status_code, response=_msg ) elif status_code == 401: raise APIError( - "Access Token is incorrect.", + f"Access Token is incorrect. {message}", request=request_data, code=status_code, response=_msg ) elif status_code == 402: raise APIError( - "An active subscription is required to access this endpoint.", + f"An active subscription is required to access this endpoint. {message}", request=request_data, code=status_code, response=_msg ) elif status_code == 409: raise APIError( - "A conflict error occured.", + f"A conflict error occured. {message}", request=request_data, code=status_code, response=_msg ) else: raise APIError( - f"An unknown error occured.{response.status_code}", + f"An unknown error occured. {response.status_code} {message}", request=request_data, code=status_code, response=_msg ) else: diff --git a/src/novelai_python/sdk/ai/generate/_enum.py b/src/novelai_python/sdk/ai/generate/_enum.py index 4fdeb3e..6d35c80 100644 --- a/src/novelai_python/sdk/ai/generate/_enum.py +++ b/src/novelai_python/sdk/ai/generate/_enum.py @@ -71,7 +71,7 @@ def generate_order(request_body: dict) -> List[int]: order_list = [] for member in Order: key, order = member.value - if key in request_body and request_body[key]: + if key in request_body and request_body[key] is None: order_list.append(order) order_list.sort() # ensures the order list is properly sorted according to the true order return order_list diff --git a/src/novelai_python/tool/image_metadata/__init__.py b/src/novelai_python/tool/image_metadata/__init__.py index ac773c3..8118ef6 100644 --- a/src/novelai_python/tool/image_metadata/__init__.py +++ b/src/novelai_python/tool/image_metadata/__init__.py @@ -66,9 +66,10 @@ def vibe_transfer_strength(self) -> List[float]: Get the vibe transfer strength totally :return: List[float] """ - if self.reference_strength: - return [self.reference_strength] - return self.reference_strength_multiple + if self.reference_strength_multiple: + return self.reference_strength_multiple + reference_strength = [] if self.reference_strength is None else [self.reference_strength] + return reference_strength @property def vibe_transfer_information(self) -> List[float]: @@ -76,9 +77,11 @@ def vibe_transfer_information(self) -> List[float]: Get the vibe transfer information totally :return: List[float] """ - if self.reference_information_extracted: - return [self.reference_information_extracted] - return self.reference_information_extracted_multiple + if self.reference_information_extracted_multiple: + return self.reference_information_extracted_multiple + reference_information = [] if self.reference_information_extracted is None else [ + self.reference_information_extracted] + return reference_information Title: str = "AI generated image" Software: str = "NovelAI" diff --git a/src/novelai_python/tool/paint_mask/__init__.py b/src/novelai_python/tool/paint_mask/__init__.py index 641c744..fc45932 100644 --- a/src/novelai_python/tool/paint_mask/__init__.py +++ b/src/novelai_python/tool/paint_mask/__init__.py @@ -2,12 +2,13 @@ import numpy as np -def create_mask_from_sketch(original_img_bytes: bytes, - sketch_img_bytes: bytes, - min_block_size: int = 15, - jagged_edges: bool = True, - output_format: str = '.png' - ) -> bytes: +def create_mask_from_sketch( + original_img_bytes: bytes, + sketch_img_bytes: bytes, + min_block_size: int = 15, + jagged_edges: bool = True, + output_format: str = '.png' +) -> bytes: """ Function to create a mask from original and sketch images input as bytes. Returns BytesIO object.