diff --git a/notebooks/tutorials/adalflow_rag_optimization.ipynb b/notebooks/tutorials/adalflow_rag_optimization.ipynb index a0f00d6e..b9365680 100644 --- a/notebooks/tutorials/adalflow_rag_optimization.ipynb +++ b/notebooks/tutorials/adalflow_rag_optimization.ipynb @@ -5,6 +5,9 @@ "metadata": { "id": "xHF95Kr4CzGq" }, + "metadata": { + "id": "xHF95Kr4CzGq" + }, "source": [ "# 馃 Welcome to AdalFlow!\n", "## The PyTorch library to auto-optimize any LLM task pipelines\n", @@ -34,6 +37,7 @@ "\n", "- Learn how to connect the output-input between components to enable auto-text-grad optimization." ] + ] }, "id": "ONfzF9Puzdd_", "outputId": "5fc0cd30-9ae7-443a-c06c-31e9edeafd69" @@ -46,6 +50,9 @@ "metadata": { "id": "Kof5M6DRaKhh" }, + "metadata": { + "id": "Kof5M6DRaKhh" + }, "source": [ "\n", "# Installation\n", @@ -59,6 +66,7 @@ "\n", "You can choose to use different client. You can import the model client you prefer. We support `Anthropic`, `Cohere`, `Google`, `GROQ`, `OpenAI`, `Transformer` and more in development. We will use OpenAI here as an example.Please refer to our [full installation guide](https://adalflow.sylph.ai/get_started/installation.html)" ] + ] }, { "cell_type": "code", @@ -76,6 +84,9 @@ "!pip uninstall httpx anyio -y\n", "!pip install \"anyio>=3.1.0,<4.0\"\n", "!pip install httpx==0.24.1\n", + "!pip uninstall httpx anyio -y\n", + "!pip install \"anyio>=3.1.0,<4.0\"\n", + "!pip install httpx==0.24.1\n", "clear_output()" ] }, @@ -84,6 +95,9 @@ "metadata": { "id": "KapUyHMM07pJ" }, + "metadata": { + "id": "KapUyHMM07pJ" + }, "source": [ "## Set Environment Variables\n", "\n", @@ -93,6 +107,7 @@ "\n", "*Go to [OpenAI](https://platform.openai.com/docs/introduction) to get API keys if you don't already have.*" ] + ] }, { "cell_type": "code", @@ -114,6 +129,24 @@ ] } ], + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ONfzF9Puzdd_", + "outputId": "5fc0cd30-9ae7-443a-c06c-31e9edeafd69" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter your OpenAI API key: 路路路路路路路路路路\n", + "API keys have been set.\n" + ] + } + ], "source": [ "import os\n", "\n", @@ -136,6 +169,11 @@ "id": "aE3I05BqOmd7" }, "outputs": [], + "execution_count": 20, + "metadata": { + "id": "aE3I05BqOmd7" + }, + "outputs": [], "source": [ "import dspy\n", "import re\n", @@ -151,6 +189,7 @@ "from adalflow.core.component import fun_to_component\n", "from adalflow.components.model_client.openai_client import OpenAIClient" ] + ] }, { "cell_type": "code", @@ -159,6 +198,11 @@ "id": "cqUUoua9fUxQ" }, "outputs": [], + "execution_count": null, + "metadata": { + "id": "cqUUoua9fUxQ" + }, + "outputs": [], "source": [ "\n", "gpt_4o_model = {\n", @@ -177,6 +221,7 @@ " },\n", "}" ] + ] }, { "cell_type": "code", @@ -207,6 +252,33 @@ "output_type": "execute_result" } ], + "execution_count": 22, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0irHeHUkOmL8", + "outputId": "61f778a2-9ec1-4fda-daa2-bcc7f31baa78" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HotPotQAData(id='5a8b57f25542995d1e6f1371', question='Were Scott Derrickson and Ed Wood of the same nationality?', answer='yes', gold_titles=\"{'Scott Derrickson', 'Ed Wood'}\") \n" + ] + }, + { + "data": { + "text/plain": [ + "HotPotQAData(id='5a8b57f25542995d1e6f1371', question='Were Scott Derrickson and Ed Wood of the same nationality?', answer='yes', gold_titles=\"{'Scott Derrickson', 'Ed Wood'}\")" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def load_datasets():\n", "\n", @@ -242,6 +314,11 @@ "id": "ZZIEtZYHNVjo" }, "outputs": [], + "execution_count": 23, + "metadata": { + "id": "ZZIEtZYHNVjo" + }, + "outputs": [], "source": [ "class DspyRetriever(adal.Retriever):\n", " def __init__(self, top_k: int = 3):\n",