Package org.machanism.machai.ai.provider.openai


package org.machanism.machai.ai.provider.openai
OpenAI provider integration for MachAI.

This package contains the OpenAI-backed Genai implementation used by MachAI to submit prompts, optional system instructions, file inputs, and locally registered tools through the OpenAI Responses API. It also exposes embedding generation support and translates OpenAI usage data into MachAI usage metrics.

The central type in this package is OpenAIProvider, which manages request construction, response parsing, tool-call execution, input logging, and client configuration. Tool definitions added through the provider are exposed as OpenAI function tools, and tool-call responses are fed back into the conversation until the model returns a final answer.

Configuration overview

The provider is initialized from a configurator and supports settings such as OPENAI_API_KEY, chatModel, OPENAI_BASE_URL, GENAI_TIMEOUT, MAX_OUTPUT_TOKENS, MAX_TOOL_CALLS, and embedding.model.

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();