Skip to content

Commit

Permalink
Add support for llama-index v0.10+ (#581)
Browse files Browse the repository at this point in the history
* Update llamaindex.ipynb

* Update llamaindex.ipynb

* Update llamaindex
  • Loading branch information
Dominastorm authored Mar 4, 2024
1 parent 05ef74b commit 7f5066b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
68 changes: 43 additions & 25 deletions examples/integrations/llamaindex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -98,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 18,
"id": "cf7104eb",
"metadata": {},
"outputs": [],
Expand All @@ -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)"
Expand All @@ -127,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 19,
"id": "7b726c86",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -156,7 +172,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 21,
"id": "65750934",
"metadata": {},
"outputs": [],
Expand All @@ -178,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 22,
"id": "95b45738-baf4-45d0-8509-1c194f50508e",
"metadata": {
"tags": []
Expand All @@ -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()"
Expand All @@ -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",
")"
]
Expand All @@ -226,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 24,
"id": "edd8d97d-33ae-4998-9942-761a2d393a19",
"metadata": {
"tags": []
Expand All @@ -252,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 25,
"id": "d68268ce-c626-4ec7-8956-8cebf00cf919",
"metadata": {
"tags": []
Expand All @@ -278,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 26,
"id": "1bc6fbb1-a524-473b-936b-f3bc9a9fec43",
"metadata": {
"tags": []
Expand Down Expand Up @@ -535,15 +553,15 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 28,
"id": "dcbf3119",
"metadata": {},
"outputs": [],
"source": [
"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",
")"
]
Expand All @@ -560,7 +578,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 29,
"id": "7bdfd3a3",
"metadata": {},
"outputs": [],
Expand All @@ -584,7 +602,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 30,
"id": "815243c7",
"metadata": {},
"outputs": [
Expand All @@ -609,7 +627,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 31,
"id": "23976958",
"metadata": {},
"outputs": [
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
Expand Down

0 comments on commit 7f5066b

Please sign in to comment.