ChatPerplexity
This notebook covers how to get started with Perplexity
chat models.
from langchain_community.chat_models import ChatPerplexity
from langchain_core.prompts import ChatPromptTemplate
The code provided assumes that your PPLX_API_KEY is set in your environment variables. If you would like to manually specify your API key and also choose a different model, you can use the following code:
chat = ChatPerplexity(
temperature=0, pplx_api_key="YOUR_API_KEY", model="llama-3-sonar-small-32k-online"
)
The code provided assumes that your PPLX_API_KEY is set in your environment variables. If you would like to manually specify your API key and also choose a different model, you can use the following code:
chat = ChatPerplexity(temperature=0, pplx_api_key="YOUR_API_KEY", model="llama-3.1-sonar-small-128k-online")
You can check a list of available models here. For reproducibility, we can set the API key dynamically by taking it as an input in this notebook.
import os
from getpass import getpass
PPLX_API_KEY = getpass()
os.environ["PPLX_API_KEY"] = PPLX_API_KEY
chat = ChatPerplexity(temperature=0, model="llama-3.1-sonar-small-128k-online")
system = "You are a helpful assistant."
human = "{input}"
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
chain = prompt | chat
response = chain.invoke({"input": "Are there any scientific studies backing that taking soy isoflavone supplements could have a positive effect on telomere length in humans?"})
response.content
'There are no specific scientific studies mentioned in the provided sources that directly link soy isoflavone supplements to a positive effect on telomere length in humans. However, some studies suggest that soybean extract can increase telomerase reverse transcriptase protein expression in pancreatic β-cells of diabetes mellitus-induced rats, which might indirectly support the idea that soy components could influence telomere dynamics positively[4]. For a definitive answer, further research specifically focusing on soy isoflavones and their impact on human telomeres would be necessary. \n\nIn general, the literature does suggest that certain dietary components and supplements can positively affect telomere length, such as vitamins C and D, polyunsaturated fatty acids, and specific dietary patterns like the Mediterranean diet[1][2][5]. However, the direct effect of soy isoflavones on human telomeres remains unexplored in the sources provided.\n\nCitations:\n[1] https://www.mdpi.com/2072-6643/16/17/2835\n[2] https://onlinelibrary.wiley.com/doi/full/10.1002/fsn3.3851\n[3] https://www.apco.co.th/storage/newsroom/research-and-development/2024/dietary-supplement/food-science.pdf\n[4] https://mji.ui.ac.id/journal/index.php/mji/article/view/1732/1582\n[5] https://www.mdpi.com/2072-6643/16/15/2525\n'
You can format and structure the prompts like you would typically. In the following example, we ask the model to tell us a joke about cats.
chat = ChatPerplexity(temperature=0, model="llama-3.1-sonar-small-128k-online")
prompt = ChatPromptTemplate.from_messages([("human", "Tell me a joke about {topic}")])
chain = prompt | chat
response = chain.invoke({"topic": "cats"})
response.content
'Here\'s a joke about cats:\n\nWhy did the cat want math lessons from a mermaid?\n\nBecause it couldn\'t find its "core purpose" in life!\n\nRemember, cats are unique and fascinating creatures, and each one has its own special traits and abilities. While some may see them as mysterious or even a bit aloof, they are still beloved pets that bring joy and companionship to their owners. So, if your cat ever seeks guidance from a mermaid, just remember that they are on their own journey to self-discovery!\n'
ChatPerplexity
also supports streaming functionality:
chat = ChatPerplexity(temperature=0.7, model="llama-3.1-sonar-small-128k-online")
prompt = ChatPromptTemplate.from_messages(
[("human", "Are there any scientific studies backing that taking soy isoflavone supplements could have a positive effect on telomere length in humans?")]
)
chain = prompt | chat
for chunk in chain.stream({}):
print(chunk.content, end="", flush=True)
There are no specific scientific studies directly linking the consumption of soy isoflavone supplements to a positive effect on telomere length in humans. However, there are studies that suggest certain dietary components and supplements can influence telomere length positively, such as:
1. **Mylife/Mylife100® Dietary Supplement**: This study found that a dietary supplement derived from five edible plants, including soy protein, significantly increased mean telomere length in Thai adults over an 8-week period[4][5].
2. **Telomere Length Dynamics**: Various studies have shown that certain nutrients like vitamins C, D, and E, as well as polyunsaturated fatty acids, can help maintain or even elongate telomeres by reducing oxidative stress and inflammation[2][3].
3. **Soybean Extract**: While not specifically focused on soy isoflavones, a study on soybean extract found that it increased telomerase reverse transcriptase protein expression in pancreatic β-cells of diabetes mellitus-induced rats, which could indirectly suggest a potential positive effect on telomeres in certain contexts[1].
However, it is crucial to note that these studies do not directly address the specific impact of soy isoflavone supplements on human telomere length. Further research would be needed to definitively establish any such relationship
Citations:
[1] https://mji.ui.ac.id/journal/index.php/mji/article/view/1732/1582
[2] https://www.mdpi.com/2072-6643/16/17/2835
[3] https://www.mdpi.com/2072-6643/16/15/2525
[4] https://onlinelibrary.wiley.com/doi/full/10.1002/fsn3.3851
[5] https://www.apco.co.th/storage/newsroom/research-and-development/2024/dietary-supplement/food-science.pdf
Related
- Chat model conceptual guide
- Chat model how-to guides