From 7f5066b245d20f2ba4b58df1dfca0edfe5e08010 Mon Sep 17 00:00:00 2001 From: Dhruv Chawla <43818888+Dominastorm@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:13:59 +0530 Subject: [PATCH] Add support for llama-index v0.10+ (#581) * Update llamaindex.ipynb * Update llamaindex.ipynb * Update llamaindex --- examples/integrations/llamaindex.ipynb | 68 ++++++++++++++++---------- pyproject.toml | 2 +- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/examples/integrations/llamaindex.ipynb b/examples/integrations/llamaindex.ipynb index b7499dbb2..147ebee06 100644 --- a/examples/integrations/llamaindex.ipynb +++ b/examples/integrations/llamaindex.ipynb @@ -57,12 +57,28 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Install UpTrain and LlamaIndex\n", - "\n", - "\n", - "```bash\n", - "pip install uptrain llama_index\n", - "```" + "## Install UpTrain and LlamaIndex" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "276331d6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install -q uptrain llama-index" ] }, { @@ -74,16 +90,17 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ + "import httpx\n", "import os\n", "import openai \n", "import pandas as pd\n", "\n", - "from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n", - "from uptrain import Evals, EvalLlamaIndex, Settings" + "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings\n", + "from uptrain import Evals, EvalLlamaIndex, Settings as UpTrainSettings" ] }, { @@ -98,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 18, "id": "cf7104eb", "metadata": {}, "outputs": [], @@ -109,7 +126,6 @@ "dataset_path = os.path.join('./nyc_wikipedia', \"nyc_text.txt\")\n", "\n", "if not os.path.exists(dataset_path):\n", - " import httpx\n", " r = httpx.get(url)\n", " with open(dataset_path, \"wb\") as f:\n", " f.write(r.content)" @@ -127,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 19, "id": "7b726c86", "metadata": {}, "outputs": [], @@ -156,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 21, "id": "65750934", "metadata": {}, "outputs": [], @@ -178,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 22, "id": "95b45738-baf4-45d0-8509-1c194f50508e", "metadata": { "tags": [] @@ -187,8 +203,10 @@ "source": [ "documents = SimpleDirectoryReader(\"./nyc_wikipedia/\").load_data()\n", "\n", + "Settings.chunk_size = 512\n", + "\n", "vector_index = VectorStoreIndex.from_documents(\n", - " documents, service_context=ServiceContext.from_defaults(chunk_size=512)\n", + " documents,\n", ")\n", "\n", "query_engine = vector_index.as_query_engine()" @@ -204,12 +222,12 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 23, "id": "da17993b", "metadata": {}, "outputs": [], "source": [ - "settings = Settings(\n", + "settings = UpTrainSettings(\n", " openai_api_key=openai.api_key,\n", ")" ] @@ -226,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 24, "id": "edd8d97d-33ae-4998-9942-761a2d393a19", "metadata": { "tags": [] @@ -252,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 25, "id": "d68268ce-c626-4ec7-8956-8cebf00cf919", "metadata": { "tags": [] @@ -278,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 26, "id": "1bc6fbb1-a524-473b-936b-f3bc9a9fec43", "metadata": { "tags": [] @@ -535,7 +553,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 28, "id": "dcbf3119", "metadata": {}, "outputs": [], @@ -543,7 +561,7 @@ "UPTRAIN_API_KEY = 'up-**********************' # your UpTrain API key\n", "\n", "# We use `uptrain_access_token` parameter instead of 'openai_api_key' in settings in this case\n", - "settings = Settings(\n", + "settings = UpTrainSettings(\n", " uptrain_access_token=UPTRAIN_API_KEY,\n", ")" ] @@ -560,7 +578,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 29, "id": "7bdfd3a3", "metadata": {}, "outputs": [], @@ -584,7 +602,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 30, "id": "815243c7", "metadata": {}, "outputs": [ @@ -609,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 31, "id": "23976958", "metadata": {}, "outputs": [ diff --git a/pyproject.toml b/pyproject.toml index 9ddb34b09..0ff78c93e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"] [project] name = "uptrain" -version = "0.6.5.post2" +version = "0.6.6" description = "UpTrain - tool to evaluate LLM applications on aspects like factual accuracy, response quality, retrieval quality, tonality, etc." readme = "README.md" maintainers = [{ name = "UpTrain AI Team", email = "oss@uptrain.ai" }]