Skip to content

Commit 9becf15

Browse files
This commit adds support for Perplexity AI provider (#3 - [Providers] Add Perplexity)
The following changes have been made: Added the Perplexity provider to the GenAIProvider enum. Updated the AI Assistance panel to handle the Perplexity provider, including loading and storing the API key, and populating the model dropdown with the available Perplexity models. Created a PerplexityModelFetcher to provide the list of hardcoded models for Perplexity. Updated the JeddictChatModelBuilder to use the OpenAI builders for the Perplexity provider, as the Perplexity API is OpenAI compatible. Sorted the providers by name in the UI. Improved error handling in the JeddictChatModelBuilder. Refactored the layout of the AIAssistancePanel to better handle component resizing.
1 parent 18f05c1 commit 9becf15

6 files changed

Lines changed: 910 additions & 422 deletions

File tree

src/main/java/io/github/jeddict/ai/lang/JeddictChatModelBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import static io.github.jeddict.ai.settings.GenAIProvider.MISTRAL;
5353
import static io.github.jeddict.ai.settings.GenAIProvider.OLLAMA;
5454
import static io.github.jeddict.ai.settings.GenAIProvider.OPEN_AI;
55+
import static io.github.jeddict.ai.settings.GenAIProvider.PERPLEXITY;
5556
import io.github.jeddict.ai.settings.PreferencesManager;
5657
import java.time.Duration;
5758
import java.util.ArrayList;
@@ -100,7 +101,7 @@ public JeddictChatModelBuilder(JeddictStreamHandler handler, String modelName) {
100101
case GOOGLE -> {
101102
streamModel = buildModel(new GoogleStreamingBuilder(), modelName);
102103
}
103-
case OPEN_AI, DEEPINFRA, DEEPSEEK, GROQ, CUSTOM_OPEN_AI,COPILOT_PROXY -> {
104+
case OPEN_AI, DEEPINFRA, DEEPSEEK, GROQ, CUSTOM_OPEN_AI, COPILOT_PROXY, PERPLEXITY -> {
104105
streamModel = buildModel(new OpenAiStreamingBuilder(), modelName);
105106
}
106107
case MISTRAL -> {
@@ -125,7 +126,7 @@ public JeddictChatModelBuilder(JeddictStreamHandler handler, String modelName) {
125126
case GOOGLE -> {
126127
model = buildModel(new GoogleBuilder(), modelName);
127128
}
128-
case OPEN_AI, DEEPINFRA, DEEPSEEK, GROQ, CUSTOM_OPEN_AI,COPILOT_PROXY -> {
129+
case OPEN_AI, DEEPINFRA, DEEPSEEK, GROQ, CUSTOM_OPEN_AI, COPILOT_PROXY, PERPLEXITY -> {
129130
model = buildModel(new OpenAiBuilder(), modelName);
130131
}
131132
case MISTRAL -> {
@@ -308,6 +309,7 @@ private String generateInternal(Project project, String prompt, List<String> ima
308309
"AI assistance failed to generate the requested response: " + errorMessage,
309310
"Error in AI Assistance",
310311
JOptionPane.ERROR_MESSAGE);
312+
handler.onError(e);
311313
}
312314
handle.finish();
313315
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2025 the original author or authors from the Jeddict project (https://jeddict.github.io/).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package io.github.jeddict.ai.models;
17+
18+
import java.util.Arrays;
19+
import java.util.List;
20+
21+
/**
22+
*
23+
*/
24+
public class PerplexityModelFetcher {
25+
26+
public final String API_URL = "https://api.perplexity.ai";
27+
28+
public String getAPIUrl() {
29+
return API_URL;
30+
}
31+
32+
/**
33+
* Perplexity does not support fetching the models for now, but we keep same
34+
* pattern as per the other providers.
35+
*/
36+
public List<String> getModels() {
37+
return Arrays.asList("sonar", "sonar-pro", "sonar-reasoning", "sonar-reasoning-pro", "sonar-deep-research");
38+
}
39+
}

0 commit comments

Comments
 (0)