Name | llama-index-llms-neutrino JSON |
Version |
0.3.1
JSON |
| download |
home_page | None |
Summary | llama-index llms neutrino integration |
upload_time | 2024-12-11 01:28:15 |
maintainer | None |
docs_url | None |
author | Your Name |
requires_python | <4.0,>=3.9 |
license | MIT |
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/f7/40/4491b356f421a581690bc0f00daaf190298a03f562379f865eb6675373a6/llama_index_llms_neutrino-0.3.1.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.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "01998129a677284af088c73377677bc987a152660eb4330945a73d77c179a273",
"md5": "378e6549a495eae9fe39d287ff53342f",
"sha256": "b5b2c669e59bd98bf22a3cd2faac73ef83ce69458f01755b8d093da95cc0a0f8"
},
"downloads": -1,
"filename": "llama_index_llms_neutrino-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "378e6549a495eae9fe39d287ff53342f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 3543,
"upload_time": "2024-12-11T01:28:14",
"upload_time_iso_8601": "2024-12-11T01:28:14.472155Z",
"url": "https://files.pythonhosted.org/packages/01/99/8129a677284af088c73377677bc987a152660eb4330945a73d77c179a273/llama_index_llms_neutrino-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f7404491b356f421a581690bc0f00daaf190298a03f562379f865eb6675373a6",
"md5": "e707793c618cc5b5cb9dcdbffb8b545b",
"sha256": "25a680320511a228e14a38fec40a7bf3fb0c58100644d8c932719a9d41da6ca7"
},
"downloads": -1,
"filename": "llama_index_llms_neutrino-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "e707793c618cc5b5cb9dcdbffb8b545b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3042,
"upload_time": "2024-12-11T01:28:15",
"upload_time_iso_8601": "2024-12-11T01:28:15.435756Z",
"url": "https://files.pythonhosted.org/packages/f7/40/4491b356f421a581690bc0f00daaf190298a03f562379f865eb6675373a6/llama_index_llms_neutrino-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-11 01:28:15",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-llms-neutrino"
}