llama-index-llms-perplexity


Namellama-index-llms-perplexity JSON
Version 0.3.2 PyPI version JSON
download
home_pageNone
Summaryllama-index llms perplexity integration
upload_time2024-12-07 05:51:59
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/d7/aa/ea1ae54334adde8c52faf2702ea60b65b02d38169d7eaa42a8868e5af3e1/llama_index_llms_perplexity-0.3.2.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.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d7ac9847fdde2f69ed4e747e6d051ff08c8f50191052b3fd3179be345bc7b49",
                "md5": "36b8ea0fb6e3a9854fa01f3a3519fe7c",
                "sha256": "01bdfe5d9ef125974573cc848fea98365861e769784976592d1c9bb211e6a68b"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "36b8ea0fb6e3a9854fa01f3a3519fe7c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 4893,
            "upload_time": "2024-12-07T05:51:58",
            "upload_time_iso_8601": "2024-12-07T05:51:58.429679Z",
            "url": "https://files.pythonhosted.org/packages/9d/7a/c9847fdde2f69ed4e747e6d051ff08c8f50191052b3fd3179be345bc7b49/llama_index_llms_perplexity-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d7aaea1ae54334adde8c52faf2702ea60b65b02d38169d7eaa42a8868e5af3e1",
                "md5": "765f0b6161d32cd24e057efe97988dd7",
                "sha256": "37f4702cc40b4218f2c10f44d9fd3dea0c711f6e16ac0d8f87c6363e1ed555e2"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "765f0b6161d32cd24e057efe97988dd7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4415,
            "upload_time": "2024-12-07T05:51:59",
            "upload_time_iso_8601": "2024-12-07T05:51:59.328294Z",
            "url": "https://files.pythonhosted.org/packages/d7/aa/ea1ae54334adde8c52faf2702ea60b65b02d38169d7eaa42a8868e5af3e1/llama_index_llms_perplexity-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-07 05:51:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-llms-perplexity"
}
        
Elapsed time: 0.80394s