llama-index-llms-perplexity


Namellama-index-llms-perplexity JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
Summaryllama-index llms perplexity integration
upload_time2024-10-08 22:36:18
maintainerNone
docs_urlNone
authorYour Name
requires_python<4.0,>=3.8.1
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.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/e3/50/e1edb51f6e13dbca30c4e8b99a370c1ec809d871ed642227353386da9f39/llama_index_llms_perplexity-0.2.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.2.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22b00e657f943a8218361b869c72eee1cc48ccbadcd1e9f5c311749a72c4e5bb",
                "md5": "46b2926779fb5f4ce7a94611f54c186f",
                "sha256": "9b7037a76bef9439bf5d9f12f026ce8c1510b09392529eca6688ed762630dda5"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "46b2926779fb5f4ce7a94611f54c186f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8.1",
            "size": 5153,
            "upload_time": "2024-10-08T22:36:16",
            "upload_time_iso_8601": "2024-10-08T22:36:16.661570Z",
            "url": "https://files.pythonhosted.org/packages/22/b0/0e657f943a8218361b869c72eee1cc48ccbadcd1e9f5c311749a72c4e5bb/llama_index_llms_perplexity-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e350e1edb51f6e13dbca30c4e8b99a370c1ec809d871ed642227353386da9f39",
                "md5": "4b6c4faac29d15e847bba4495adb9c3b",
                "sha256": "ffc81b462468cbdc58515c9299c78ee050adb6d7d888889a58a51dbbe7fbccf1"
            },
            "downloads": -1,
            "filename": "llama_index_llms_perplexity-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4b6c4faac29d15e847bba4495adb9c3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8.1",
            "size": 4697,
            "upload_time": "2024-10-08T22:36:18",
            "upload_time_iso_8601": "2024-10-08T22:36:18.364538Z",
            "url": "https://files.pythonhosted.org/packages/e3/50/e1edb51f6e13dbca30c4e8b99a370c1ec809d871ed642227353386da9f39/llama_index_llms_perplexity-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-08 22:36:18",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-llms-perplexity"
}
        
Elapsed time: 0.36669s