-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: track cost and token usage in log file #80
Conversation
logger = logging.getLogger(_LOGGER_NAME) | ||
logger.setLevel(level) | ||
log_file_directory.mkdir(parents=True, exist_ok=True) | ||
file_handler = logging.FileHandler(log_file_directory / _LOGGER_FILE_NAME) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about bucketing the logs by time (e.g. goose.yyyy-mm-dd.log
or something)? not sure how verbose the logging could be, but we sorta also get rolling logs for free too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, definitely we can use the TimedRotatingFileHandler when the log gets verbose. At the moment we only log the cost, but I think it will be helpful to log errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense! if we wanna go long-term we could also go one step further extending logging.Filter
to some intelligent routing [or segment] (e.g. api-costs.log
vs goose.log
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, like tags
src/goose/_logger.py
Outdated
|
||
def setup_logging(log_file_directory: Path, level: int = logging.INFO) -> None: | ||
logger = logging.getLogger(_LOGGER_NAME) | ||
logger.setLevel(level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we want to control this via the cli , i've been playing with click
and we could maybe add @click.option("--log-level", ...)
so it's easier to dial up the messages up/down without rebuilding goose
* main: feat: add version options (#74)
I like this - and has been asked for a bit |
fyi since this is a common feature in Q/A or eval tools (langtrace, openlit, traceloop etc) you can have a look to validate approach vs what they are doing. Not suggesting change, just for context: e.g. from openlit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Why
Users can view the cost and token usage in the log file
What
exchange
[PR](feat: collect total token usage square/exchange#32)