Package org.machanism.machai.ai


package org.machanism.machai.ai
Provider-agnostic generative AI integration for MachAI.

This package defines the root API used to work with large language model providers, provider management, host-exposed tools, and usage tracking without coupling application code to a specific backend implementation. It serves as the entry point for configuring providers, preparing prompts and instructions, enabling tool calling, executing model requests, and collecting usage information across supported integrations.

Responsibilities

  • Provider resolution and lifecycle via org.machanism.machai.ai.manager, including lookup by provider/model identifier, initialization with runtime configuration, and aggregation of usage metrics.
  • Common provider contracts in org.machanism.machai.ai.provider, centered on the Genai interface for prompts, instructions, execution, embeddings, file inputs, tool integration, and token accounting.
  • Concrete provider implementations under org.machanism.machai.ai.provider.* for specific backends such as OpenAI-compatible services, EPAM CodeMie, and fallback no-operation behavior.
  • Function tool discovery and registration in org.machanism.machai.ai.tools, enabling providers that support tool or function calling to expose controlled application capabilities through ServiceLoader.

Typical workflow

  1. Select or resolve a provider for a model identifier such as OpenAI:gpt-4o-mini.
  2. Initialize the provider using application configuration supplied through Configurator.
  3. Set instructions, prompts, optional files, and provider-specific options.
  4. Apply discovered tools with FunctionToolsLoader when tool calling is needed.
  5. Execute the request and record returned usage with GenaiProviderManager.

Example

 Configurator conf = ...;
 Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4o-mini", conf);

 provider.instructions("You are a concise assistant.");
 provider.prompt("Summarize this repository.");

 FunctionToolsLoader loader = FunctionToolsLoader.getInstance();
 loader.setConfiguration(conf);
 loader.applyTools(provider);

 String answer = provider.perform();
 GenaiProviderManager.addUsage(provider.usage());
 GenaiProviderManager.logUsage();
 

Application code should depend on this package when it needs a stable, vendor-neutral entry point for AI interactions while delegating provider-specific behavior and runtime integration details to the corresponding sub-packages.