Skip to content

Conversation

@amaze-28
Copy link
Contributor

Summary

Adds support for Perplexity AI models in the universal chat model factory.

Changes

  • Added 'perplexity' to _SUPPORTED_PROVIDERS array
  • Added perplexity case to initChatModel() switch statement
  • Updated _inferModelProvider() to recognize sonar* and pplx* model names
  • Added integration test for Perplexity support

Usage

import { initChatModel } from "langchain/chat_models/universal";

// Auto-inferred from model name
const model = await initChatModel("sonar-pro", {
  apiKey: "your-perplexity-key"
});

// Or explicitly specified
const model2 = await initChatModel("sonar-deep-research", {
  modelProvider: "perplexity",
  apiKey: "your-perplexity-key"
});

Testing

  • Added integration test that verifies perplexity models work with the universal API
  • Test covers model initialization and basic invocation

- Add 'perplexity' to supported providers list
- Add perplexity case to initChatModel switch statement
- Update model provider inference for sonar* and pplx* models
- Add integration test for perplexity support
@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2025

🦋 Changeset detected

Latest commit: 7779308

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
langchain Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
langchainjs-docs Ready Ready Preview Sep 26, 2025 3:11am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchainjs-api-refs Ignored Ignored Sep 26, 2025 3:11am

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thanks for the contribution!

- Add @ts-ignore comments for perplexity import to handle circular dependency
- Update documentation to list perplexity as community import
- Follows same pattern as fireworks and together imports
@amaze-28
Copy link
Contributor Author

Hi @christian-bromann, I've pushed a fix for the circular dependency issue. The build should now pass. Could you please check?

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm 🤔 the circular dependency is worrisome .. maybe it is worth creating a perplexity provider package ala @langchain/perplexity here before moving forward.

Thoughts @hntrl ?

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christian-bromann yeah that would be an ideal state, but it's not high prio and if there's an immediate need for this I'm fine to merge. I'd be more worried if we didn't have other community models doing the same thing

Comment on lines 120 to 132
case "perplexity": {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Can not install as a proper dependency due to circular dependency
const { ChatPerplexity } = await import(
// We can not 'expect-error' because if you explicitly build `@langchain/community`
// this import will be able to be resolved, thus there will be no error. However
// this will never be the case in CI.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Can not install as a proper dependency due to circular dependency
"@langchain/community/chat_models/perplexity"
);
return new ChatPerplexity({ model, ...passedParams });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we move this down to the other community models?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Move the perplexity case in the universal chat model switch statement
to be grouped with other community models (fireworks, together) for
better code organization, as requested in maintainer review.
@hntrl hntrl merged commit 2f19cd5 into langchain-ai:main Sep 26, 2025
33 checks passed
@christian-bromann
Copy link
Member

Ported to v1 02ce0b4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants