Salta ai contenuti

Open Interpreter

Installation

# Install via pip
pip install open-interpreter

# Install with all optional features
pip install open-interpreter[safe]     # Safe mode dependencies
pip install open-interpreter[os]       # OS mode (computer use) dependencies

# Install from source (latest development)
git clone https://github.com/OpenInterpreter/open-interpreter
cd open-interpreter
pip install -e .

# Verify installation
interpreter --version

# Quick test
interpreter "What is 2 + 2?"

Configuration

# Interactive setup wizard (sets API keys, model, etc.)
interpreter --setup

# Common environment variables
export OPENAI_API_KEY=sk-your-key-here
export ANTHROPIC_API_KEY=sk-ant-your-key-here
export GOOGLE_API_KEY=your-google-key

# Profiles directory (auto-created)
# Linux/Mac: ~/.config/open-interpreter/profiles/
# Windows:   %APPDATA%\Open Interpreter\profiles\

# List available profiles
interpreter --profiles

# Use a named profile
interpreter --profile my_profile.py
# Programmatic configuration
from interpreter import interpreter

# Set model
interpreter.llm.model = "gpt-4o"

# Set API key
interpreter.llm.api_key = "sk-your-key"

# Set base URL (for local models via Ollama, LM Studio, etc.)
interpreter.llm.api_base = "http://localhost:11434/v1"

# Context window and token limits
interpreter.llm.context_window = 110000
interpreter.llm.max_tokens = 4096

# Safety settings
interpreter.safe_mode = "ask"     # "off" | "ask" | "auto"
interpreter.auto_run = False       # Prompt before running code

# System message customization
interpreter.system_message = "You are a helpful coding assistant."

Core Commands / API

CLI FlagDescription
interpreterStart interactive chat
interpreter "task"Run single task and exit
interpreter --model gpt-4oSpecify model
interpreter --osEnable OS/computer use mode
interpreter --localUse local model (Ollama/LM Studio)
interpreter --safe_mode askPrompt before executing code
interpreter --auto_runRun code without prompting
interpreter --visionEnable image input support
interpreter --voiceEnable voice input
interpreter --context_window 110000Set context window size
interpreter --max_tokens 4096Set max output tokens
interpreter --api_base URLCustom API endpoint
interpreter --api_key KEYSet API key inline
interpreter --system_message "..."Override system message
interpreter --profile path.pyLoad profile file
interpreter --resetClear conversation history
interpreter --verboseShow debug output
interpreter --helpShow all options
Python APIDescription
interpreter.chat("task")Run task, return messages
interpreter.chat()Start interactive session
interpreter.messagesAccess conversation history
interpreter.reset()Clear conversation
interpreter.computer.run("python", code)Execute code directly

Advanced Usage

Python SDK — Programmatic Control

from interpreter import interpreter

# Configure
interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True

# Run a task (returns list of messages)
messages = interpreter.chat("Create a bar chart of the top 5 programming languages")

# Inspect output
for message in messages:
    print(f"Role: {message['role']}")
    if message['type'] == 'code':
        print(f"Language: {message['language']}")
        print(f"Code: {message['code']}")
    elif message['type'] == 'message':
        print(f"Content: {message['content']}")

Streaming Responses

from interpreter import interpreter

interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True

# Stream output chunk by chunk
for chunk in interpreter.chat("Analyze my Downloads folder", stream=True, display=False):
    # chunk is a dict: {"role": "assistant", "type": "message", "content": "..."}
    if chunk.get("type") == "message":
        print(chunk.get("content", ""), end="", flush=True)
    elif chunk.get("type") == "code":
        print(f"\n[Running {chunk.get('language')} code...]")
    elif chunk.get("type") == "console":
        print(f"Output: {chunk.get('output', '')}")

OS Mode (Computer Use)

# Start with full computer control
interpreter --os

# OS mode capabilities:
# - Take screenshots
# - Move mouse and click
# - Type text
# - Read screen content
# - Open applications
# - Browse the web
from interpreter import interpreter

# Enable OS mode
interpreter.os = True
interpreter.llm.model = "gpt-4o"           # Vision-capable model required
interpreter.llm.supports_vision = True
interpreter.auto_run = True

# Computer use tasks
interpreter.chat("Open Spotify and play my liked songs playlist")
interpreter.chat("Take a screenshot and describe what you see")
interpreter.chat("Fill out the form at localhost:3000 with test data")

Vision / Image Input

from interpreter import interpreter

interpreter.llm.model = "gpt-4o"
interpreter.llm.supports_vision = True

# Pass image as part of chat
interpreter.chat([
    {
        "role": "user",
        "type": "message",
        "content": "What chart type would best display this data?",
    },
    {
        "role": "user",
        "type": "image",
        "format": "path",
        "content": "/path/to/data-screenshot.png",
    },
])

# Image from URL
interpreter.chat([
    {"role": "user", "type": "message", "content": "Describe this image"},
    {"role": "user", "type": "image", "format": "url", "content": "https://example.com/img.png"},
])

Local Models via Ollama

# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh

# Pull a model
ollama pull codellama
ollama pull llama3

# Run Open Interpreter with local model
interpreter --local
# Select your model from the list

# Or specify directly
interpreter --model ollama/codellama --api_base http://localhost:11434
from interpreter import interpreter

# Local Ollama model
interpreter.llm.model = "ollama/codellama"
interpreter.llm.api_base = "http://localhost:11434"
interpreter.llm.context_window = 4096
interpreter.llm.max_tokens = 1024

interpreter.chat("Write a Python function to sort a list")

Custom Profiles

# ~/.config/open-interpreter/profiles/data_analyst.py

from interpreter import interpreter

# Data analyst profile
interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True
interpreter.system_message = """
You are an expert data analyst. When given data tasks:
1. Always start by examining the data structure
2. Use pandas and matplotlib for analysis
3. Generate visualizations when helpful
4. Explain your findings clearly
"""

# Pre-import common libraries
interpreter.computer.run("python", """
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
print("Data analysis environment ready.")
""")
# Use profile
interpreter --profile data_analyst.py

Safe Mode Configuration

from interpreter import interpreter

# Safe mode options:
# "off"  — run all code without asking (default)
# "ask"  — ask before running each code block
# "auto" — auto-sandbox in Docker container

interpreter.safe_mode = "ask"

# Docker sandbox (requires Docker installed)
interpreter.safe_mode = "auto"
# This runs all code inside an isolated Docker container

Conversation Management

from interpreter import interpreter

# Continue a conversation
interpreter.chat("Start a web scraper for news.ycombinator.com")
interpreter.chat("Now add pagination support")  # remembers context

# Access full history
print(interpreter.messages)

# Save conversation
import json
with open("session.json", "w") as f:
    json.dump(interpreter.messages, f, indent=2)

# Resume conversation from saved state
with open("session.json") as f:
    interpreter.messages = json.load(f)

interpreter.chat("Continue where we left off")

# Reset conversation
interpreter.reset()

Common Workflows

Data Analysis Automation

from interpreter import interpreter

interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True

# Analyze a CSV file end-to-end
result = interpreter.chat("""
1. Load the file sales_data.csv
2. Show me basic statistics (mean, median, std) for numeric columns
3. Find the top 10 products by revenue
4. Create a visualization of monthly sales trends
5. Save the chart as sales_trends.png
""")

File Processing Pipeline

from interpreter import interpreter

interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True

tasks = [
    "Find all PDF files in ~/Documents created in the last 30 days",
    "Extract text from each PDF and save to a .txt file with the same name",
    "Create a summary of all extracted texts in summary.md",
]

for task in tasks:
    print(f"\nTask: {task}")
    interpreter.chat(task)

Web Scraping with OI

from interpreter import interpreter

interpreter.llm.model = "gpt-4o"
interpreter.auto_run = True

interpreter.chat("""
Write and run a Python script that:
1. Fetches the top 10 Hacker News stories
2. Gets the title, URL, and score for each
3. Saves results to hn_top10.json
4. Prints a formatted table of the results
""")

System Administration

# Use interpreter for sysadmin tasks
interpreter --auto_run "Check disk usage, find the 5 largest directories, and create a report"

interpreter --auto_run "List all running processes using more than 500MB RAM and show them sorted by memory"

interpreter --auto_run "Create a daily backup script for ~/Documents and add it to cron"

Tips and Best Practices

Effective Prompting

# Be specific about desired output format
interpreter.chat("Analyze sales.csv and return results as a markdown table, not raw print statements")

# Break complex tasks into steps
interpreter.chat("""
Step 1: Parse the JSON file at data.json
Step 2: Filter records where status == 'active'
Step 3: Calculate the average age by department
Step 4: Output as CSV to results.csv
""")

# Provide context upfront
interpreter.chat("""
Context: I'm working with PostgreSQL 15 on Ubuntu.
Task: Write a backup script that dumps all databases to /backups/ with timestamps.
""")

Safety Best Practices

PracticeRecommendation
Production systemsAlways use safe_mode = "ask"
Untrusted dataUse safe_mode = "auto" (Docker sandbox)
Sensitive filesAdd to interpreter.computer.forbidden_paths
API keysNever paste keys into chat; use env vars
New tasksReview code before allowing auto_run = True
Reversible opsPrefer dry-run first; delete ops need confirmation

Performance Tips

# Reduce token usage with tighter context
interpreter.llm.max_tokens = 2048           # Limit response length
interpreter.llm.context_window = 8000       # Smaller context for faster models

# Use cheaper models for simple tasks
interpreter.llm.model = "gpt-4o-mini"       # 10x cheaper than gpt-4o

# Local models for privacy + cost
interpreter.llm.model = "ollama/llama3"     # Free, private, offline

# Disable display for scripted use (avoids overhead)
messages = interpreter.chat("task", display=False)

Supported Languages

LanguageNotes
PythonDefault; most capable
JavaScript/Node.jsFull Node.js environment
Shell/BashSystem commands
HTMLOpens in browser preview
RStatistical computing
AppleScriptmacOS automation (Mac only)
PowerShellWindows automation

Troubleshooting

# Enable verbose logging
interpreter --verbose

# Common issues:
# "Command not found" → check PATH, try `python -m interpreter`
# Timeout errors     → increase timeout in profile
# Vision not working → ensure model supports vision (gpt-4o, claude-3)
# Local model slow   → reduce context_window, use quantized model
# Safe mode issues   → install Docker for auto mode

# Reset to defaults
interpreter --reset