mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-26 22:45:00 +00:00
Merge branch 'main' of github.com:Aider-AI/aider
This commit is contained in:
commit
8fe52d7b0d
6 changed files with 57 additions and 21 deletions
|
@ -70,9 +70,17 @@ class Analytics:
|
||||||
# ephemeral
|
# ephemeral
|
||||||
logfile = None
|
logfile = None
|
||||||
|
|
||||||
def __init__(self, logfile=None, permanently_disable=False):
|
def __init__(
|
||||||
|
self,
|
||||||
|
logfile=None,
|
||||||
|
permanently_disable=False,
|
||||||
|
posthog_host=None,
|
||||||
|
posthog_project_api_key=None
|
||||||
|
):
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
self.get_or_create_uuid()
|
self.get_or_create_uuid()
|
||||||
|
self.custom_posthog_host = posthog_host
|
||||||
|
self.custom_posthog_project_api_key = posthog_project_api_key
|
||||||
|
|
||||||
if self.permanently_disable or permanently_disable or not self.asked_opt_in:
|
if self.permanently_disable or permanently_disable or not self.asked_opt_in:
|
||||||
self.disable(permanently_disable)
|
self.disable(permanently_disable)
|
||||||
|
@ -92,8 +100,8 @@ class Analytics:
|
||||||
|
|
||||||
# self.mp = Mixpanel(mixpanel_project_token)
|
# self.mp = Mixpanel(mixpanel_project_token)
|
||||||
self.ph = Posthog(
|
self.ph = Posthog(
|
||||||
project_api_key=posthog_project_api_key,
|
project_api_key=self.custom_posthog_project_api_key or posthog_project_api_key,
|
||||||
host=posthog_host,
|
host=self.custom_posthog_host or posthog_host,
|
||||||
on_error=self.posthog_error,
|
on_error=self.posthog_error,
|
||||||
enable_exception_autocapture=True,
|
enable_exception_autocapture=True,
|
||||||
super_properties=self.get_system_info(), # Add system info to all events
|
super_properties=self.get_system_info(), # Add system info to all events
|
||||||
|
|
|
@ -582,6 +582,16 @@ def get_parser(default_config_files, git_root):
|
||||||
help="Permanently disable analytics",
|
help="Permanently disable analytics",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--analytics-posthog-host",
|
||||||
|
metavar="ANALYTICS_POSTHOG_HOST",
|
||||||
|
help="Send analytics to custom PostHog instance",
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--analytics-posthog-project-api-key",
|
||||||
|
metavar="ANALYTICS_POSTHOG_PROJECT_API_KEY",
|
||||||
|
help="Send analytics to custom PostHog project"
|
||||||
|
)
|
||||||
|
|
||||||
#########
|
#########
|
||||||
group = parser.add_argument_group("Upgrading")
|
group = parser.add_argument_group("Upgrading")
|
||||||
|
|
|
@ -63,37 +63,38 @@ class ChatSummary:
|
||||||
if split_index <= min_split:
|
if split_index <= min_split:
|
||||||
return self.summarize_all(messages)
|
return self.summarize_all(messages)
|
||||||
|
|
||||||
|
# Split head and tail
|
||||||
head = messages[:split_index]
|
head = messages[:split_index]
|
||||||
tail = messages[split_index:]
|
tail = messages[split_index:]
|
||||||
|
|
||||||
sized = sized[:split_index]
|
# Only size the head once
|
||||||
head.reverse()
|
sized_head = sized[:split_index]
|
||||||
sized.reverse()
|
|
||||||
|
# Precompute token limit (fallback to 4096 if undefined)
|
||||||
|
model_max_input_tokens = self.models[0].info.get("max_input_tokens") or 4096
|
||||||
|
model_max_input_tokens -= 512 # reserve buffer for safety
|
||||||
|
|
||||||
keep = []
|
keep = []
|
||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
# These sometimes come set with value = None
|
# Iterate in original order, summing tokens until limit
|
||||||
model_max_input_tokens = self.models[0].info.get("max_input_tokens") or 4096
|
for tokens, msg in sized_head:
|
||||||
model_max_input_tokens -= 512
|
total += tokens
|
||||||
|
|
||||||
for i in range(split_index):
|
|
||||||
total += sized[i][0]
|
|
||||||
if total > model_max_input_tokens:
|
if total > model_max_input_tokens:
|
||||||
break
|
break
|
||||||
keep.append(head[i])
|
keep.append(msg)
|
||||||
|
# No need to reverse lists back and forth
|
||||||
keep.reverse()
|
|
||||||
|
|
||||||
summary = self.summarize_all(keep)
|
summary = self.summarize_all(keep)
|
||||||
|
|
||||||
tail_tokens = sum(tokens for tokens, msg in sized[split_index:])
|
# If the combined summary and tail still fits, return directly
|
||||||
summary_tokens = self.token_count(summary)
|
summary_tokens = self.token_count(summary)
|
||||||
|
tail_tokens = sum(tokens for tokens, _ in sized[split_index:])
|
||||||
result = summary + tail
|
|
||||||
if summary_tokens + tail_tokens < self.max_tokens:
|
if summary_tokens + tail_tokens < self.max_tokens:
|
||||||
return result
|
return summary + tail
|
||||||
|
|
||||||
return self.summarize_real(result, depth + 1)
|
# Otherwise recurse with increased depth
|
||||||
|
return self.summarize_real(summary + tail, depth + 1)
|
||||||
|
|
||||||
def summarize_all(self, messages):
|
def summarize_all(self, messages):
|
||||||
content = ""
|
content = ""
|
||||||
|
|
|
@ -633,7 +633,12 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
)
|
)
|
||||||
os.environ["OPENAI_ORGANIZATION"] = args.openai_organization_id
|
os.environ["OPENAI_ORGANIZATION"] = args.openai_organization_id
|
||||||
|
|
||||||
analytics = Analytics(logfile=args.analytics_log, permanently_disable=args.analytics_disable)
|
analytics = Analytics(
|
||||||
|
logfile=args.analytics_log,
|
||||||
|
permanently_disable=args.analytics_disable,
|
||||||
|
posthog_host=args.analytics_posthog_host,
|
||||||
|
posthog_project_api_key=args.analytics_posthog_project_api_key
|
||||||
|
)
|
||||||
if args.analytics is not False:
|
if args.analytics is not False:
|
||||||
if analytics.need_to_ask(args.analytics):
|
if analytics.need_to_ask(args.analytics):
|
||||||
io.tool_output(
|
io.tool_output(
|
||||||
|
|
|
@ -298,6 +298,12 @@
|
||||||
## Permanently disable analytics
|
## Permanently disable analytics
|
||||||
#analytics-disable: false
|
#analytics-disable: false
|
||||||
|
|
||||||
|
## PostHog host (default: https://us.i.posthog.com)
|
||||||
|
#analytics-posthog-host: xxx
|
||||||
|
|
||||||
|
## PostHog project api key (default: phc_99T7muzafUMMZX15H8XePbMSreEUzahHbtWjy3l5Qbv)
|
||||||
|
#analytics-posthog-project-api-key: xxx
|
||||||
|
|
||||||
############
|
############
|
||||||
# Upgrading:
|
# Upgrading:
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,12 @@ If you want to just log analytics without reporting them, you can do:
|
||||||
aider --analytics-log filename.jsonl --no-analytics
|
aider --analytics-log filename.jsonl --no-analytics
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Sending analytics to custom PostHog project or installation
|
||||||
|
|
||||||
|
Aider uses PostHog for analytics collection. You can configure aider to send analytics to your own PostHog project or a custom PostHog installation using these parameters:
|
||||||
|
|
||||||
|
- `--analytics-posthog-project-api-key KEY` - Set a custom PostHog project API key
|
||||||
|
- `--analytics-posthog-host HOST` - Set a custom PostHog host (default is app.posthog.com)
|
||||||
|
|
||||||
## Reporting issues
|
## Reporting issues
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue