Package org.machanism.machai.ai.provider.openai
This package contains the OpenAI-backed Genai
implementation used by MachAI to perform conversational completions, execute
registered function tools, attach file-based inputs, invoke optional built-in
OpenAI tools, and request embedding vectors through the OpenAI Java SDK.
Its central type, OpenAIProvider,
adapts the framework-level provider abstraction to the OpenAI Responses API. The
provider is responsible for client construction, request assembly, conversation
state management, tool registration, iterative tool-call resolution, response
parsing, usage accounting, and request logging.
Supported capabilities
- Sending user prompts and optional system instructions to a configured chat model
- Supplying file references as request inputs
- Registering local Java callbacks as OpenAI function tools
- Enabling built-in web search and MCP server tools from configuration
- Generating embeddings with a configured embedding model
- Capturing token usage for framework-level statistics
Configuration overview
Typical configuration includes values such as OPENAI_API_KEY,
OPENAI_BASE_URL, chatModel, GENAI_TIMEOUT,
MAX_OUTPUT_TOKENS, MAX_TOOL_CALLS, and embedding.model.
Additional namespaced settings control optional web-search and MCP tool
registration.
Typical usage
Configurator cfg = ...;
OpenAIProvider provider = new OpenAIProvider();
provider.init(cfg);
provider.instructions("You are a helpful assistant.");
provider.prompt("Summarize the attached document.");
String answer = provider.perform();
Usage usage = provider.usage();
-
Classes