llama-index-llms-neutrino


Namellama-index-llms-neutrino JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
Summaryllama-index llms neutrino integration
upload_time2024-11-18 01:27:49
maintainerNone
docs_urlNone
authorYour Name
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LlamaIndex Llms Integration: Neutrino

## Installation

To install the required packages, run:

```bash
%pip install llama-index-llms-neutrino
!pip install llama-index
```

## Setup

### Create Neutrino API Key

You can create an API key by visiting [platform.neutrinoapp.com](https://platform.neutrinoapp.com). Once you have the API key, set it as an environment variable:

```python
import os

os.environ["NEUTRINO_API_KEY"] = "<your-neutrino-api-key>"
```

## Using Your Router

A router is a collection of LLMs that you can route queries to. You can create a router in the Neutrino dashboard or use the default router, which includes all supported models. You can treat a router as a single LLM.

### Initialize Neutrino

Create an instance of the Neutrino model:

```python
from llama_index.llms.neutrino import Neutrino

llm = Neutrino(
    # api_key="<your-neutrino-api-key>",
    # router="<your-router-id>"  # Use 'default' for the default router
)
```

### Generate Completions

To generate a text completion for a prompt, use the `complete` method:

```python
response = llm.complete("In short, a Neutrino is")
print(f"Optimal model: {response.raw['model']}")
print(response)
```

### Chat Responses

To send a chat message and receive a response, create a `ChatMessage` and use the `chat` method:

```python
from llama_index.core.llms import ChatMessage

message = ChatMessage(
    role="user",
    content="Explain the difference between statically typed and dynamically typed languages.",
)

resp = llm.chat([message])
print(f"Optimal model: {resp.raw['model']}")
print(resp)
```

### Streaming Responses

To stream responses for a chat message, use the `stream_chat` method:

```python
message = ChatMessage(
    role="user", content="What is the approximate population of Mexico?"
)

resp = llm.stream_chat([message])
for i, r in enumerate(resp):
    if i == 0:
        print(f"Optimal model: {r.raw['model']}")
    print(r.delta, end="")
```

### LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/neutrino/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-llms-neutrino",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/bb/bf/b3cd16f67842e74744292fb8d9813b1f6983ff6a75ff2006d917ed8be6d3/llama_index_llms_neutrino-0.3.0.tar.gz",
    "platform": null,
    "description": "# LlamaIndex Llms Integration: Neutrino\n\n## Installation\n\nTo install the required packages, run:\n\n```bash\n%pip install llama-index-llms-neutrino\n!pip install llama-index\n```\n\n## Setup\n\n### Create Neutrino API Key\n\nYou can create an API key by visiting [platform.neutrinoapp.com](https://platform.neutrinoapp.com). Once you have the API key, set it as an environment variable:\n\n```python\nimport os\n\nos.environ[\"NEUTRINO_API_KEY\"] = \"<your-neutrino-api-key>\"\n```\n\n## Using Your Router\n\nA router is a collection of LLMs that you can route queries to. You can create a router in the Neutrino dashboard or use the default router, which includes all supported models. You can treat a router as a single LLM.\n\n### Initialize Neutrino\n\nCreate an instance of the Neutrino model:\n\n```python\nfrom llama_index.llms.neutrino import Neutrino\n\nllm = Neutrino(\n    # api_key=\"<your-neutrino-api-key>\",\n    # router=\"<your-router-id>\"  # Use 'default' for the default router\n)\n```\n\n### Generate Completions\n\nTo generate a text completion for a prompt, use the `complete` method:\n\n```python\nresponse = llm.complete(\"In short, a Neutrino is\")\nprint(f\"Optimal model: {response.raw['model']}\")\nprint(response)\n```\n\n### Chat Responses\n\nTo send a chat message and receive a response, create a `ChatMessage` and use the `chat` method:\n\n```python\nfrom llama_index.core.llms import ChatMessage\n\nmessage = ChatMessage(\n    role=\"user\",\n    content=\"Explain the difference between statically typed and dynamically typed languages.\",\n)\n\nresp = llm.chat([message])\nprint(f\"Optimal model: {resp.raw['model']}\")\nprint(resp)\n```\n\n### Streaming Responses\n\nTo stream responses for a chat message, use the `stream_chat` method:\n\n```python\nmessage = ChatMessage(\n    role=\"user\", content=\"What is the approximate population of Mexico?\"\n)\n\nresp = llm.stream_chat([message])\nfor i, r in enumerate(resp):\n    if i == 0:\n        print(f\"Optimal model: {r.raw['model']}\")\n    print(r.delta, end=\"\")\n```\n\n### LLM Implementation example\n\nhttps://docs.llamaindex.ai/en/stable/examples/llm/neutrino/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index llms neutrino integration",
    "version": "0.3.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50e62c5b004eaed1a4184cac23ec89cb56859dbad363ed3e8c523b240f82137f",
                "md5": "fbd967bf39936b3bd146f542a6073648",
                "sha256": "d4843d5259074fcf565f3a51bea02a8bec32ae990f2b6ae71b0e0fb6b10cbf3b"
            },
            "downloads": -1,
            "filename": "llama_index_llms_neutrino-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fbd967bf39936b3bd146f542a6073648",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 3541,
            "upload_time": "2024-11-18T01:27:49",
            "upload_time_iso_8601": "2024-11-18T01:27:49.043940Z",
            "url": "https://files.pythonhosted.org/packages/50/e6/2c5b004eaed1a4184cac23ec89cb56859dbad363ed3e8c523b240f82137f/llama_index_llms_neutrino-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bbbfb3cd16f67842e74744292fb8d9813b1f6983ff6a75ff2006d917ed8be6d3",
                "md5": "38aa4d0ae499d4b79443bde45b7b53e9",
                "sha256": "4776322e595411c9f55c83fceb67722995dbf4a98adfa89437fc4ba8138bd709"
            },
            "downloads": -1,
            "filename": "llama_index_llms_neutrino-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "38aa4d0ae499d4b79443bde45b7b53e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 3113,
            "upload_time": "2024-11-18T01:27:49",
            "upload_time_iso_8601": "2024-11-18T01:27:49.882382Z",
            "url": "https://files.pythonhosted.org/packages/bb/bf/b3cd16f67842e74744292fb8d9813b1f6983ff6a75ff2006d917ed8be6d3/llama_index_llms_neutrino-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-18 01:27:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-llms-neutrino"
}
        
Elapsed time: 0.65195s