Repository: langchain
Issue: ChatPerplexity: 'str' object has no attribute 'choices'
Labels: 🤖:bug

### Checked other resources

- [x] I added a very descriptive title to this issue.
- [x] I searched the LangChain documentation with the integrated search.
- [x] I used the GitHub search to find a similar question and didn't find it.
- [x] I am sure that this is a bug in LangChain rather than my code.
- [x] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

### Example Code

```python
from langchain_community.chat_models import ChatPerplexity
research_model = ChatPerplexity(
        model="llama-3.1-sonar-large-128k-online",
        temperature=0,
        # to not emit messages to the client
        disable_streaming=True,
    )

research_prompt = 'How many starts are there?'
research_response = research_model.invoke([HumanMessage(content=research_prompt)])
```

### Error Message and Stack Trace (if applicable)

AttributeError("'str' object has no attribute 'choices'")Traceback (most recent call last):


  File "/Users/nsviridenko/.local/share/virtualenvs/nce-agent-dIPyehe6/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 633, in generate
    self._generate_with_cache(


  File "/Users/nsviridenko/.local/share/virtualenvs/nce-agent-dIPyehe6/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 851, in _generate_with_cache
    result = self._generate(
             ^^^^^^^^^^^^^^^


  File "/Users/nsviridenko/.local/share/virtualenvs/nce-agent-dIPyehe6/lib/python3.11/site-packages/langchain_community/chat_models/perplexity.py", line 265, in _generate
    content=response.choices[0].message.content,
            ^^^^^^^^^^^^^^^^


AttributeError: 'str' object has no attribute 'choices'

### Description

When trying to use ChatPerplexity, it throws an error.

### System Info




System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 20.6.0: Tue Jun 21 20:50:28 PDT 2022; root:xnu-7195.141.32~1/RELEASE_X86_64
> Python Version:  3.11.5 (main, Sep 29 2024, 15:09:05) [Clang 12.0.5 (clang-1205.0.22.11)]

Package Information
-------------------
> langchain_core: 0.3.21
> langchain: 0.3.9
> langchain_community: 0.3.9
> langsmith: 0.1.147
> langchain_anthropic: 0.3.0
> langchain_openai: 0.2.10
> langchain_text_splitters: 0.3.2
> langgraph_api: 0.0.15
> langgraph_cli: 0.1.65
> langgraph_license: Installed. No version info available.
> langgraph_sdk: 0.1.48
> langgraph_storage: Installed. No version info available.

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.11.11
> anthropic: 0.42.0
> async-timeout: Installed. No version info available.
> click: 8.1.8
> cryptography: 43.0.3
> dataclasses-json: 0.6.7
> defusedxml: 0.7.1
> httpx: 0.28.1
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> jsonschema-rs: 0.25.1
> langgraph: 0.2.56
> langgraph-checkpoint: 2.0.9
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.4
> openai: 1.55.3
> orjson: 3.10.13
> packaging: 24.2
> pydantic: 2.10.4
> pydantic-settings: 2.7.1
> pyjwt: 2.10.1
> python-dotenv: 1.0.1
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.27
> sse-starlette: 2.1.3
> starlette: 0.45.2
> structlog: 24.4.0
> tenacity: 8.5.0
> tiktoken: 0.8.0
> typing-extensions: 4.12.2
> uvicorn: 0.34.0
> watchfiles: 1.0.3