-
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add support for Anthropic and DeepSeek AI providers #94
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
Open
shenxianpeng
wants to merge
5
commits into
main
Choose a base branch
from
feature/add-providers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
54ee322
feat: add support for Anthropic and DeepSeek AI providers with config…
shenxianpeng 161bf85
feat: add help documentation for Anthropic and DeepSeek providers
shenxianpeng 869e639
feat: refine dependency exclusions for Jackson and SLF4J in pom.xml
shenxianpeng f2df191
Merge branch 'main' into feature/add-providers
shenxianpeng 5382082
fix: update ProviderTest to fix test failure
shenxianpeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/io/jenkins/plugins/explain_error/provider/AnthropicProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package io.jenkins.plugins.explain_error.provider; | ||
|
|
||
| import dev.langchain4j.model.anthropic.AnthropicChatModel; | ||
| import dev.langchain4j.model.chat.ChatModel; | ||
| import dev.langchain4j.service.AiServices; | ||
| import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import hudson.Extension; | ||
| import hudson.Util; | ||
| import hudson.model.AutoCompletionCandidates; | ||
| import hudson.model.TaskListener; | ||
| import hudson.util.FormValidation; | ||
| import hudson.util.Secret; | ||
| import io.jenkins.plugins.explain_error.ExplanationException; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import jenkins.model.Jenkins; | ||
| import org.jenkinsci.Symbol; | ||
| import org.kohsuke.stapler.DataBoundConstructor; | ||
| import org.kohsuke.stapler.QueryParameter; | ||
| import org.kohsuke.stapler.verb.GET; | ||
| import org.kohsuke.stapler.verb.POST; | ||
|
|
||
| public class AnthropicProvider extends BaseAIProvider { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(AnthropicProvider.class.getName()); | ||
|
|
||
| protected Secret apiKey; | ||
|
|
||
| @DataBoundConstructor | ||
| public AnthropicProvider(String url, String model, Secret apiKey) { | ||
| super(url, model); | ||
| this.apiKey = apiKey; | ||
| } | ||
|
|
||
| public Secret getApiKey() { | ||
| return apiKey; | ||
| } | ||
|
|
||
| @Override | ||
| public Assistant createAssistant() { | ||
| ChatModel model = AnthropicChatModel.builder() | ||
| .baseUrl(Util.fixEmptyAndTrim(getUrl())) // Will use default if null | ||
| .apiKey(getApiKey().getPlainText()) | ||
| .modelName(getModel()) | ||
| .temperature(0.3) | ||
| .logRequests(LOGGER.isLoggable(Level.FINE)) | ||
| .logResponses(LOGGER.isLoggable(Level.FINE)) | ||
| .build(); | ||
|
|
||
| return AiServices.create(Assistant.class, model); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isNotValid(@CheckForNull TaskListener listener) { | ||
| if (listener != null) { | ||
| if (Util.fixEmptyAndTrim(Secret.toString(getApiKey())) == null) { | ||
| listener.getLogger().println("No Api key configured for Anthropic."); | ||
| } else if (Util.fixEmptyAndTrim(getModel()) == null) { | ||
| listener.getLogger().println("No Model configured for Anthropic."); | ||
| } | ||
| } | ||
| return Util.fixEmptyAndTrim(Secret.toString(getApiKey())) == null || | ||
| Util.fixEmptyAndTrim(getModel()) == null; | ||
| } | ||
|
|
||
| @Extension | ||
| @Symbol("anthropic") | ||
| public static class DescriptorImpl extends BaseProviderDescriptor { | ||
|
|
||
| private static final String[] MODELS = new String[]{ | ||
| "claude-3-5-sonnet-20241022", | ||
| "claude-3-5-sonnet-20240620", | ||
| "claude-3-5-haiku-20241022", | ||
| "claude-3-opus-20240229", | ||
| "claude-3-sonnet-20240229", | ||
| "claude-3-haiku-20240307" | ||
| }; | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Anthropic"; | ||
| } | ||
|
|
||
| public String getDefaultModel() { | ||
| return "claude-3-5-sonnet-20241022"; | ||
| } | ||
|
|
||
| @GET | ||
| @SuppressWarnings("lgtm[jenkins/no-permission-check]") | ||
| public AutoCompletionCandidates doAutoCompleteModel(@QueryParameter String value) { | ||
| AutoCompletionCandidates c = new AutoCompletionCandidates(); | ||
| for (String model : MODELS) { | ||
| if (model.toLowerCase().startsWith(value.toLowerCase())) { | ||
| c.add(model); | ||
| } | ||
| } | ||
| return c; | ||
| } | ||
|
|
||
| /** | ||
| * Method to test the AI API configuration. | ||
| * This is called when the "Test Configuration" button is clicked. | ||
| */ | ||
| @POST | ||
| public FormValidation doTestConfiguration(@QueryParameter("apiKey") Secret apiKey, | ||
| @QueryParameter("url") String url, | ||
| @QueryParameter("model") String model) throws ExplanationException { | ||
| Jenkins.get().checkPermission(Jenkins.ADMINISTER); | ||
|
|
||
| AnthropicProvider provider = new AnthropicProvider(url, model, apiKey); | ||
| try { | ||
| provider.explainError("Send 'Configuration test successful' to me.", null); | ||
| return FormValidation.ok("Configuration test successful! API connection is working properly."); | ||
| } catch (ExplanationException e) { | ||
| return FormValidation.error("Configuration test failed: " + e.getMessage(), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.