forked from theroyallab/tabbyAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tree: Add generation logging support
Generations can be logged in the console along with sampling parameters if the user enables it in config. Metrics are always logged at the end of each prompt. In addition, the model endpoint tells the user if they're being logged or not for transparancy purposes. Signed-off-by: kingbri <bdashore3@proton.me>
- Loading branch information
Showing
5 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Dict | ||
from pydantic import BaseModel | ||
|
||
# Logging preference config | ||
class LogConfig(BaseModel): | ||
prompt: bool = False | ||
generation_params: bool = False | ||
|
||
# Global reference to logging preferences | ||
config = LogConfig() | ||
|
||
# Wrapper to set the logging config for generations | ||
def update_from_dict(options_dict: Dict[str, bool]): | ||
global config | ||
|
||
# Force bools on the dict | ||
for value in options_dict.values(): | ||
if value is None: | ||
value = False | ||
|
||
config = LogConfig.parse_obj(options_dict) | ||
|
||
def broadcast_status(): | ||
enabled = [] | ||
if config.prompt: | ||
enabled.append("prompts") | ||
|
||
if config.generation_params: | ||
enabled.append("generation params") | ||
|
||
if len(enabled) > 0: | ||
print("Generation logging is enabled for: " + ", ".join(enabled)) | ||
else: | ||
print("Generation logging is disabled") | ||
|
||
# Logs generation parameters to console | ||
def log_generation_params(**kwargs): | ||
if config.generation_params: | ||
print(f"Generation options: {kwargs}\n") | ||
|
||
def log_prompt(prompt: str): | ||
if config.prompt: | ||
print(f"Prompt: {prompt if prompt else 'Empty'}\n") | ||
|
||
def log_response(response: str): | ||
if config.prompt: | ||
print(f"Response: {response if response else 'Empty'}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters