Name | llama-index-llms-openllm JSON |
Version |
0.4.1
JSON |
| download |
home_page | None |
Summary | llama-index llms openllm integration |
upload_time | 2024-12-11 01:53:29 |
maintainer | None |
docs_url | None |
author | Aaron Pham |
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 LLM Integration: OpenLLM
## Installation
To install the required packages, run:
```bash
%pip install llama-index-llms-openllm
!pip install llama-index
```
## Setup
### Initialize OpenLLM
First, import the necessary libraries and set up your `OpenLLM` instance. Replace `my-model`, `https://hostname.com/v1`, and `na` with your model name, API base URL, and API key, respectively:
```python
import os
from typing import List, Optional
from llama_index.llms.openllm import OpenLLM
from llama_index.core.llms import ChatMessage
llm = OpenLLM(
model="my-model", api_base="https://hostname.com/v1", api_key="na"
)
```
## Generate Completions
To generate a completion, use the `complete` method:
```python
completion_response = llm.complete("To infinity, and")
print(completion_response)
```
### Stream Completions
You can also stream completions using the `stream_complete` method:
```python
async for it in llm.stream_complete(
"The meaning of time is", max_new_tokens=128
):
print(it, end="", flush=True)
```
## Chat Functionality
OpenLLM supports chat APIs, allowing you to handle conversation-like interactions. Here’s how to use it:
### Synchronous Chat
You can perform a synchronous chat by constructing a list of `ChatMessage` instances:
```python
from llama_index.core.llms import ChatMessage
chat_messages = [
ChatMessage(role="system", content="You are acting as Ernest Hemmingway."),
ChatMessage(role="user", content="Hi there!"),
ChatMessage(role="assistant", content="Yes?"),
ChatMessage(role="user", content="What is the meaning of life?"),
]
for it in llm.chat(chat_messages):
print(it.message.content, flush=True, end="")
```
### Asynchronous Chat
To perform an asynchronous chat, use the `astream_chat` method:
```python
async for it in llm.astream_chat(chat_messages):
print(it.message.content, flush=True, end="")
```
### LLM Implementation example
https://docs.llamaindex.ai/en/stable/examples/llm/openllm/
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-llms-openllm",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Aaron Pham",
"author_email": "aarnphm@bentoml.com",
"download_url": "https://files.pythonhosted.org/packages/73/d8/533fc949cc6f441fda6f09e3c491817795bd4f3fe29bed33b013c9396778/llama_index_llms_openllm-0.4.1.tar.gz",
"platform": null,
"description": "# LlamaIndex LLM Integration: OpenLLM\n\n## Installation\n\nTo install the required packages, run:\n\n```bash\n%pip install llama-index-llms-openllm\n!pip install llama-index\n```\n\n## Setup\n\n### Initialize OpenLLM\n\nFirst, import the necessary libraries and set up your `OpenLLM` instance. Replace `my-model`, `https://hostname.com/v1`, and `na` with your model name, API base URL, and API key, respectively:\n\n```python\nimport os\nfrom typing import List, Optional\nfrom llama_index.llms.openllm import OpenLLM\nfrom llama_index.core.llms import ChatMessage\n\nllm = OpenLLM(\n model=\"my-model\", api_base=\"https://hostname.com/v1\", api_key=\"na\"\n)\n```\n\n## Generate Completions\n\nTo generate a completion, use the `complete` method:\n\n```python\ncompletion_response = llm.complete(\"To infinity, and\")\nprint(completion_response)\n```\n\n### Stream Completions\n\nYou can also stream completions using the `stream_complete` method:\n\n```python\nasync for it in llm.stream_complete(\n \"The meaning of time is\", max_new_tokens=128\n):\n print(it, end=\"\", flush=True)\n```\n\n## Chat Functionality\n\nOpenLLM supports chat APIs, allowing you to handle conversation-like interactions. Here\u2019s how to use it:\n\n### Synchronous Chat\n\nYou can perform a synchronous chat by constructing a list of `ChatMessage` instances:\n\n```python\nfrom llama_index.core.llms import ChatMessage\n\nchat_messages = [\n ChatMessage(role=\"system\", content=\"You are acting as Ernest Hemmingway.\"),\n ChatMessage(role=\"user\", content=\"Hi there!\"),\n ChatMessage(role=\"assistant\", content=\"Yes?\"),\n ChatMessage(role=\"user\", content=\"What is the meaning of life?\"),\n]\n\nfor it in llm.chat(chat_messages):\n print(it.message.content, flush=True, end=\"\")\n```\n\n### Asynchronous Chat\n\nTo perform an asynchronous chat, use the `astream_chat` method:\n\n```python\nasync for it in llm.astream_chat(chat_messages):\n print(it.message.content, flush=True, end=\"\")\n```\n\n### LLM Implementation example\n\nhttps://docs.llamaindex.ai/en/stable/examples/llm/openllm/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index llms openllm integration",
"version": "0.4.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "343626cb3ec5ce3f1760a18c76c0c853eba6d39f9aa76b2a57ef37e014e1a8aa",
"md5": "aae835a2e39577bcc475ead0e3bc23bf",
"sha256": "258463f3c54852aa07f6983fdcb4b4ffd75e690ef894999097c2fc54a5b9b30b"
},
"downloads": -1,
"filename": "llama_index_llms_openllm-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aae835a2e39577bcc475ead0e3bc23bf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 2701,
"upload_time": "2024-12-11T01:53:27",
"upload_time_iso_8601": "2024-12-11T01:53:27.373194Z",
"url": "https://files.pythonhosted.org/packages/34/36/26cb3ec5ce3f1760a18c76c0c853eba6d39f9aa76b2a57ef37e014e1a8aa/llama_index_llms_openllm-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "73d8533fc949cc6f441fda6f09e3c491817795bd4f3fe29bed33b013c9396778",
"md5": "134975221b2503ad6e8ccd19bd038540",
"sha256": "76b6d20ef66f583dae4490cf9235476a356197a62f46cfc27ffff5cc12d1b8bf"
},
"downloads": -1,
"filename": "llama_index_llms_openllm-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "134975221b2503ad6e8ccd19bd038540",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 2474,
"upload_time": "2024-12-11T01:53:29",
"upload_time_iso_8601": "2024-12-11T01:53:29.574757Z",
"url": "https://files.pythonhosted.org/packages/73/d8/533fc949cc6f441fda6f09e3c491817795bd4f3fe29bed33b013c9396778/llama_index_llms_openllm-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-11 01:53:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-llms-openllm"
}