llama-index-callbacks-argilla


Namellama-index-callbacks-argilla JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
Summaryllama-index callbacks argilla integration
upload_time2024-08-22 03:45:08
maintainerNone
docs_urlNone
authorYour Name
requires_python<3.12,>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <h1>✨🦙 Argilla's LlamaIndex Integration</h1>
  <p><em> Argilla integration into the LlamaIndex workflow</em></p>
</div>

> [!TIP]
> To discuss, get support, or give feedback [join Argilla's Slack Community](https://join.slack.com/t/rubrixworkspace/shared_invite/zt-whigkyjn-a3IUJLD7gDbTZ0rKlvcJ5g) and you will be able to engage with our amazing community and also with the core developers of `argilla` and `distilabel`.

This integration 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.

Don't hesitate to check out both [LlamaIndex](https://github.com/run-llama/llama_index) and [Argilla](https://github.com/argilla-io/argilla)

## Getting Started

You first need to install argilla and argilla-llama-index as follows:

```bash
pip install llama-index-callbacks-argilla
```

You will need to an Argilla Server running to monitor the LLM. You can either install the server locally or have it on HuggingFace Spaces. For a complete guide on how to install and initialize the server, you can refer to the [Quickstart Guide](https://docs.argilla.io/en/latest/getting_started/quickstart_installation.html).

## Usage

It requires just a simple step to log your data into Argilla within your LlamaIndex workflow. We just need to call the handler before starting production with your LLM.

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 info and get one via [this link](https://openai.com/blog/openai-api).

After you get your API key, the easiest way to import it is through an environment variable, or via _getpass()_.

```python
import os
from getpass import getpass

openai_api_key = os.getenv("OPENAI_API_KEY", None) or getpass(
    "Enter OpenAI API key:"
)
```

Let's now write all the necessary imports

```python
from llama_index.core import (
    VectorStoreIndex,
    SimpleDirectoryReader,
    set_global_handler,
)
from llama_index.llms.openai import OpenAI
```

What we need to do is to set Argilla as the global handler as below. Within the handler, we need to provide the dataset name that we will use. If the dataset does not exist, it will be created with the given name. You can also set the API KEY, API URL, and the Workspace name. You can learn more about the variables that controls Argilla initialization [here](https://docs.argilla.io/en/latest/getting_started/installation/configurations/workspace_management.html)

> [!TIP]
> Remember that the default Argilla workspace name is `admin`. If you want to use a custom Workspace, you'll need to create it and grant access to the desired users. The link above also explains how to do that.

```python
set_global_handler("argilla", dataset_name="query_model")
```

Let's now create the llm instance, using GPT-3.5 from OpenAI.

```python
llm = OpenAI(
    model="gpt-3.5-turbo", temperature=0.8, openai_api_key=openai_api_key
)
```

With the code snippet below, you can create a basic workflow with LlamaIndex. You will also need a txt file as the data source within a folder named "data". For a sample data file and more info regarding the use of Llama Index, you can refer to the [Llama Index documentation](https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html).

```python
docs = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(docs)
query_engine = index.as_query_engine()
```

Now, let's run the `query_engine` to have a response from the model.

```python
response = query_engine.query("What did the author do growing up?")
response
```

```bash
The author worked on two main things outside of school before college: writing and programming. They wrote short stories and tried writing programs on an IBM 1401. They later got a microcomputer, built it themselves, and started programming on it.
```

The prompt given and the response obtained will be logged in to Argilla server.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-callbacks-argilla",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.12,>=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/f0/92/341e2f0fc63471fe36a00acce4ea3fc3e63da7636df194d92209765252be/llama_index_callbacks_argilla-0.2.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <h1>\u2728\ud83e\udd99 Argilla's LlamaIndex Integration</h1>\n  <p><em> Argilla integration into the LlamaIndex workflow</em></p>\n</div>\n\n> [!TIP]\n> To discuss, get support, or give feedback [join Argilla's Slack Community](https://join.slack.com/t/rubrixworkspace/shared_invite/zt-whigkyjn-a3IUJLD7gDbTZ0rKlvcJ5g) and you will be able to engage with our amazing community and also with the core developers of `argilla` and `distilabel`.\n\nThis integration 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\nDon't hesitate to check out both [LlamaIndex](https://github.com/run-llama/llama_index) and [Argilla](https://github.com/argilla-io/argilla)\n\n## Getting Started\n\nYou first need to install argilla and argilla-llama-index as follows:\n\n```bash\npip install llama-index-callbacks-argilla\n```\n\nYou will need to an Argilla Server running to monitor the LLM. You can either install the server locally or have it on HuggingFace Spaces. For a complete guide on how to install and initialize the server, you can refer to the [Quickstart Guide](https://docs.argilla.io/en/latest/getting_started/quickstart_installation.html).\n\n## Usage\n\nIt requires just a simple step to log your data into Argilla within your LlamaIndex workflow. We just need to call the handler before starting production with your LLM.\n\nWe will use GPT3.5 from OpenAI as our LLM. For this, you will need a valid API key from OpenAI. You can have more info and get one via [this link](https://openai.com/blog/openai-api).\n\nAfter you get your API key, the easiest way to import it is through an environment variable, or via _getpass()_.\n\n```python\nimport os\nfrom getpass import getpass\n\nopenai_api_key = os.getenv(\"OPENAI_API_KEY\", None) or getpass(\n    \"Enter OpenAI API key:\"\n)\n```\n\nLet's now write all the necessary imports\n\n```python\nfrom llama_index.core import (\n    VectorStoreIndex,\n    SimpleDirectoryReader,\n    set_global_handler,\n)\nfrom llama_index.llms.openai import OpenAI\n```\n\nWhat we need to do is to set Argilla as the global handler as below. Within the handler, we need to provide the dataset name that we will use. If the dataset does not exist, it will be created with the given name. You can also set the API KEY, API URL, and the Workspace name. You can learn more about the variables that controls Argilla initialization [here](https://docs.argilla.io/en/latest/getting_started/installation/configurations/workspace_management.html)\n\n> [!TIP]\n> Remember that the default Argilla workspace name is `admin`. If you want to use a custom Workspace, you'll need to create it and grant access to the desired users. The link above also explains how to do that.\n\n```python\nset_global_handler(\"argilla\", dataset_name=\"query_model\")\n```\n\nLet's now create the llm instance, using GPT-3.5 from OpenAI.\n\n```python\nllm = OpenAI(\n    model=\"gpt-3.5-turbo\", temperature=0.8, openai_api_key=openai_api_key\n)\n```\n\nWith the code snippet below, you can create a basic workflow with LlamaIndex. You will also need a txt file as the data source within a folder named \"data\". For a sample data file and more info regarding the use of Llama Index, you can refer to the [Llama Index documentation](https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html).\n\n```python\ndocs = SimpleDirectoryReader(\"data\").load_data()\nindex = VectorStoreIndex.from_documents(docs)\nquery_engine = index.as_query_engine()\n```\n\nNow, let's run the `query_engine` to have a response from the model.\n\n```python\nresponse = query_engine.query(\"What did the author do growing up?\")\nresponse\n```\n\n```bash\nThe author worked on two main things outside of school before college: writing and programming. They wrote short stories and tried writing programs on an IBM 1401. They later got a microcomputer, built it themselves, and started programming on it.\n```\n\nThe prompt given and the response obtained will be logged in to Argilla server.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index callbacks argilla integration",
    "version": "0.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "116b43ac8dd0b61b634305a4471b53116097d9ad5444695afb4b1c28cf65fa93",
                "md5": "c367aa994cf580255ba4f911b22ac1ea",
                "sha256": "2752151d85b6a59bdb1aaf058b546e81ef6403dfcfa74383bdbaa97c5cfac9ec"
            },
            "downloads": -1,
            "filename": "llama_index_callbacks_argilla-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c367aa994cf580255ba4f911b22ac1ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.8.1",
            "size": 3619,
            "upload_time": "2024-08-22T03:45:07",
            "upload_time_iso_8601": "2024-08-22T03:45:07.174092Z",
            "url": "https://files.pythonhosted.org/packages/11/6b/43ac8dd0b61b634305a4471b53116097d9ad5444695afb4b1c28cf65fa93/llama_index_callbacks_argilla-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f092341e2f0fc63471fe36a00acce4ea3fc3e63da7636df194d92209765252be",
                "md5": "a2ae181b93fc3b837aa7214ba45c31d5",
                "sha256": "8db164df931739ad29cb337beb86921f8e629a0bfe4f1af96a2a88481e3c746d"
            },
            "downloads": -1,
            "filename": "llama_index_callbacks_argilla-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a2ae181b93fc3b837aa7214ba45c31d5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.8.1",
            "size": 3402,
            "upload_time": "2024-08-22T03:45:08",
            "upload_time_iso_8601": "2024-08-22T03:45:08.451779Z",
            "url": "https://files.pythonhosted.org/packages/f0/92/341e2f0fc63471fe36a00acce4ea3fc3e63da7636df194d92209765252be/llama_index_callbacks_argilla-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 03:45:08",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-callbacks-argilla"
}
        
Elapsed time: 0.58174s