Class AnthropicClient
- All Implemented Interfaces:
AiProviderClient
AiProviderClient implementation for the Anthropic API.
This client submits classification requests to the Anthropic
Claude API and converts the
returned response into the internal AiClassSuggestion model used by
the MethodAtlas AI subsystem.
Operational Responsibilities
- constructing Anthropic message API requests
- injecting the taxonomy-driven classification prompt
- performing authenticated HTTP calls to the Anthropic service
- extracting the JSON result embedded in the model response
- normalizing the result into
AiClassSuggestion
The client uses the /v1/messages endpoint and relies on the Claude
message format, where a system prompt defines classification rules and the
user message contains the class source together with the taxonomy
specification.
Instances of this class are typically created by
AiProviderFactory.create(AiOptions).
This implementation is stateless apart from immutable configuration and is therefore safe for reuse across multiple requests.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAnthropicClient(AiOptions options) Creates a new Anthropic client using the supplied runtime configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines whether the Anthropic provider can be used in the current runtime environment.suggestForClass(String fqcn, String classSource, String taxonomyText, List<PromptBuilder.TargetMethod> targetMethods) Submits a classification request to the Anthropic API for the specified test class.
-
Constructor Details
-
AnthropicClient
Creates a new Anthropic client using the supplied runtime configuration.The configuration defines the model identifier, API endpoint, request timeout, and authentication settings used when communicating with the Anthropic service.
- Parameters:
options- AI runtime configuration
-
-
Method Details
-
isAvailable
public boolean isAvailable()Determines whether the Anthropic provider can be used in the current runtime environment.The provider is considered available when a non-empty API key can be resolved from
AiOptions.resolvedApiKey().- Specified by:
isAvailablein interfaceAiProviderClient- Returns:
trueif a usable API key is configured
-
suggestForClass
public AiClassSuggestion suggestForClass(String fqcn, String classSource, String taxonomyText, List<PromptBuilder.TargetMethod> targetMethods) throws AiSuggestionException Submits a classification request to the Anthropic API for the specified test class.The method constructs a message-based request containing:
- a system prompt enforcing deterministic JSON output
- a user prompt containing the class source and taxonomy definition
The response is parsed to extract the first JSON object returned by the model, which is then deserialized into an
AiClassSuggestion.- Specified by:
suggestForClassin interfaceAiProviderClient- Parameters:
fqcn- fully qualified class name being analyzedclassSource- complete source code of the classtaxonomyText- taxonomy definition guiding classificationtargetMethods- deterministically extracted JUnit test methods that must be classified- Returns:
- normalized AI classification result
- Throws:
AiSuggestionException- if the provider request fails, the response cannot be parsed, or the provider returns invalid content- See Also:
-