OpenInterpreter / open-interpreter

A natural language interface for computers
http://openinterpreter.com/
GNU Affero General Public License v3.0
52.42k stars 4.63k forks source link

Streaming Out OpenInterpreter's Output + Trigger (Y/N) Remotely #1259

Open fire17 opened 4 months ago

fire17 commented 4 months ago

Describe the changes you have made:

This PR Adds the following Abilities:

### 1. Streaming Out all of OpenInterpreter's Output (to another UI for example)
### 2. Remotely Triggering (Y/N) Confirmation Input
        2.2 Allows to Manually Revise The Code Before Executuion
### 3. Request OI to make changes directly from the confirmation input (Y/N/Other), 
            Answers (Other than Y/N) are treated as User Messages

Reference any relevant issues:

Fixes #419 and allows Operation of OI from another GUI

Snapshots from MagicLLight which uses stream_out to get OI's output and async_input to trigger OI's (Y/N/Other) confirmation input

image Screen Shot 2024-05-08 at 22 08 01 Screen Shot 2024-04-28 at 13 43 07 Screen Shot 2024-04-29 at 20 24 03 Screen Shot 2024-04-29 at 21 15 54 Screen Shot 2024-04-29 at 23 16 53 Screen Shot 2024-04-27 at 22 08 33 MagicLLight code coming soon to a repo near you

This PR will help others Integrate and build on top of OpenInterpreter

You can stream out all the output from Open Interpreter by adding stream_output=function in an interpreter.chat() call (optional).

You can also trigger OpenInterpreter's (Y/N) Confirmation Input REMOTELY by passing async_input={"input":None, "code_revision":None} changing the dict['input'] will trigger the (Y/N) confirmation, place your answer there

Additionally, you can pass New Code to dict['code_revision'] and it will be executed instead of the last codeblock (usefull for manual editing)

## ↓ THIS FUNCTION IS CALLED ON ALL OI'S OUTPUTS
def stream_out_hook(partial, debug = False, *a, **kw):
    ''' THIS FUNCTION PROCESSES ALL THE OUTPUTS FROM OPEN INTERPRETER '''
    if debug: print("STREAMING OUT! ",partial)
    # Replace this function with one that will send the output to YOUR APPLICATION

## ↓ THIS IS OBJECT BEING WATCHED FOR TRIGGERING INPUT
async_input_data = {"input":None, "code_revision":None}
## ↑ CHANGING async_input_data["input"] WILL TRIGGER OI'S (Y/N/OTHER) CONFIRMATION INPUT

interpreter.chat(stream_out = stream_out_hook, async_input = async_input_data)

For a more comprehensive & full example, please checkout examples/stream_out.py


Pre-Submission Checklist (optional but appreciated):

OS Tests (optional but appreciated):


Made sure to make the code well documented and clean :)
Thanks a lot and all the best! 🌈

hossain666 commented 4 months ago

↓ THIS FUNCTION IS CALLED ON ALL OI'S OUTPUTS

def stream_out_hook(partial, debug = False, *a, **kw): ''' THIS FUNCTION PROCESSES ALL THE OUTPUTS FROM OPEN INTERPRETER ''' if debug: print("STREAMING OUT! ",partial)

Replace this function with one that will send the output to YOUR APPLICATION

↓ THIS IS OBJECT BEING WATCHED FOR TRIGGERING INPUT

async_input_data = {"input":None, "code_revision":None}

↑ CHANGING async_input_data["input"] WILL TRIGGER OI'S (Y/N/OTHER) CONFIRMATION INPUT

interpreter.chat(stream_out = stream_out_hook, async_input = async_input_data)

fire17 commented 4 months ago

Hi @KillianLucas :) This PR's tldr is:

  1. Adds hook to stream output (without needing to call chat() as generator)
  2. Adds Ability to Remotely Trigger (Y/N/Other) Confirmation Input() 2.2 Allows users to Manually Revise The Code Before Executuion
  3. Request OI to make changes directly from the confirmation input (Y/N/Other), added as User Message and runs llm again

Please let me know what you think about MagicLLight, and about this PR, I think it will really help others build on top of OpenInterpreter.

I currently can't publish MagicLLight with OI as a requirement until this PR is pushed, so I would love it if we could get this merged :)

Thanks a lot and all the best! 🌸

PS - would love to get an interview when possible πŸ˜‡