be careful logging main_models that are not in the model db

This commit is contained in:
Paul Gauthier 2024-08-12 18:20:35 -07:00
parent a7a626423c
commit aa840f0e28
3 changed files with 16 additions and 4 deletions

View file

@ -7,6 +7,7 @@ from pathlib import Path
from mixpanel import Mixpanel
from aider import __version__
from aider.dump import dump # noqa: F401
class Analytics:
@ -46,6 +47,13 @@ class Analytics:
return
properties = {}
if main_model:
if main_model.info:
properties["main_model"] = main_model.name
elif "/" in main_model.name:
properties["main_model"] = main_model.name.split("/")[0] + "/REDACTED"
properties.update(kwargs)
properties.update(self.get_system_info()) # Add system info to all events

View file

@ -1412,13 +1412,13 @@ class Coder:
)
self.event(
"token_usage",
"message_send",
main_model=self.main_model,
prompt_tokens=prompt_tokens,
completion_tokens=completion_tokens,
total_tokens=prompt_tokens + completion_tokens,
cost=cost,
total_cost=self.total_cost,
model=self.main_model.name,
)
def get_multi_response_content(self, final=False):

View file

@ -373,9 +373,13 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
editingmode=editing_mode,
)
analytics = Analytics(args.analytics)
analytics.event("launched")
if args.gui and not return_coder:
if not check_streamlit_install(io):
return
analytics.event("gui session")
launch_gui(argv)
return
@ -497,8 +501,6 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
args.max_chat_history_tokens or main_model.max_chat_history_tokens,
)
analytics = Analytics(args.analytics)
try:
coder = Coder.create(
main_model=main_model,
@ -615,6 +617,8 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
if args.exit:
return
analytics.event("cli session", main_model=main_model)
thread = threading.Thread(target=load_slow_imports)
thread.daemon = True
thread.start()