Class CodeMieProvider
java.lang.Object
org.machanism.machai.ai.provider.GenaiAdapter
org.machanism.machai.ai.provider.impl.CodeMieProvider
- All Implemented Interfaces:
EmbeddingProvider,Genai
Genai implementation that integrates with EPAM CodeMie.
This provider authenticates against a CodeMie OpenID Connect (OIDC) token endpoint to obtain an OAuth 2.0 access token and then configures an OpenAI-compatible backend (CodeMie Code Assistant REST API).
Authentication modes
- Password grant is used when
GENAI_USERNAMEcontains"@"(typical e-mail login). - Client credentials is used otherwise (service-to-service).
Provider delegation
After retrieving a token, this provider sets the following configuration keys before delegating to a downstream provider:
OPENAI_BASE_URLtoBASE_URLOPENAI_API_KEYto the retrieved access token
Delegation is selected based on the configured model prefix:
gpt-*(or blank/unspecified) models delegate toOpenAIProviderclaude-*models delegate toAnthropicProvider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classAnthropic provider extension that refreshes the CodeMie access token.private final classOpenAI provider extension that refreshes the CodeMie access token. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault OpenID Connect token endpoint for CodeMie.static final StringConfiguration key used to override the default token endpoint.static final StringBase URL for the CodeMie Code Assistant API.private static final String[]Model prefixes delegated to the Anthropic-compatible provider.private static final org.slf4j.LoggerLogger used for authentication and provider-delegation diagnostics.private static final String[]Model prefixes delegated to the OpenAI-compatible provider.Fields inherited from class org.machanism.machai.ai.provider.GenaiAdapter
provider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRequests an embedding vector for the given input text.static StringRequests an OAuth 2.0 access token from the given token endpoint.voidinit(String model, Configurator conf) Initializes the provider using configuration values.private static StringURL-encodes a value forapplication/x-www-form-urlencodedrequest bodies.Methods inherited from class org.machanism.machai.ai.provider.GenaiAdapter
addPrompts, addResources, addTools, clear, instructions, perform, prompt, setEnabledTools, setErrorHandling, setProjectDir, setProvider
-
Field Details
-
logger
private static final org.slf4j.Logger loggerLogger used for authentication and provider-delegation diagnostics. -
AUTH_URL_PROP_NAME
Configuration key used to override the default token endpoint.- See Also:
-
AUTH_URL
Default OpenID Connect token endpoint for CodeMie.Can be overridden via the
AUTH_URLconfiguration key.- See Also:
-
BASE_URL
Base URL for the CodeMie Code Assistant API.This base URL is used to configure the underlying OpenAI-compatible client.
- See Also:
-
OPENAI_COMPATIBLE_MODELS_PREFIXES
Model prefixes delegated to the OpenAI-compatible provider. -
CLAUDE_COMPATIBLE_MODELS_PREFIXES
Model prefixes delegated to the Anthropic-compatible provider.
-
-
Constructor Details
-
CodeMieProvider
public CodeMieProvider()Creates a CodeMie provider instance.
-
-
Method Details
-
init
Initializes the provider using configuration values.Required configuration keys:
GENAI_USERNAME– user e-mail or client id.GENAI_PASSWORD– password or client secret.model– model identifier (for examplegpt-4o-mini,gemini-1.5-pro,claude-3-5-sonnet).
Optional configuration keys:
AUTH_URL– token endpoint override.
- Specified by:
initin interfaceEmbeddingProvider- Specified by:
initin interfaceGenai- Overrides:
initin classGenaiAdapter- Parameters:
conf- configuration sourcemodel- the model identifier or name to use- Throws:
IllegalArgumentException- if a configuration conflict is detected, authorization fails, or an unsupported model is configured
-
getToken
Requests an OAuth 2.0 access token from the given token endpoint.The request uses
application/x-www-form-urlencodedand selects the grant type based on theusernamevalue:passwordif the username contains"@".client_credentialsotherwise.
- Parameters:
url- token endpoint URLusername- user e-mail (password grant) or client id (client credentials)password- password (password grant) or client secret (client credentials)- Returns:
- the
access_tokenvalue extracted from the response - Throws:
IOException- if the HTTP request fails, returns a non-200 response, or the token cannot be read
-
urlEncode
URL-encodes a value forapplication/x-www-form-urlencodedrequest bodies.- Parameters:
value- value to encode- Returns:
- encoded value using UTF-8
-
embedding
Requests an embedding vector for the given input text.- Specified by:
embeddingin interfaceEmbeddingProvider- Parameters:
text- input to embeddimensions- number of dimensions requested from the embedding model- Returns:
- embedding as a list of
doublevalues, ornullwhentextisnull
-