JARVIS: Collaborative AI System

repository·main·Indexed 12 days ago

https://github.com/microsoft/jarvis

A collaborative AI system that uses a Large Language Model (LLM) as a controller to orchestrate expert models from the Hugging Face Hub. JARVIS solves complex tasks through a four-stage workflow: task planning, model selection, task execution, and response generation. It includes support for various inference modes (local, huggingface, hybrid), a web API, a Gradio demo, and integration with benchmarks like ToolBench, FuncQA, RestBench, and TaskBench.

Tokens
7.2K
Snippets
25
Records
32
Agent score
98%

What's inside JARVIS

  1. Introduction to TaskBench

    main

    TaskBench is a benchmark designed to evaluate the task automation capabilities of Large Language Models (LLMs). It focuses on three critical stages of automation:

    1. Task Decomposition: Breaking down a user intent into discrete steps.
    2. Tool Invocation: Identifying the correct tools and their dependencies (nodes and edges).
    3. Parameter Prediction: Predicting the correct types and values for tool parameters.

    The benchmark uses a Tool Graph concept to represent tasks, where nodes are tools and edges represent resource or temporal dependencies. Task structures are sampled in three ways: node, chain, and DAGs (Directed Acyclic Graphs).

  2. Overview of JARVIS

    main
    JARVIS is a research project focused on exploring Artificial General Intelligence (AGI) and delivering cutting-edge research to the community. It is associated with the research paper available on arXiv.
  3. How JARVIS works: LLM as Controller and Expert Models as Executors

    main

    JARVIS is a collaborative system that uses a Large Language Model (LLM) as a controller to solve complex AI tasks by orchestrating numerous expert models (from HuggingFace Hub) as collaborative executors.

    The workflow follows four stages:

    1. Task Planning: The LLM analyzes user requests to understand intention and disassembles them into solvable tasks.
    2. Model Selection: The LLM selects specific expert models hosted on Hugging Face based on their descriptions.
    3. Task Execution: The system invokes and executes the selected models and returns results to the LLM.
    4. Response Generation: The LLM integrates all model predictions to generate a final response to the user.
  4. TaskBench Dataset Structure

    main

    The TaskBench dataset is organized into three domains: HuggingFace Tools, Multimedia Tools, and Daily Life APIs. Each domain directory contains the following four files:

    • data.json: The main dataset file containing samples.
    • graph_desc.json: The tool graph description file.
    • user_requests.json: Contains the user requests.
    • tool_desc.json: Contains the tool descriptions.
  5. Define tool library formats for custom datasets

    main

    To build a custom tool library for TaskBench, you must create a JSON file containing tool descriptions. TaskBench supports two distinct formats depending on the tool type:

    1. Type-specific parameters: Used for tools like image processors. These define input-type and output-type arrays.
    2. API with request parameters: Used for functional APIs. These define a parameters array where each object specifies a name, type, and desc.

    Use the appropriate format to ensure the correct dependency graph is generated later.

    // Tool with type-specific parameters
    {
      "id": "Image-to-Image",
      "desc": "Image-to-image is the task of transforming a source image...",
      "input-type": ["image"],
      "output-type": ["image"]
    }
    
    // API with request parameters
    {
      "id": "send_sms",
      "desc": "Send an sms to a specific phone number",
      "parameters": [
        {
          "name": "phone_number",
          "type": "string",
          "desc": "The phone number to send the sms to"
        },
        {
          "name": "content",
          "type": "string",
          "desc": "The content of the sms"
        }
      ]
    }
  6. Run ToolBench inference

    main

    To run inference on the ToolBench dataset, follow these steps:

    1. Download Tool Execution Code: Obtain the tool execution code (./data/toolenv/tools.) from the provided Google Drive or Tsinghua Cloud and save it to ./toolenv/tools.
    2. Unzip Embeddings: Unzip the API description embeddings into the data directory:
      unzip data_toolbench/tool_instruction/API_description_embeddings.zip -d data_toolbench/tool_instruction/
    3. **Execute Inference**: Use `main.py` with the appropriate `--task` and `--data_type` flags. Ensure `OPENAI_API_KEY` and `RAPIDAPI_KEY` are exported.
    
    **Available Tasks and Data Types:**
    - `--task toolbench` with `--data_type G2` or `G3`
    - `--task toolbench_retrieve` with `--data_type G2` or `G3`
    
    **Required Flags:**
    - `--model_name`: The LLM to use (e.g., `gpt-3.5-turbo`).
    - `--task`: The specific ToolBench task.
    - `--data_type`: The data type variant (`G2` or `G3`).
    - `--tool_root_dir`: Path to the tool environment (e.g., `./toolenv/tools`).
    
    ```bash
    unzip data_toolbench/tool_instruction/API_description_embeddings.zip -d data_toolbench/tool_instruction/
    
    export OPENAI_API_KEY="your_key"
    export RAPIDAPI_KEY="your_key"
    
    python3 main.py \
      --model_name gpt-3.5-turbo \
      --task toolbench \
      --data_type G2 \
      --tool_root_dir ./toolenv/tools
  7. Run JARVIS via Gradio Demo

    main

    You can run the Gradio demo locally using the provided configuration files, or run it as a Docker image (requires inference_mode=hybrid and local_deployment=standard).

    # Local Gradio
    python models_server.py --config configs/config.gradio.yaml
    python run_gradio_demo.py --config configs/config.gradio.yaml
    
    # Docker Gradio
    docker run -it -p 7860:7860 --platform=linux/amd64 registry.hf.space/microsoft-hugginggpt:latest python app.py
  8. Format generated data with format_data.py

    main

    After generating the dataset with data_engine.py, run format_data.py to prepare the data for use. You must specify the --data_dir and the --dependency_type used during generation.

    python format_data.py \
        --data_dir data_multimedia \
        --dependency_type resource
  9. Deploy JARVIS on NVIDIA Jetson

    main

    Experimental support for NVIDIA Jetson embedded devices is provided via a Dockerfile. It is recommended to use Jetson AGX Orin family devices (64G RAM preferred).

    Setup Requirements

    • Set the default docker runtime to nvidia.
    • Use inference_mode: local and local_deployment: standard.
    • Mount models and configs from the host to the container via volumes.

    Deployment Steps

    1. Build the image.
    2. Run the container (automatically starts the model server).
    3. Start the chat interface via docker exec.
    4. Start the web application via docker exec.
    # Build the docker image
    docker build --pull --rm -f "Dockerfile.jetson" -t toolboc/nv-jarvis:r35.2.1 
    
    # Run the container
    docker run --name jarvis --net=host --gpus all -v ~/jarvis/configs:/app/server/configs -v ~/src/JARVIS/server/models:/app/server/models toolboc/nv-jarvis:r35.2.1
    
    # Start awesome_chat.py
    docker exec jarvis python3 awesome_chat.py --config configs/config.default.yaml --mode server
    
    # Start the web application
    docker exec jarvis npm run dev --prefix=/app/web
  10. Run the JARVIS Web Client

    main

    The web client provides a user-friendly interface. After starting awesome_chat.py in server mode, follow these steps:

    1. Install nodejs and npm.
    2. Configuration: If running the web client on a different machine than the server, set HUGGINGGPT_BASE_URL to http://{LAN_IP_of_the_server}:{port}/ in web/src/config/index.ts.
    3. Video Support: To use video generation, you must manually compile ffmpeg with H.264 support.

    Installation and Launch

    cd web
    npm install
    npm run dev