genkitx-perplexity-sonar is a community plugin for using Perplexity's Sonar API and all its supported models with Firebase Genkit.
This Genkit plugin allows to use Perplexity's Sonar API models through their official APIs.
The plugin supports the most recent Sonar models: sonar, sonar-pro, sonar-reasoning, sonar-reasoning-pro, and sonar-deep-research.
Install the plugin in your project with your favorite package manager:
npm installyarn add
import { genkit } from 'genkit';
import { perplexitySonar, sonar } from '';
const ai = genkit({
plugins: [perplexitySonar({ apiKey: process.env.PERPLEXITY_SONAR_API_KEY })],
});The simplest way to generate text is by using the generate method:
const response = await ai.generate({
model: sonar, // model imported from
prompt: 'Tell me a joke.',
});
console.log(response.text);You can check the official documentations Here for more details about the API.
const response = await ai.generate({
model: sonar, // model imported from
prompt: 'Tell me a joke.',
config: {
// check https://docs.perplexity.ai/guides/search-domain-filters for more details
allowed_search_domain_filter: ["https://www.domain1.com", "domain2.com"], // allowed domain names, https:// and www are removed automatically
denied_search_domain_filter: ["domain3.con", "domain4.com"], // denied list, it will automatically add - before the domain name
// check https://docs.perplexity.ai/guides/date-range-filter-guide for more details
search_before_date_filter: new Date(),
search_after_date_filter: new Date(),
search_recency_filter: "month",
// check https://docs.perplexity.ai/guides/search-context-size-guide for more details
search_context_size: "low",
// check https://docs.perplexity.ai/guides/user-location-filter-guide for more etails
user_location: {
country: "DZ",
latitude: 12.2,
longitude: 12.2,
},
// other configurarions
results_with_images: false,
results_with_related_questions: false,
}
});Want to contribute to the project? That's awesome! Head over to our Contribution Guidelines.
Note
This repository depends on Google's Firebase Genkit. For issues and questions related to Genkit, please refer to instructions available in Genkit's repository.
Reach out by opening a discussion on Github Discussions.
This project is licensed under the Apache 2.0 License.
