Package org.machanism.machai.ai


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

This package defines the top-level abstractions used to work with large language models and related AI services without coupling application code to a specific vendor SDK, transport, or authentication mechanism. It serves as the entry point for configuring providers, building prompts and instructions, attaching host-executed tools, and collecting usage information from completed interactions.

Package scope

  • Manager infrastructure in org.machanism.machai.ai.manager resolves provider/model identifiers, initializes provider implementations, and aggregates token usage statistics.
  • Provider contracts and implementations in org.machanism.machai.ai.provider define the common Genai API together with concrete integrations such as OpenAI, Gemini, CodeMie, and no-op/offline providers.
  • Host-side tool integration in org.machanism.machai.ai.tools exposes controlled local capabilities such as command execution and HTTP access that can be registered with compatible providers for tool or function calling.

Typical usage flow

  1. Resolve a provider using a provider/model identifier such as OpenAI:gpt-4o-mini.
  2. Configure system instructions, user prompts, and any optional provider settings.
  3. Optionally discover and register host-side tools through FunctionToolsLoader.
  4. Execute the request through the selected provider and inspect or aggregate usage metrics.

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.getInstance().setConfiguration(conf);
 FunctionToolsLoader.getInstance().applyTools(provider);

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

The package is designed so higher-level application code can remain focused on prompt orchestration and result handling while provider selection, provider-specific execution details, and host capability registration are managed by the corresponding sub-packages.