Skip to content

Commit

Permalink
Merge pull request #57 from LlmKira/dev
Browse files Browse the repository at this point in the history
Fix docs
  • Loading branch information
sudoskys authored Apr 10, 2024
2 parents 582d8bd + 1f8a9ac commit 964c42e
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 40 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions playground/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)}")
Expand Down
9 changes: 5 additions & 4 deletions playground/generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}")
Expand Down
8 changes: 4 additions & 4 deletions playground/generate_image_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}")
Expand Down
8 changes: 4 additions & 4 deletions playground/generate_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)}")
Expand Down
9 changes: 5 additions & 4 deletions playground/vibe_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}")
Expand Down
12 changes: 6 additions & 6 deletions src/novelai_python/sdk/ai/generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/novelai_python/sdk/ai/generate/_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions src/novelai_python/tool/image_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,22 @@ 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]:
"""
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"
Expand Down
13 changes: 7 additions & 6 deletions src/novelai_python/tool/paint_mask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 964c42e

Please sign in to comment.