-
Notifications
You must be signed in to change notification settings - Fork 17.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from OpenAI Client to Perplexity API for Full Functionality #30393
Comments
I ran into the same issue and couldn’t use the full Perplexity functionality in my requests. It would be great if this could be supported! Definitely think this would be a useful update. 👌 |
The OpenAI client supports some fields for handling additional parameters, see for example here. Can we use these? from langchain_community.chat_models import ChatPerplexity
chat_perplexity = ChatPerplexity(model="sonar-pro", temperature=0.8)
response = chat_perplexity.invoke(
"Tell me about Michael Jordan.",
extra_body={"search_recency_filter": "week"},
) I tried passing
|
Thank you for noticing! I tried it, and it works as expected. However, I also noticed something else in the Python code block: message = AIMessage(
content=response.choices[0].message.content,
additional_kwargs={"citations": response.citations},
usage_metadata=usage_metadata,
) Currently, only citations are appended to the response, but depending on the parameters passed, the response could include other important attributes like related_questions or images. To ensure the Perplexity response is handled correctly, these fields should also be included when available. I’m working on a PR to properly append or return these fields. Let me know if you have any thoughts on this! Should I close the other PR? |
Thanks @DavidSanSan110, will take a look at the new PR. For context, we will likely move ChatPerplexity into a dedicated package In my mind here are some other needs for ChatPerplexity:
|
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
TypeError: Completions.create() got an unexpected keyword argument 'search_recency_filter'
Description
The latest version of LangChain uses the OpenAI client to make calls to Perplexity. However, the OpenAI client does not support certain Perplexity-specific attributes such as search_domain_filter and search_recency_filter. This results in errors when trying to use these parameters, even though Perplexity does support them.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: