Class CodeMieProvider

java.lang.Object
org.machanism.machai.ai.provider.GenaiAdapter
org.machanism.machai.ai.provider.codemie.CodeMieProvider
All Implemented Interfaces:
Genai

public class CodeMieProvider extends GenaiAdapter implements 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_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 chatModel prefix:

  • Field Details

    • AUTH_URL_PROP_NAME

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

      public static final String OPENAI_API_KEY
      Configuration/environment key used by OpenAI-compatible clients to provide the API key.

      For CodeMie this value is set to the retrieved OAuth 2.0 access token.

      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:
  • Constructor Details

    • CodeMieProvider

      public CodeMieProvider()
  • Method Details

    • init

      public void init(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.
      • chatModel – model identifier (for example gpt-4o-mini, gemini-1.5-pro, claude-3-5-sonnet).

      Optional configuration keys:

      • AUTH_URL – token endpoint override.
      Specified by:
      init in interface Genai
      Overrides:
      init in class GenaiAdapter
      Parameters:
      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