Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update with instrumentation module #27

Merged
merged 27 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e969d2b
fix: update LICENSE_HEADER
sdiazlor Sep 17, 2024
1b2aa4a
feat: update with instrumentation
sdiazlor Sep 17, 2024
6a6bcba
feat: update helpers
sdiazlor Sep 17, 2024
c431cd7
feat: update init
sdiazlor Sep 17, 2024
0166acd
feat: update versions
sdiazlor Sep 17, 2024
26977fd
feat: update tests for handler
sdiazlor Sep 17, 2024
8d6dc1a
feat: add separated test for helpers and update it
sdiazlor Sep 17, 2024
d11cf63
docs: update documentation
sdiazlor Sep 17, 2024
4708a38
Update src/argilla_llama_index/llama_index_handler.py
sdiazlor Sep 18, 2024
dc84a44
Update src/argilla_llama_index/llama_index_handler.py
sdiazlor Sep 18, 2024
459d0a0
Update src/argilla_llama_index/llama_index_handler.py
sdiazlor Sep 18, 2024
ad8b954
feat: bump argilla version (for chatfield)
sdiazlor Sep 18, 2024
4f9daa3
fix: update to ArgillaHandler
sdiazlor Sep 18, 2024
ff85b22
fix: add number_of_retrievals message and update default
sdiazlor Sep 18, 2024
105faf7
feat: add independent field for scores
sdiazlor Sep 18, 2024
67cea7c
feat: add ChatField
sdiazlor Sep 20, 2024
31e4385
docs: modify images
sdiazlor Sep 20, 2024
bcdb4c3
feat: remove chat_to_html from tests
sdiazlor Sep 20, 2024
396a59f
feat: add logic to handle events
sdiazlor Oct 2, 2024
c57c330
feat: add events to tree and show in a different color
sdiazlor Oct 2, 2024
76de037
typo
sdiazlor Oct 2, 2024
1295ecf
feat: update helper tests
sdiazlor Oct 2, 2024
f7fc322
feat: update main tests
sdiazlor Oct 2, 2024
e20ef1d
docs: update previous documentation
sdiazlor Oct 2, 2024
d761540
docs: add new tutorial
sdiazlor Oct 2, 2024
aa5c466
update license header
sdiazlor Oct 2, 2024
7e98a74
docs: add initial context
sdiazlor Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions LICENSE_HEADER
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Copyright 2023-present, Argilla, Inc.
Copyright 2021-present, the Recognai S.L. team.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

sdiazlor marked this conversation as resolved.
Show resolved Hide resolved
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you already have deployed Argilla, you can skip this step. Otherwise, you can

## Basic Usage

To easily log your data into Argilla within your LlamaIndex workflow, you only need a simple step. Just call the Argilla global handler for Llama Index before starting production with your LLM.
To easily log your data into Argilla within your LlamaIndex workflow, you only need to initialize the span handler and attach it to the Llama Index dispatcher. This ensured that the predictions obtained using Llama Index are automatically logged to the Argilla instance.

- `dataset_name`: The name of the dataset. If the dataset does not exist, it will be created with the specified name. Otherwise, it will be updated.
- `api_url`: The URL to connect to the Argilla instance.
Expand All @@ -33,23 +33,23 @@ To easily log your data into Argilla within your LlamaIndex workflow, you only n
> For more information about the credentials, check the documentation for [users](https://docs.argilla.io/latest/how_to_guides/user/) and [workspaces](https://docs.argilla.io/latest/how_to_guides/workspace/).

```python
from llama_index.core import set_global_handler
import llama_index.core.instrumentation as instrument
from argilla_llama_index import ArgillaHandler

set_global_handler(
"argilla",
dataset_name="query_model",
span_handler = ArgillaHandler(
dataset_name="query_llama_index",
api_url="http://localhost:6900",
api_key="argilla.apikey",
number_of_retrievals=2,
)

dispatcher = instrument.get_dispatcher().add_span_handler(span_handler)
```

Let's log some data into Argilla. With the code below, you can create a basic LlamaIndex workflow. We will use GPT3.5 from OpenAI as our LLM ([OpenAI API key](https://openai.com/blog/openai-api)). Moreover, we will use an example `.txt` file obtained from the [Llama Index documentation](https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html).



```python
import os
import os

from llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
Expand All @@ -63,8 +63,8 @@ Settings.llm = OpenAI(
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)

# Create the query engine
query_engine = index.as_query_engine()
# Create the query engine with the same similarity top k as the number of retrievals
query_engine = index.as_query_engine(similarity_top_k=2)
```

Now, let's run the `query_engine` to have a response from the model. The generated response will be logged into Argilla.
Expand Down
Binary file modified docs/assets/UI-screenshot-github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/UI-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 27 additions & 22 deletions docs/tutorials/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"source": [
"# ✨🦙 Getting started with Argilla's LlamaIndex Integration\n",
"\n",
"In this tutorial, we will show the basic usage of this integration that allows the user to include the feedback loop that Argilla offers into the LlamaIndex ecosystem. It's based on a callback handler to be run within the LlamaIndex workflow. \n",
"In this tutorial, we will show the basic usage of this integration that allows the user to include the feedback loop that Argilla offers into the LlamaIndex ecosystem. It's based on a span handler to be run within the LlamaIndex workflow.\n",
"\n",
"Don't hesitate to check out both [LlamaIndex](https://github.com/run-llama/llama_index) and [Argilla](https://github.com/argilla-io/argilla)"
"Don't hesitate to check out both [LlamaIndex](https://github.com/run-llama/llama_index) and [Argilla](https://github.com/argilla-io/argilla)\n"
]
},
{
Expand All @@ -19,7 +19,7 @@
"\n",
"### Deploy the Argilla server¶\n",
"\n",
"If you already have deployed Argilla, you can skip this step. Otherwise, you can quickly deploy Argilla following [this guide](https://docs.argilla.io/latest/getting_started/quickstart/)."
"If you already have deployed Argilla, you can skip this step. Otherwise, you can quickly deploy Argilla following [this guide](https://docs.argilla.io/latest/getting_started/quickstart/).\n"
]
},
{
Expand All @@ -28,7 +28,7 @@
"source": [
"### Set up the environment¶\n",
"\n",
"To complete this tutorial, you need to install this integration."
"To complete this tutorial, you need to install this integration.\n"
]
},
{
Expand All @@ -37,14 +37,14 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install argilla-llama-index"
"%pip install \"argilla-llama-index>=2.1.0\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's make the required imports:"
"Let's make the required imports:\n"
]
},
{
Expand All @@ -53,20 +53,22 @@
"metadata": {},
"outputs": [],
"source": [
"import llama_index.core.instrumentation as instrument\n",
"from llama_index.core import (\n",
" Settings,\n",
" VectorStoreIndex,\n",
" SimpleDirectoryReader,\n",
" set_global_handler,\n",
")\n",
"from llama_index.llms.openai import OpenAI"
"from llama_index.llms.openai import OpenAI\n",
"\n",
"from argilla_llama_index import ArgillaHandler"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use GPT3.5 from OpenAI as our LLM. For this, you will need a valid API key from OpenAI. You can have more information and get one via [this link](https://openai.com/blog/openai-api)."
"We will use GPT3.5 from OpenAI as our LLM. For this, you will need a valid API key from OpenAI. You can have more information and get one via [this link](https://openai.com/blog/openai-api).\n"
]
},
{
Expand All @@ -87,15 +89,15 @@
"source": [
"## Set the Argilla's LlamaIndex handler\n",
"\n",
"To easily log your data into Argilla within your LlamaIndex workflow, you only need a simple step. Just call the Argilla global handler for Llama Index before starting production with your LLM. This ensured that the predictions obtained using Llama Index are automatically logged to the Argilla instance.\n",
"To easily log your data into Argilla within your LlamaIndex workflow, you only need to initialize the span handler and attach it to the Llama Index dispatcher. This ensured that the predictions obtained using Llama Index are automatically logged to the Argilla instance.\n",
"\n",
"- `dataset_name`: The name of the dataset. If the dataset does not exist, it will be created with the specified name. Otherwise, it will be updated.\n",
"- `api_url`: The URL to connect to the Argilla instance.\n",
"- `api_key`: The API key to authenticate with the Argilla instance.\n",
"- `number_of_retrievals`: The number of retrieved documents to be logged. Defaults to 0.\n",
"- `workspace_name`: The name of the workspace to log the data. By default, the first available workspace.\n",
"\n",
"> For more information about the credentials, check the documentation for [users](https://docs.argilla.io/latest/how_to_guides/user/) and [workspaces](https://docs.argilla.io/latest/how_to_guides/workspace/)."
"> For more information about the credentials, check the documentation for [users](https://docs.argilla.io/latest/how_to_guides/user/) and [workspaces](https://docs.argilla.io/latest/how_to_guides/workspace/).\n"
]
},
{
Expand All @@ -104,27 +106,28 @@
"metadata": {},
"outputs": [],
"source": [
"set_global_handler(\n",
" \"argilla\",\n",
" dataset_name=\"query_model\",\n",
"span_handler = ArgillaHandler\n",
" dataset_name=\"query_llama_index\",\n",
" api_url=\"http://localhost:6900\",\n",
" api_key=\"argilla.apikey\",\n",
" number_of_retrievals=2,\n",
")"
")\n",
"\n",
"dispatcher = instrument.get_dispatcher().add_span_handler(span_handler)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Log the data to Argilla"
"## Log the data to Argilla\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With the code below, you can create a basic LlamaIndex workflow. We will use an example `.txt` file obtained from the [Llama Index documentation](https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html)."
"With the code below, you can create a basic LlamaIndex workflow. We will use an example `.txt` file obtained from the [Llama Index documentation](https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html).\n"
]
},
{
Expand All @@ -145,21 +148,23 @@
"outputs": [],
"source": [
"# LLM settings\n",
"Settings.llm = OpenAI(model=\"gpt-3.5-turbo\", temperature=0.8, openai_api_key=openai_api_key)\n",
"Settings.llm = OpenAI(\n",
" model=\"gpt-3.5-turbo\", temperature=0.8, openai_api_key=openai_api_key\n",
")\n",
"\n",
"# Load the data and create the index\n",
"documents = SimpleDirectoryReader(\"../../data\").load_data()\n",
"index = VectorStoreIndex.from_documents(documents)\n",
"\n",
"# Create the query engine\n",
"query_engine = index.as_query_engine()"
"# Create the query engine with the same similarity top k as the number of retrievals\n",
"query_engine = index.as_query_engine(similarity_top_k=2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's run the `query_engine` to have a response from the model."
"Now, let's run the `query_engine` to have a response from the model.\n"
]
},
{
Expand All @@ -178,7 +183,7 @@
"source": [
"The prompt given and the response obtained will be logged in as a chat, as well as the indicated number of retrieved documents.\n",
"\n",
"![Argilla UI](../assets/UI-screenshot.png)"
"![Argilla UI](../assets/UI-screenshot.png)\n"
]
}
],
Expand Down
Loading