Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 23, 2024
2 parents 526c4fa + 5672a8e commit 5d3b121
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">● Open Interpreter</h1>

<p align="center">
<a href="https://discord.gg/6p3fD6rBVm">
<a href="https://discord.gg/Hvz9Axh84z">
<img alt="Discord" src="https://img.shields.io/discord/1146610656779440188?logo=discord&style=flat&logoColor=white"/></a>
<a href="docs/README_JA.md"><img src="https://img.shields.io/badge/ドキュメント-日本語-white.svg" alt="JA doc"/></a>
<a href="docs/README_ZH.md"><img src="https://img.shields.io/badge/文档-中文版-white.svg" alt="ZH doc"/></a>
Expand Down
128 changes: 127 additions & 1 deletion docs/code-execution/computer-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,130 @@
title: Computer API
---

Coming soon...
The following functions are designed for language models to use in Open Interpreter, currently only supported in [OS Mode](/guides/os-mode/).

### Display - View

Takes a screenshot of the primary display.

<CodeGroup>

```python Python
interpreter.computer.display.view()
```

</CodeGroup>

### Display - Center

Gets the x, y value of the center of the screen.

<CodeGroup>

```python Python
x, y = interpreter.computer.display.center()
```

</CodeGroup>

### Keyboard - Hotkey

Performs a hotkey on the computer

<CodeGroup>

```python Python
interpreter.computer.keboard.hotkey(" ", "command")
```

</CodeGroup>

### Keyboard - Write

Writes the text into the currently focused window.

<CodeGroup>

```python Python
interpreter.computer.keyboard.write("hello")
```

</CodeGroup>

### Mouse - Click

Clicks on the specified coordinates, or an icon, or text. If text is specified, OCR will be run on the screenshot to find the text coordinates and click on it.

<CodeGroup>

```python Python
# Click on coordinates
interpreter.computer.mouse.click(x=100, y=100)

# Click on text on the screen
interpreter.computer.mouse.click("Onscreen Text")

# Click on a gear icon
interpreter.computer.mouse.click(icon="gear icon")
```

</CodeGroup>

### Mouse - Move

Moves to the specified coordinates, or an icon, or text. If text is specified, OCR will be run on the screenshot to find the text coordinates and move to it.

<CodeGroup>

```python Python
# Click on coordinates
interpreter.computer.mouse.move(x=100, y=100)

# Click on text on the screen
interpreter.computer.mouse.move("Onscreen Text")

# Click on a gear icon
interpreter.computer.mouse.move(icon="gear icon")
```

</CodeGroup>

### Mouse - Scroll

Scrolls the mouse a specified number of pixels.

<CodeGroup>

```python Python
# Scroll Down
interpreter.computer.mouse.scroll(-10)

# Scroll Up
interpreter.computer.mouse.scroll(10)
```

</CodeGroup>

### Clipboard - View

Returns the contents of the clipboard.

<CodeGroup>

```python Python
interpreter.computer.clipboard.view()
```

</CodeGroup>

### OS - Get Selected Text

Get the selected text on the screen.

<CodeGroup>

```python Python
interpreter.computer.os.get_selected_text()
```

</CodeGroup>
73 changes: 72 additions & 1 deletion docs/code-execution/custom-languages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,75 @@
title: Custom Languages
---

Coming soon...
You can add or edit the programming languages that Open Interpreter's computer runs.

In this example, we'll swap out the `python` language for a version of `python` that runs in the cloud. We'll use `E2B` to do this.

([`E2B`](https://e2b.dev/) is a secure, sandboxed environment where you can run arbitrary code.)

First, [get an API key here](https://e2b.dev/), and set it:

```python
import os
os.environ["E2B_API_KEY"] = "<your_api_key_here>"
```

Then, define a custom language for Open Interpreter. The class name doesn't matter, but we'll call it `PythonE2B`:

```python
import e2b

class PythonE2B:
"""
This class contains all requirements for being a custom language in Open Interpreter:
- name (an attribute)
- run (a method)
- stop (a method)
- terminate (a method)
You can use this class to run any language you know how to run, or edit any of the official languages (which also conform to this class).
Here, we'll use E2B to power the `run` method.
"""

# This is the name that will appear to the LLM.
name = "python"

# Optionally, you can append some information about this language to the system message:
system_message = "# Follow this rule: Every Python code block MUST contain at least one print statement."

# (E2B isn't a Jupyter Notebook, so we added ^ this so it would print things,
# instead of putting variables at the end of code blocks, which is a Jupyter thing.)

def run(self, code):
"""Generator that yields a dictionary in LMC Format."""

# Run the code on E2B
stdout, stderr = e2b.run_code('Python3', code)

# Yield the output
yield {
"type": "console", "format": "output",
"content": stdout + stderr # We combined these arbitrarily. Yield anything you'd like!
}

def stop(self):
"""Stops the code."""
# Not needed here, because e2b.run_code isn't stateful.
pass

def terminate(self):
"""Terminates the entire process."""
# Not needed here, because e2b.run_code isn't stateful.
pass

# (Tip: Do this before adding/removing languages, otherwise OI might retain the state of previous languages:)
interpreter.computer.terminate()

# Give Open Interpreter its languages. This will only let it run PythonE2B:
interpreter.computer.languages = [PythonE2B]

# Try it out!
interpreter.chat("What's 349808*38490739?")
```
33 changes: 32 additions & 1 deletion docs/code-execution/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@
title: Usage
---

Coming soon...
# Running Code

The `computer` itself is separate from Open Interpreter's core, so you can run it independently:

```python
from interpreter import interpreter

interpreter.computer.run("python", "print('Hello World!')")
```

This runs in the same Python instance that interpreter uses, so you can define functions, variables, or log in to services before the AI starts running code:

```python
interpreter.computer.run("python", "import replicate\nreplicate.api_key='...'")

interpreter.custom_instructions = "Replicate has already been imported."

interpreter.chat("Please generate an image on replicate...") # Interpreter will be logged into Replicate
```

# Custom Languages

You also have control over the `computer`'s languages (like Python, Javascript, and Shell), and can easily append custom languages:

<Card
title="Custom Languages"
icon="code"
iconType="solid"
href="/code-execution/custom-languages/"
>
Add or customize the programming languages that Open Interpreter can use.
</Card>
4 changes: 2 additions & 2 deletions docs/getting-started/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: A new way to use computers

# <div class="hidden">Introduction</div>

<img src="https://openinterpreter.com/assets/ncu_thumbnail.jpg" alt="thumbnail" style={{transform: "translateY(-1.25rem)"}} />
<img src="https://openinterpreter.com/assets/banner.jpg" alt="thumbnail" style={{transform: "translateY(-1.25rem)"}} />

**Open Interpreter** lets language models run code.

Expand Down Expand Up @@ -41,4 +41,4 @@ interpreter
</Step>
</Steps>

We've also developed [one-line installers](/getting-started/setup) that install Python and set up Open Interpreter.
We've also developed [one-line installers](/getting-started/setup) that install Python and set up Open Interpreter.
8 changes: 4 additions & 4 deletions docs/language-models/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Introduction

**Open Interpreter** works with both hosted and local language models.

Hosted models are faster and far more capable, but require payment. Local models are private and free, but are often difficult to set up.
Hosted models are faster and more capable, but require payment. Local models are private and free, but are often less capable.

For this reason, we recommend starting with a **hosted** model, then switching to a local model once you've explored Open Interpreter's capabilities.

Expand All @@ -13,17 +13,17 @@ For this reason, we recommend starting with a **hosted** model, then switching t
<Card
title="Hosted setup"
icon="cloud"
href="/language-model-setup/hosted-models"
href="/language-models/hosted-models"
>
Connect to a hosted language model like GPT-4 **(recommended)**
</Card>

<Card
title="Local setup"
icon="microchip"
href="/language-model-setup/local-models"
href="/language-models/local-models"
>
Setup a local language model like Code Llama
Setup a local language model like Mistral
</Card>

</CardGroup>
Expand Down
5 changes: 4 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
{
"group": "Code Execution",
"pages": [
"code-execution/settings"
"code-execution/settings",
"code-execution/usage",
"code-execution/computer-api",
"code-execution/custom-languages"
]
},
{
Expand Down
Loading

0 comments on commit 5d3b121

Please sign in to comment.