Class OpenAiCompatibleClient
- All Implemented Interfaces:
AiProviderClient
AiProviderClient implementation for AI providers that expose an
OpenAI-compatible chat completion API.
This client supports providers that implement the OpenAI-style
/v1/chat/completions endpoint. The same implementation is used for:
The client constructs a chat-style prompt consisting of a system message defining the classification rules and a user message containing the test class source together with the taxonomy definition. The model response is expected to contain a JSON object describing the security classification.
Operational Responsibilities
- constructing OpenAI-compatible chat completion requests
- injecting the taxonomy-driven classification prompt
- performing authenticated HTTP requests
- extracting JSON content from the model response
- normalizing the result into
AiClassSuggestion
The implementation is provider-neutral for APIs that follow the OpenAI protocol, which allows reuse across multiple compatible services such as OpenRouter.
Instances are typically created through
AiProviderFactory.create(AiOptions).
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenAiCompatibleClient(AiOptions options) Creates a new client for an OpenAI-compatible provider. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines whether the configured 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 an OpenAI-compatible chat completion API.
-
Constructor Details
-
OpenAiCompatibleClient
Creates a new client for an OpenAI-compatible provider.The supplied configuration determines the provider endpoint, model name, authentication method, request timeout, and other runtime parameters.
- Parameters:
options- AI runtime configuration
-
-
Method Details
-
isAvailable
public boolean isAvailable()Determines whether the configured provider can be used in the current runtime environment.For OpenAI-compatible providers, availability is determined by the presence of a usable API key resolved through
AiOptions.resolvedApiKey().- Specified by:
isAvailablein interfaceAiProviderClient- Returns:
trueif a usable API key is available
-
suggestForClass
public AiClassSuggestion suggestForClass(String fqcn, String classSource, String taxonomyText, List<PromptBuilder.TargetMethod> targetMethods) throws AiSuggestionException Submits a classification request to an OpenAI-compatible chat completion API.The request payload includes:
- the configured model identifier
- a system prompt defining classification rules
- a user prompt containing the test class source and taxonomy
- a deterministic temperature setting
When the selected provider is
AiProvider.OPENROUTER, additional HTTP headers are included to identify the calling application.The response is expected to contain a JSON object in the message content field. The JSON text is extracted and 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 classification result
- Throws:
AiSuggestionException- if the provider request fails, the model response is invalid, or JSON deserialization fails- See Also:
-