Skip to content

Remove json profile references #1612

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

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions interpreter/__init__.py
Original file line number Diff line number Diff line change
@@ -12,17 +12,20 @@

Configuration
------------
>>> from interpreter import Interpreter, Config
>>> from interpreter import Interpreter, Profile

# Use defaults
interpreter = Interpreter()
Use defaults:

# Load from custom profile
config = Config.from_file("~/custom_profile.json")
interpreter = Interpreter(config)
>>> interpreter = Interpreter()

Load from custom profile:

>>> profile = Profile.from_file("~/custom_profile.py")
>>> interpreter = Interpreter(profile)

Save current settings:

# Save current settings
interpreter.save_config("~/my_settings.json")
>>> interpreter.save_profile("~/my_settings.py")
"""

# Use lazy imports to avoid loading heavy modules immediately
27 changes: 15 additions & 12 deletions interpreter/interpreter.py
Original file line number Diff line number Diff line change
@@ -93,17 +93,20 @@ class Interpreter:
--------
>>> from interpreter import Interpreter

# Basic usage
interpreter = Interpreter()
interpreter.chat()
Basic usage:

# With custom configuration
from interpreter import Profile
profile = Profile.from_file("~/custom_profile.json")
interpreter = Interpreter(profile)
>>> interpreter = Interpreter()
>>> interpreter.chat()

# Save settings for later
interpreter.save_profile("~/my_settings.json")
With custom configuration:

>>> from interpreter import Profile
>>> profile = Profile.from_file("~/custom_profile.py")
>>> interpreter = Interpreter(profile)

Save settings for later:

>>> interpreter.save_profile("~/my_settings.py")

Parameters
----------
@@ -152,7 +155,7 @@ def load_profile(self, path):
Load settings from a profile file

Example:
>>> interpreter.load_profile("~/work_settings.json")
>>> interpreter.load_profile("~/work_settings.py")
"""
self._profile.load(path)
# Update interpreter attributes from new profile
@@ -164,7 +167,7 @@ def save_profile(self, path=None):
Save current settings as a profile

Example:
>>> interpreter.save_profile("~/my_preferred_settings.json")
>>> interpreter.save_profile("~/my_preferred_settings.py")
"""
# Update profile object with current values
self._profile.from_dict(self.to_dict())
@@ -177,7 +180,7 @@ def from_profile(cls, path):
Create new interpreter instance from a profile file

Example:
>>> interpreter = Interpreter.from_profile("~/work_settings.json")
>>> interpreter = Interpreter.from_profile("~/work_settings.py")
"""
return cls(Profile.from_file(path))

8 changes: 4 additions & 4 deletions interpreter/misc/welcome.py
Original file line number Diff line number Diff line change
@@ -254,9 +254,9 @@ def welcome_message():
--serve Start in server mode

example: interpreter "create a python script"
example: interpreter -m gpt-4 "analyze data.csv"
example: interpreter -m gpt-4 "analyze data.csv"
example: interpreter --auto-run "install nodejs"
example: interpreter --profile work.json
example: interpreter --profile work.py
"""
)

@@ -282,9 +282,9 @@ def welcome_message():
--serve Start in server mode

example: interpreter "create a python script"
example: interpreter -m gpt-4 "analyze data.csv"
example: interpreter -m gpt-4 "analyze data.csv"
example: interpreter --auto-run "install nodejs"
example: interpreter --profile work.json
example: interpreter --profile work.py
"""
)

25 changes: 14 additions & 11 deletions interpreter/profiles.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import json
import os
import platform
import sys
from datetime import datetime


class Profile:
@@ -16,14 +13,17 @@ class Profile:
--------
>>> from interpreter import Profile

# Load defaults (and ~/.openinterpreter if it exists)
profile = Profile()
Load defaults (and ~/.openinterpreter if it exists):

# Load from specific profile
profile = Profile.from_file("~/custom_profile.json")
>>> profile = Profile()

# Save current settings
profile.save("~/my_settings.json")
Load from specific profile:

>>> profile = Profile.from_file("~/custom_profile.py")

Save current settings:

>>> profile.save("~/my_settings.py")
"""

DEFAULT_PROFILE_FOLDER = "~/.openinterpreter"
@@ -129,7 +129,8 @@ def load(self, path):
path += ".py"

if not os.path.exists(path):
# If file doesn't exist, if it's the default, that's fine
# If the missing file is the default profile path, that's fine -
# we'll use the defaults from __init__
if os.path.abspath(os.path.expanduser(path)) == os.path.abspath(
os.path.expanduser(self.DEFAULT_PROFILE_PATH)
):
@@ -147,7 +148,9 @@ def load(self, path):
# This avoids loading the full interpreter module which is resource intensive
content = content.replace(
"from interpreter import interpreter",
"class Interpreter:\n pass\ninterpreter = Interpreter()",
"class Interpreter:\n"
" pass\n"
"interpreter = Interpreter()",
)

# Execute the modified profile content
Loading
Oops, something went wrong.