Package org.machanism.machai.ai.provider
Class GenaiAdapter
java.lang.Object
org.machanism.machai.ai.provider.GenaiAdapter
- All Implemented Interfaces:
Genai
- Direct Known Subclasses:
CodeMieProvider
Delegating
Genai implementation.
This adapter forwards all Genai calls to an underlying provider instance configured via
setProvider(Genai).
Intended use cases include decorating providers (for example, adding cross-cutting concerns like logging,
metrics, retries, or request shaping) while preserving the Genai contract.
Thread-safety: Instances are not thread-safe unless the delegated provider is thread-safe and access is externally synchronized.
-
Field Summary
FieldsFields inherited from interface org.machanism.machai.ai.provider.Genai
LINE_SEPARATOR, LOG_INPUTS_PROP_NAME, PARAGRAPH_SEPARATOR, PASSWORD_PROP_NAME, SERVERID_PROP_NAME, USERNAME_PROP_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTool(String name, String description, ToolFunction function, String... paramsDesc) Registers a custom tool function that the provider may invoke at runtime.voidclear()Clears any stored files and session/provider state.Computes an embedding vector for the provided text.voidinit(Configurator conf) Initializes the provider with application configuration.voidEnables logging of provider inputs to the given directory.voidinstructions(String instructions) Sets system/session instructions for the current conversation.perform()Executes the provider to produce a response based on the accumulated prompts and state.voidAdds a user prompt to the current session.voidsetProvider(Genai provider) Sets the delegate provider.voidsetWorkingDir(File workingDir) Configures the working directory used for file and tool operations.usage()Returns token usage metrics for the most recentGenai.perform()invocation.
-
Field Details
-
provider
Delegate provider.Subclasses typically set this value during construction or initialization using
setProvider(Genai).
-
-
Constructor Details
-
GenaiAdapter
public GenaiAdapter()Creates an adapter without a delegate.Call
setProvider(Genai)before invoking any other methods.
-
-
Method Details
-
setProvider
Sets the delegate provider.- Parameters:
provider- the provider to delegate to- Throws:
IllegalArgumentException- ifproviderisnull
-
init
Description copied from interface:GenaiInitializes the provider with application configuration. -
prompt
Description copied from interface:GenaiAdds a user prompt to the current session. -
embedding
Description copied from interface:GenaiComputes an embedding vector for the provided text. -
clear
public void clear()Description copied from interface:GenaiClears any stored files and session/provider state. -
addTool
Description copied from interface:GenaiRegisters a custom tool function that the provider may invoke at runtime.The expected argument structure passed to
functionis provider-specific.- Specified by:
addToolin interfaceGenai- Parameters:
name- tool name (unique per provider instance)description- human-readable description of the toolfunction- function implementation; receives an argument array and returns a resultparamsDesc- parameter descriptors (format is provider-specific)
-
instructions
Description copied from interface:GenaiSets system/session instructions for the current conversation.- Specified by:
instructionsin interfaceGenai- Parameters:
instructions- instruction text
-
perform
Description copied from interface:GenaiExecutes the provider to produce a response based on the accumulated prompts and state. -
inputsLog
Description copied from interface:GenaiEnables logging of provider inputs to the given directory. -
setWorkingDir
Description copied from interface:GenaiConfigures the working directory used for file and tool operations.- Specified by:
setWorkingDirin interfaceGenai- Parameters:
workingDir- the working directory
-
usage
Description copied from interface:GenaiReturns token usage metrics for the most recentGenai.perform()invocation.
-