Package org.machanism.machai.ai.provider
Interface Genai
- All Known Implementing Classes:
AbstractAIProvider,AnthropicProvider,CodeMieProvider,GenaiAdapter,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 functionTool) Scans the providedFunctionToolsinstance for methods annotated withPrompt, and registers each prompt 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.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.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
-
inputsLog
Enables logging of provider inputs to the given directory.- Parameters:
bindexTempDir- directory used for writing log files
-
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:
functionTool- theFunctionToolsinstance whose methods will be scanned forPromptannotations
-
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
-