Package org.machanism.machai.ai.provider
Interface Genai
- All Known Implementing Classes:
AbstractAIProvider,AnthropicProvider,CodeMieProvider,CodeMieProvider.ClaudeProviderExtension,CodeMieProvider.OpenAIProviderExtension,GenaiAdapter,NoneProvider,OpenAIProvider,ToolsProvider
public interface Genai
Contract for a generative-AI provider integration.
A Genai represents a concrete implementation (for example OpenAI,
Gemini, a local model, etc.) capable of:
- Collecting prompts and system instructions for a conversation,
- Attaching local or remote files for provider-side processing,
- Registering tool functions that may be invoked during a run.
Implementations may keep session state between calls. Use clear() to
reset conversation state.
Typical usage
Configurator conf = ...;
Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4o-mini", conf);
provider.instructions("You are a helpful assistant.");
provider.prompt("Hello!");
String response = provider.perform();
provider.clear();
- Author:
- Viktor Tovstyi
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPrompts(FunctionTools tools) Scans the providedFunctionToolsinstance for methods annotated withPrompt, and registers each prompt for use during a run.voidaddResources(FunctionTools tools) Scans the providedFunctionToolsinstance for methods annotated withResource, and registers each resource for use during a run.voidaddTools(FunctionTools tools) Registers a set of tool functions that may be invoked during a run.voidclear()Clears any stored files and session/provider state.voidinit(String model, Configurator conf) Initializes the provider with application configuration.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.voidsetEnabledTools(String[] tools) Configures the list of tool names that are enabled and allowed to be used by the AI provider.voidsetErrorHandling(boolean errorHandling) Configures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.voidsetProjectDir(File projectDir) Sets the working directory for the provider, which may be used by tool handlers.
-
Method Details
-
init
Initializes the provider with application configuration.- Parameters:
model- the model identifier or name to useconf- configuration source
-
prompt
Adds a user prompt to the current session.- Parameters:
text- the prompt text
-
clear
void clear()Clears any stored files and session/provider state.This resets the conversation and any accumulated context.
-
instructions
Sets system/session instructions for the current conversation.- Parameters:
instructions- instruction text
-
perform
String perform()Executes the provider to produce a response based on the accumulated prompts and state.- Returns:
- the provider response as a string
-
addTools
Registers a set of tool functions that may be invoked during a run.- Parameters:
tools- theFunctionToolsinstance containing tool methods
-
addPrompts
Scans the providedFunctionToolsinstance for methods annotated withPrompt, and registers each prompt for use during a run.- Parameters:
tools- theFunctionToolsinstance whose methods will be scanned forPromptannotations
-
addResources
Scans the providedFunctionToolsinstance for methods annotated withResource, and registers each resource for use during a run.This method inspects the given class instance to register executable resource utilities that can be dynamically called by the AI model during generation processes.
- Parameters:
tools- theFunctionToolsinstance whose methods will be scanned for resource annotations
-
setProjectDir
Sets the working directory for the provider, which may be used by tool handlers.- Parameters:
projectDir- the project directory
-
setErrorHandling
void setErrorHandling(boolean errorHandling) Configures whether tool invocation errors should be returned to the model for conversational recovery or propagated as exceptions.- Parameters:
errorHandling-trueto return tool errors as response text;falseto propagate them immediately
-
setEnabledTools
Configures the list of tool names that are enabled and allowed to be used by the AI provider.If the specified array is
nullor empty, all registered tools are typically enabled by default. Only tools whose identifiers are present in this collection will be active during provider execution.- Parameters:
tools- the array of unique tool names to enable; ifnullor empty, all tools are enabled
-