* add github workflows for pylint and yapf * yapf * docstrings for auth * fix auth.py * fix generators.py * fix gen_logging.py * fix main.py * fix model.py * fix templating.py * fix utils.py * update formatting.sh to include subdirs for pylint * fix model_test.py * fix wheel_test.py * rename utils to utils_oai * fix OAI/utils_oai.py * fix completion.py * fix token.py * fix lora.py * fix common.py * add pylintrc and fix model.py * finish up pylint * fix attribute error * main.py formatting * add formatting batch script * Main: Remove unnecessary global Linter suggestion. Signed-off-by: kingbri <bdashore3@proton.me> * switch to ruff * Formatting + Linting: Add ruff.toml Signed-off-by: kingbri <bdashore3@proton.me> * Formatting + Linting: Switch scripts to use ruff Also remove the file and recent file change functions from both scripts. Signed-off-by: kingbri <bdashore3@proton.me> * Tree: Format and lint Signed-off-by: kingbri <bdashore3@proton.me> * Scripts + Workflows: Format Signed-off-by: kingbri <bdashore3@proton.me> * Tree: Remove pylint flags We use ruff now Signed-off-by: kingbri <bdashore3@proton.me> * Tree: Format Signed-off-by: kingbri <bdashore3@proton.me> * Formatting: Line length is 88 Use the same value as Black. Signed-off-by: kingbri <bdashore3@proton.me> * Tree: Format Update to new line length rules. Signed-off-by: kingbri <bdashore3@proton.me> --------- Authored-by: AlpinDale <52078762+AlpinDale@users.noreply.github.com> Co-authored-by: kingbri <bdashore3@proton.me>
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
"""Common utilities for the tabbyAPI"""
|
|
import traceback
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
def load_progress(module, modules):
|
|
"""Wrapper callback for load progress."""
|
|
yield module, modules
|
|
|
|
|
|
class TabbyGeneratorErrorMessage(BaseModel):
|
|
"""Common error types."""
|
|
|
|
message: str
|
|
trace: Optional[str] = None
|
|
|
|
|
|
class TabbyGeneratorError(BaseModel):
|
|
"""Common error types."""
|
|
|
|
error: TabbyGeneratorErrorMessage
|
|
|
|
|
|
def get_generator_error(message: str):
|
|
"""Get a generator error."""
|
|
error_message = TabbyGeneratorErrorMessage(
|
|
message=message, trace=traceback.format_exc()
|
|
)
|
|
|
|
generator_error = TabbyGeneratorError(error=error_message)
|
|
|
|
# Log and send the exception
|
|
print(f"\n{generator_error.error.trace}")
|
|
return get_sse_packet(generator_error.model_dump_json())
|
|
|
|
|
|
def get_sse_packet(json_data: str):
|
|
"""Get an SSE packet."""
|
|
return f"data: {json_data}\n\n"
|
|
|
|
|
|
def unwrap(wrapped, default=None):
|
|
"""Unwrap function for Optionals."""
|
|
if wrapped is None:
|
|
return default
|
|
|
|
return wrapped
|
|
|
|
|
|
def coalesce(*args):
|
|
"""Coalesce function for multiple unwraps."""
|
|
return next((arg for arg in args if arg is not None), None)
|