Skip to content
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

6591/improvement/auto-gpt/add-api #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions autogpt/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flask import Flask, request, jsonify
import subprocess
import threading

def run(instruction, callback_url):
prompt = f"Send a POST HTTP request to {callback_url}. The body of the request should be a JSON object with two keys: 1. 'status': The value of this key should be the integer 200. 2. 'response': The value of this key should be the answer in text to the following instruction: '{instruction}'. If an error occurs, the 'status' key should have the value 500 and the 'response' should have the error with the backtrace. Send the request only once and terminate immediately after sending the request."
command = f"echo '{prompt}' | python -m autogpt --continuous --continuous-limit 100 --allow-downloads --skip-news --skip-reprompt --browser-name firefox"
subprocess.run(command, shell=True)

app = Flask(__name__)

# Define a POST endpoint to execute shell commands
@app.route('/execute', methods=['POST'])
def execute_command():
payload = request.get_json()
instruction = payload.get('instruction')
callback_url = payload.get('callback_url')
try:
thread = threading.Thread(target=run, args=[instruction, callback_url])
thread.start()
return jsonify({'response': 'acknowledged'})
except subprocess.CalledProcessError as e:
return jsonify({'error': str(e.output.decode('utf-8'))}), 400

if __name__ == '__main__':
app.run(host='0.0.0.0')
27 changes: 24 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,39 @@
version: "3.9"

services:
auto-gpt:
base: &base
build:
context: ./
dockerfile: Dockerfile
depends_on:
- redis
build: ./
env_file:
- .env
environment:
MEMORY_BACKEND: ${MEMORY_BACKEND:-redis}
REDIS_HOST: ${REDIS_HOST:-redis}
volumes:
- ./:/app
- ./auto_gpt_workspace:/app/autogpt/auto_gpt_workspace
- ./data:/app/data
- ./logs:/app/logs
- ./autogpt:/app/autogpt
profiles: ["exclude-from-up"]

auto-gpt:
<<: *base
image: "auto-gpt:latest"
container_name: auto-gpt

auto-gpt-as-a-service:
<<: *base
image: "auto-gpt-as-a-service:latest"
container_name: auto-gpt-as-a-service
entrypoint: ''
command: python /app/autogpt/api.py
ports:
- "4999:5000" # Expose the API on port 4999 on the host machine
extra_hosts:
- "host.docker.internal:host-gateway"

redis:
image: "redis/redis-stack-server:latest"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ click
charset-normalizer>=3.1.0
spacy>=3.0.0,<4.0.0
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl
Flask==2.0.1

##Dev
coverage
Expand Down