Skip to content

🐝 The First Self-Improving agents with RL / Prompting Optimization

3.4 KB
Raw Blame
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Minimal example of running GPTSwarm"
      ],
      "metadata": {
        "id": "rG3RVrQkpbV5"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import userdata\n",
        "import os\n",
        "os.environ['OPENAI_API_KEY'] = userdata.get('OPENAI_API_KEY')"
      ],
      "metadata": {
        "id": "4D0UL3Y8VbKg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WlohndxYzGy9"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/metauto-ai/GPTSwarm.git"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%cd GPTSwarm"
      ],
      "metadata": {
        "id": "XFVR_f57zian"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!rm requirements_py310_macos.txt\n",
        "!touch requirements_py310_macos.txt"
      ],
      "metadata": {
        "id": "3orsPSxPrjue"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install -r requirements_colab.txt"
      ],
      "metadata": {
        "id": "CJB6-nBq1gVL"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install -e ."
      ],
      "metadata": {
        "id": "19hZCZZdz187"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "Here we make a test run of a swarm without OpenAI calls, by using a mock backend."
      ],
      "metadata": {
        "id": "6jAJV4SAoooE"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from swarm.graph.swarm import Swarm\n",
        "\n",
        "swarm = Swarm([\"IO\", \"IO\", \"IO\"], \"gaia\", model_name='mock')\n",
        "task = \"What is the capital of Jordan?\"\n",
        "inputs = {\"task\": task}\n",
        "answer = await swarm.arun(inputs)\n",
        "answer"
      ],
      "metadata": {
        "id": "2G7WrIG334YC"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "Here we run swarm inference with ChatGPT4 backend. OPENAI_API_KEY must be specified in Colab secrets at this point."
      ],
      "metadata": {
        "id": "tZ0c1_xIo6LM"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from swarm.graph.swarm import Swarm\n",
        "\n",
        "swarm = Swarm([\"IO\", \"IO\", \"IO\"], \"gaia\")\n",
        "task = \"What is the capital of Jordan?\"\n",
        "inputs = {\"task\": task}\n",
        "answer = await swarm.arun(inputs)\n",
        "answer"
      ],
      "metadata": {
        "id": "bWIri65gQYLw"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "Fhgp-mPNWwi6"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}