Class CodeMieProvider

java.lang.Object
org.machanism.machai.process.provider.ProcessProviderAdapter
org.machanism.machai.genai.provider.CodeMieProvider
All Implemented Interfaces:
EmbeddingProvider, ProcessProvider

public class CodeMieProvider extends ProcessProviderAdapter implements EmbeddingProvider
ProcessProvider 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_USERNAME contains "@" (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_URL to BASE_URL
  • OPENAI_API_KEY to the retrieved access token

Delegation is selected based on the configured model prefix:

  • gpt-*, gemini-*, text-embedding-*, codemie-text-embedding-*, amazon.titan-embed-text-*, and blank/unspecified models delegate to OpenAIProvider.
  • claude-* models delegate to AnthropicProvider
Since:
1.2.0
Author:
Viktor Tovstyi
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
      Logger used for authentication and provider-delegation diagnostics.
    • AUTH_URL_PROP_NAME

      public static final String AUTH_URL_PROP_NAME
      Configuration key used to override the default token endpoint.
      See Also:
    • AUTH_URL

      public static final String AUTH_URL
      Default OpenID Connect token endpoint for CodeMie.

      Can be overridden via the AUTH_URL configuration key.

      See Also:
    • BASE_URL

      public static final String 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

      private static final String[] OPENAI_COMPATIBLE_MODELS_PREFIXES
      Model prefixes delegated to the OpenAI-compatible provider.
    • CLAUDE_COMPATIBLE_MODELS_PREFIXES

      private static final String[] 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

      public void init(String model, Configurator conf)
      Initializes the provider using configuration values.

      Required configuration keys:

      • GENAI_USERNAME – user e-mail or client id.
      • GENAI_PASSWORD – password or client secret.

      Optional configuration keys:

      • AUTH_URL – token endpoint override.
      Specified by:
      init in interface EmbeddingProvider
      Specified by:
      init in interface ProcessProvider
      Overrides:
      init in class ProcessProviderAdapter
      Parameters:
      model - model identifier that selects the downstream provider, for example gpt-4o-mini, gemini-1.5-pro, or claude-3-5-sonnet
      conf - configuration source
      Throws:
      IllegalArgumentException - if a configuration conflict is detected, authorization fails, or an unsupported model is configured
    • getToken

      public static String getToken(String url, String username, String password) throws IOException
      Requests an OAuth 2.0 access token from the given token endpoint.

      The request uses application/x-www-form-urlencoded and selects the grant type based on the username value:

      • password if the username contains "@".
      • client_credentials otherwise.
      Parameters:
      url - token endpoint URL
      username - user e-mail (password grant) or client id (client credentials)
      password - password (password grant) or client secret (client credentials)
      Returns:
      the access_token value extracted from the response
      Throws:
      IOException - if the HTTP request fails, returns a non-200 response, or the token cannot be read
    • urlEncode

      private static String urlEncode(String value)
      URL-encodes a value for application/x-www-form-urlencoded request bodies.
      Parameters:
      value - value to encode
      Returns:
      encoded value using UTF-8
    • embedding

      public List<Double> embedding(String text, long dimensions)
      Requests an embedding vector for the given input text.
      Specified by:
      embedding in interface EmbeddingProvider
      Parameters:
      text - input to embed
      dimensions - number of dimensions requested from the embedding model
      Returns:
      embedding as a list of double values, or null when text is null
      Throws:
      IllegalArgumentException - if the selected downstream provider does not support embeddings