GenAI Client 1.4.2-SNAPSHOT API
GenAI Client
GenAI Client is a Java library designed for seamless integration with Generative AI providers. It offers foundational prompt management and embedding capabilities, enabling AI-powered features across Machai modules. The library simplifies interactions with AI services, supporting advanced use cases such as semantic search, automated content generation, and intelligent project assembly within the Machanism ecosystem.
GenAI Client supports all types of project files, including source code, documentation, project site content, and other relevant files. Applications can expose project-specific capabilities as annotated tools, prompts, and resources; configure a provider; submit generation or embedding requests; and incorporate the results into project workflows.
Architecture
The provider package defines vendor-neutral contracts for conversational processing and embeddings, together with reusable lifecycle, state, conversion, logging, and capability registration infrastructure. Providers accept a model and configuration, collect instructions and prompts, optionally register tools and resources, perform a request, and can be cleared before an independent request. Implementations should be treated as stateful and non-thread-safe unless they document otherwise.
The implementation packages connect those contracts to backend SDKs and local workflows. OpenAI and Anthropic adapters translate requests, execute registered tools, support their backend-specific search and MCP features, and record response usage. CodeMie routes model names to compatible backend adapters. The process-provider package also provides a disabled provider and a deterministic YAML-driven tool provider.
The manager package resolves chat and embedding providers from provider-and-model identifiers and records process-local input, cached-input, and output token usage. The tools package supplies runtime annotations and metadata for tools, prompts, resources, and parameters, along with service-based discovery, compatibility filtering, callable callbacks, conversation roles, and structured exception types.
The class diagram shows the relationships among provider contracts, shared infrastructure, manager, concrete backend adapters, usage records, and annotated function-tool types.
Packages
- org.machanism.machai.process.manager
- Resolves configured generative-AI and embedding providers from provider-and-model identifiers and records process-local usage by model identifier. Its central types are ProcessProviderManager, Usage, and UsageStatistics.
- org.machanism.machai.process.provider
- Defines provider-neutral generation and embedding contracts, stateful provider infrastructure, delegation, type conversion, reflective capability registration, and logging for prompts, tools, resources, web search, and MCP configuration.
- org.machanism.machai.process.tools
- Provides runtime annotations and metadata for declaring Java tools, prompts, resources, and parameters, together with service-based discovery, compatibility filtering, callable-tool contracts, roles, and structured error types.
- org.machanism.machai.genai.provider
- Implements OpenAI and Anthropic integrations, CodeMie authentication and model-prefix routing, backend-specific request translation, web search and MCP support, embeddings, and response-usage accounting. These adapters connect provider contracts to remote model APIs, resolve model-issued tool calls, and retain conversation state until cleared.
Using the API
Start with the provider and tools package summaries to select a provider contract and declare application capabilities. Use the manager package when a provider must be selected dynamically from configuration. Concrete provider documentation describes backend-specific credentials, endpoints, model options, supported capabilities, and request lifecycle details. Register function-tool implementations when a model or local tool workflow needs access to project capabilities, and call the provider's clear operation before beginning an independent request on a reused instance. Use an EmbeddingProvider for vector generation in semantic and similarity-based workflows.