llama-index-llms-perplexity


Namellama-index-llms-perplexity JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
Summaryllama-index llms perplexity integration
upload_time2024-11-25 21:06:22
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: Perplexity

## Installation

To install the required packages, run:

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

## Setup

### Import Libraries and Configure API Key

Import the necessary libraries and set your Perplexity API key:

```python
from llama_index.llms.perplexity import Perplexity

pplx_api_key = "your-perplexity-api-key"  # Replace with your actual API key
```

### Initialize the Perplexity LLM

Create an instance of the Perplexity LLM with your API key and desired model settings:

```python
llm = Perplexity(
    api_key=pplx_api_key, model="mistral-7b-instruct", temperature=0.5
)
```

## Chat Example

### Sending a Chat Message

You can send a chat message using the `chat` method. Here’s how to do that:

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

messages_dict = [
    {"role": "system", "content": "Be precise and concise."},
    {"role": "user", "content": "Tell me 5 sentences about Perplexity."},
]

messages = [ChatMessage(**msg) for msg in messages_dict]

# Get response from the model
response = llm.chat(messages)
print(response)
```

### Async Chat

To send messages asynchronously, you can use the `achat` method:

```python
response = await llm.achat(messages)
print(response)
```

### Stream Chat

For streaming responses, you can use the `stream_chat` method:

```python
resp = llm.stream_chat(messages)
for r in resp:
    print(r.delta, end="")
```

### Async Stream Chat

To stream responses asynchronously, use the `astream_chat` method:

```python
resp = await llm.astream_chat(messages)
async for delta in resp:
    print(delta.delta, end="")
```

### LLM Implementation example

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-llms-perplexity",
    "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/05/87/d77d7fdc0123e8f9c7efa6e273c91121c63baf9a50ec996ab274e8c3009c/llama_index_llms_perplexity-0.3.1.tar.gz",
    "platform": null,
    "description": "# LlamaIndex Llms Integration: Perplexity\n\n## Installation\n\nTo install the required packages, run:\n\n```bash\n%pip install llama-index-llms-perplexity\n!pip install llama-index\n```\n\n## Setup\n\n### Import Libraries and Configure API Key\n\nImport the necessary libraries and set your Perplexity API key:\n\n```python\nfrom llama_index.llms.perplexity import Perplexity\n\npplx_api_key = \"your-perplexity-api-key\"  # Replace with your actual API key\n```\n\n### Initialize the Perplexity LLM\n\nCreate an instance of the Perplexity LLM with your API key and desired model settings:\n\n```python\nllm = Perplexity(\n    api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5\n)\n```\n\n## Chat Example\n\n### Sending a Chat Message\n\nYou can send a chat message using the `chat` method. Here\u2019s how to do that:\n\n```python\nfrom llama_index.core.llms import ChatMessage\n\nmessages_dict = [\n    {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n    {\"role\": \"user\", \"content\": \"Tell me 5 sentences about Perplexity.\"},\n]\n\nmessages = [ChatMessage(**msg) for msg in messages_dict]\n\n# Get response from the model\nresponse = llm.chat(messages)\nprint(response)\n```\n\n### Async Chat\n\nTo send messages asynchronously, you can use the `achat` method:\n\n```python\nresponse = await llm.achat(messages)\nprint(response)\n```\n\n### Stream Chat\n\nFor streaming responses, you can use the `stream_chat` method:\n\n```python\nresp = llm.stream_chat(messages)\nfor r in resp:\n    print(r.delta, end=\"\")\n```\n\n### Async Stream Chat\n\nTo stream responses asynchronously, use the `astream_chat` method:\n\n```python\nresp = await llm.astream_chat(messages)\nasync for delta in resp:\n    print(delta.delta, end=\"\")\n```\n\n### LLM Implementation example\n\nhttps://docs.llamaindex.ai/en/stable/examples/llm/perplexity/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index llms perplexity integration",
    "version": "0.3.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dbd9781b5b13a8925bd63304bd3f362cfe22d05436a65c41c90e24b9b7d1430a",
                "md5": "41f49416932072320cf0a979b57083c1",
                "sha256": "e1d442802845358bcc76cfec6270763ccbcbd3b99a37618fed1e3044a20cbe7a"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41f49416932072320cf0a979b57083c1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 4883,
            "upload_time": "2024-11-25T21:06:20",
            "upload_time_iso_8601": "2024-11-25T21:06:20.594737Z",
            "url": "https://files.pythonhosted.org/packages/db/d9/781b5b13a8925bd63304bd3f362cfe22d05436a65c41c90e24b9b7d1430a/llama_index_llms_perplexity-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0587d77d7fdc0123e8f9c7efa6e273c91121c63baf9a50ec996ab274e8c3009c",
                "md5": "5ac551e14c20c7222d714a22225fd8e2",
                "sha256": "12d85b8533544a43734df79749582d2857b607bb2ff617f4432ecfd3759a6938"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5ac551e14c20c7222d714a22225fd8e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4401,
            "upload_time": "2024-11-25T21:06:22",
            "upload_time_iso_8601": "2024-11-25T21:06:22.145634Z",
            "url": "https://files.pythonhosted.org/packages/05/87/d77d7fdc0123e8f9c7efa6e273c91121c63baf9a50ec996ab274e8c3009c/llama_index_llms_perplexity-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-25 21:06:22",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-llms-perplexity"
}
        
Elapsed time: 0.61340s