mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-22 23:38:57 +00:00
feat: workflows for formatting/linting (#35)
* 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>
This commit is contained in:
@@ -1,31 +1,40 @@
|
||||
"""
|
||||
Functions for logging generation events.
|
||||
"""
|
||||
from typing import Dict
|
||||
from pydantic import BaseModel
|
||||
|
||||
# Logging preference config
|
||||
|
||||
class LogConfig(BaseModel):
|
||||
"""Logging preference config."""
|
||||
|
||||
prompt: bool = False
|
||||
generation_params: bool = False
|
||||
|
||||
# Global reference to logging preferences
|
||||
config = LogConfig()
|
||||
|
||||
# Wrapper to set the logging config for generations
|
||||
# Global reference to logging preferences
|
||||
CONFIG = LogConfig()
|
||||
|
||||
|
||||
def update_from_dict(options_dict: Dict[str, bool]):
|
||||
global config
|
||||
"""Wrapper to set the logging config for generations"""
|
||||
global CONFIG
|
||||
|
||||
# Force bools on the dict
|
||||
for value in options_dict.values():
|
||||
if value is None:
|
||||
value = False
|
||||
|
||||
config = LogConfig.model_validate(options_dict)
|
||||
CONFIG = LogConfig.model_validate(options_dict)
|
||||
|
||||
|
||||
def broadcast_status():
|
||||
"""Broadcasts the current logging status"""
|
||||
enabled = []
|
||||
if config.prompt:
|
||||
if CONFIG.prompt:
|
||||
enabled.append("prompts")
|
||||
|
||||
if config.generation_params:
|
||||
if CONFIG.generation_params:
|
||||
enabled.append("generation params")
|
||||
|
||||
if len(enabled) > 0:
|
||||
@@ -33,15 +42,20 @@ def broadcast_status():
|
||||
else:
|
||||
print("Generation logging is disabled")
|
||||
|
||||
# Logs generation parameters to console
|
||||
|
||||
def log_generation_params(**kwargs):
|
||||
if config.generation_params:
|
||||
"""Logs generation parameters to console."""
|
||||
if CONFIG.generation_params:
|
||||
print(f"Generation options: {kwargs}\n")
|
||||
|
||||
|
||||
def log_prompt(prompt: str):
|
||||
if config.prompt:
|
||||
"""Logs the prompt to console."""
|
||||
if CONFIG.prompt:
|
||||
print(f"Prompt: {prompt if prompt else 'Empty'}\n")
|
||||
|
||||
|
||||
def log_response(response: str):
|
||||
if config.prompt:
|
||||
"""Logs the response to console."""
|
||||
if CONFIG.prompt:
|
||||
print(f"Response: {response if response else 'Empty'}\n")
|
||||
|
||||
Reference in New Issue
Block a user