Skip to content

Commit dbcc9e8

Browse files
authored
Merge pull request #1159 from LucienShui/fix/profile_disable_telemetry_not_working
Fix/profile disable_telemetry not working
2 parents 924715c + 3dc3086 commit dbcc9e8

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

docs/telemetry/telemetry.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ If you prefer to opt out of telemetry, you can do this in two ways.
1212

1313
### Python
1414

15-
Set `anonymized_telemetry` to `false` on the `interpreter` object:
15+
Set `disable_telemetry` to `true` on the `interpreter` object:
1616

1717
```python
1818
from interpreter import interpreter
19-
interpreter.anonymized_telemetry = False
19+
interpreter.disable_telemetry = True
2020
```
2121

2222
### Terminal
@@ -29,20 +29,20 @@ interpreter --disable_telemetry
2929

3030
### Configuration File
3131

32-
Set `anonymized_telemetry` to `false`. This will persist to future terminal sessions:
32+
Set `disable_telemetry` to `true`. This will persist to future terminal sessions:
3333

3434
```yaml
35-
anonymized_telemetry: false
35+
disable_telemetry: true
3636
```
3737
3838
### Environment Variables
3939
40-
Set `ANONYMIZED_TELEMETRY` to `False` in your shell or server environment.
40+
Set `DISABLE_TELEMETRY` to `true` in your shell or server environment.
4141

4242
If you are running Open Interpreter on your local computer with `docker-compose` you can set this value in an `.env` file placed in the same directory as the `docker-compose.yml` file:
4343

4444
```
45-
ANONYMIZED_TELEMETRY=False
45+
DISABLE_TELEMETRY=true
4646
```
4747

4848
# What do you track?

interpreter/core/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
"let me know what you'd like to do next.",
5858
"please provide more information.",
5959
],
60-
anonymous_telemetry=os.getenv("ANONYMIZED_TELEMETRY", "True") == "True",
60+
disable_telemetry=os.getenv("DISABLE_TELEMETRY", "false").lower() == "true",
6161
in_terminal_interface=False,
6262
conversation_history=True,
6363
conversation_filename=None,
@@ -87,7 +87,7 @@ def __init__(
8787
self.max_output = max_output
8888
self.safe_mode = safe_mode
8989
self.shrink_images = shrink_images
90-
self.anonymous_telemetry = anonymous_telemetry
90+
self.disable_telemetry = disable_telemetry
9191
self.in_terminal_interface = in_terminal_interface
9292
self.multi_line = multi_line
9393

@@ -132,10 +132,14 @@ def wait(self):
132132
# Return new messages
133133
return self.messages[self.last_messages_count :]
134134

135+
@property
136+
def anonymous_telemetry(self) -> bool:
137+
return not self.disable_telemetry and not self.offline
138+
135139
def chat(self, message=None, display=True, stream=False, blocking=True):
136140
try:
137141
self.responding = True
138-
if self.anonymous_telemetry and not self.offline:
142+
if self.anonymous_telemetry:
139143
message_type = type(
140144
message
141145
).__name__ # Only send message type, no content
@@ -168,7 +172,7 @@ def chat(self, message=None, display=True, stream=False, blocking=True):
168172

169173
except Exception as e:
170174
self.responding = False
171-
if self.anonymous_telemetry and not self.offline:
175+
if self.anonymous_telemetry:
172176
message_type = type(message).__name__
173177
send_telemetry(
174178
"errored",

interpreter/core/utils/telemetry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
22
Sends anonymous telemetry to posthog. This helps us know how people are using OI / what needs our focus.
33
4-
Disable this by running `interpreter --disable_telemetry` or `interpreter.anonymized_telemetry = False` or setting the `ANONYMIZED_TELEMETRY` os var to `false`.
4+
Disable anonymous telemetry by execute one of below:
5+
1. Running `interpreter --disable_telemetry` in command line.
6+
2. Executing `interpreter.disable_telemetry = True` in Python.
7+
3. Setting the `DISABLE_TELEMETRY` os var to `true`.
58
69
based on ChromaDB's telemetry: https://github.com/chroma-core/chroma/tree/main/chromadb/telemetry/product
710
"""

interpreter/terminal_interface/start_terminal_interface.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def start_terminal_interface(interpreter):
144144
"nickname": "dt",
145145
"help_text": "disables sending of basic anonymous usage stats",
146146
"type": bool,
147-
"default": True,
148-
"action": "store_false",
149-
"attribute": {"object": interpreter, "attr_name": "anonymous_telemetry"},
147+
"default": False,
148+
"attribute": {"object": interpreter, "attr_name": "disable_telemetry"},
150149
},
151150
{
152151
"name": "offline",
@@ -260,7 +259,10 @@ def start_terminal_interface(interpreter):
260259
for arg in arguments:
261260
action = arg.get("action", "store_true")
262261
nickname = arg.get("nickname")
263-
default = arg.get("default")
262+
263+
name_or_flags = [f'--{arg["name"]}']
264+
if nickname:
265+
name_or_flags.append(f"-{nickname}")
264266

265267
# Construct argument name flags
266268
flags = (
@@ -306,7 +308,7 @@ def start_terminal_interface(interpreter):
306308
open_storage_dir("models")
307309
return
308310

309-
if args.reset_profile != "NOT_PROVIDED":
311+
if args.reset_profile is not None and args.reset_profile != "NOT_PROVIDED":
310312
reset_profile(
311313
args.reset_profile
312314
) # This will be None if they just ran `--reset_profile`
@@ -342,7 +344,7 @@ def start_terminal_interface(interpreter):
342344

343345
### Apply profile
344346

345-
interpreter = profile(interpreter, args.profile)
347+
interpreter = profile(interpreter, args.profile or get_argument_dictionary(arguments, "profile")["default"])
346348

347349
### Set attributes on interpreter, because the arguments passed in via the CLI should override profile
348350

@@ -417,9 +419,7 @@ def start_terminal_interface(interpreter):
417419
def set_attributes(args, arguments):
418420
for argument_name, argument_value in vars(args).items():
419421
if argument_value is not None:
420-
argument_dictionary = [a for a in arguments if a["name"] == argument_name]
421-
if len(argument_dictionary) > 0:
422-
argument_dictionary = argument_dictionary[0]
422+
if argument_dictionary := get_argument_dictionary(arguments, argument_name):
423423
if "attribute" in argument_dictionary:
424424
attr_dict = argument_dictionary["attribute"]
425425
setattr(attr_dict["object"], attr_dict["attr_name"], argument_value)
@@ -430,6 +430,12 @@ def set_attributes(args, arguments):
430430
)
431431

432432

433+
def get_argument_dictionary(arguments: list[dict], key: str) -> dict:
434+
if len(argument_dictionary_list := list(filter(lambda x: x["name"] == key, arguments))) > 0:
435+
return argument_dictionary_list[0]
436+
return {}
437+
438+
433439
def main():
434440
interpreter = OpenInterpreter(import_computer_api=True)
435441
try:

0 commit comments

Comments
 (0)