-
-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for Anthropic, Azure OpenAI, and DeepSeek providers #78
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
11
commits into
main
Choose a base branch
from
feature/more-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
11 commits
Select commit
Hold shift + click to select a range
3fe6783
feat: enhance AI provider support with Anthropic, Azure OpenAI, and D…
shenxianpeng d88e2c1
feat: add support for Anthropic, Azure OpenAI, and DeepSeek providers…
shenxianpeng ac030f6
feat: add configuration files for Anthropic, Azure OpenAI, and DeepSe…
shenxianpeng 7fed73e
Update src/main/java/io/jenkins/plugins/explain_error/provider/Anthro…
shenxianpeng 8fac7f3
Update src/main/java/io/jenkins/plugins/explain_error/provider/AzureO…
shenxianpeng 8918998
Update src/main/java/io/jenkins/plugins/explain_error/provider/Anthro…
shenxianpeng d8c771e
Update src/main/java/io/jenkins/plugins/explain_error/provider/AzureO…
shenxianpeng 715a47e
Update src/main/java/io/jenkins/plugins/explain_error/provider/DeepSe…
shenxianpeng f9175d0
Remove response format specification from AnthropicProvider
shenxianpeng 2a7e9be
Address PR review comments
shenxianpeng 5bb85f2
Merge branch 'main' into feature/more-providers
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
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
126 changes: 126 additions & 0 deletions
126
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,126 @@ | ||
| package io.jenkins.plugins.explain_error.provider; | ||
|
|
||
| import dev.langchain4j.model.anthropic.AnthropicChatModel; | ||
| import dev.langchain4j.model.chat.ChatModel; | ||
| import dev.langchain4j.model.chat.request.ResponseFormat; | ||
| 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."); | ||
| } | ||
| if (Util.fixEmptyAndTrim(getModel()) == null) { | ||
| listener.getLogger().println("No Model configured for Anthropic."); | ||
shenxianpeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| 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-7-sonnet-20250219", | ||
| "claude-3-5-sonnet-20241022", | ||
| "claude-3-5-haiku-20241022", | ||
| "claude-3-opus-20240229", | ||
| "claude-3-sonnet-20240229", | ||
| "claude-3-haiku-20240307" | ||
| }; | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Anthropic (Claude)"; | ||
| } | ||
|
|
||
shenxianpeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| 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.