Package org.machanism.machai.ai.provider
Interface Genai
- All Known Implementing Classes:
ClaudeProvider,CodeMieProvider,GeminiProvider,GenaiAdapter,NoneProvider,OpenAIProvider
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,
- computing embedding vectors,
- 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringLine separator used when composing prompts.static final StringConfiguration property name indicating whether provider inputs should be logged.static final StringParagraph separator used when composing prompts.static final StringEnvironment variable name for authenticating with the GenAI provider.static final StringConfiguration property name for the target GenAI server identifier.static final StringEnvironment variable name for authenticating with the GenAI provider. -
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.voidsetWorkingDir(File workingDir) Configures the working directory used for file and tool operations.usage()Returns token usage metrics for the most recentperform()invocation.
-
Field Details
-
LOG_INPUTS_PROP_NAME
Configuration property name indicating whether provider inputs should be logged.- See Also:
-
SERVERID_PROP_NAME
Configuration property name for the target GenAI server identifier.- See Also:
-
USERNAME_PROP_NAME
Environment variable name for authenticating with the GenAI provider.- See Also:
-
PASSWORD_PROP_NAME
Environment variable name for authenticating with the GenAI provider.- See Also:
-
LINE_SEPARATOR
Line separator used when composing prompts.- See Also:
-
PARAGRAPH_SEPARATOR
Paragraph separator used when composing prompts.- See Also:
-
-
Method Details
-
init
Initializes the provider with application configuration.- Parameters:
conf- configuration source
-
prompt
Adds a user prompt to the current session.- Parameters:
text- the prompt text
-
embedding
Computes an embedding vector for the provided text.- Parameters:
text- the input textdimensions- desired embedding dimensionality (provider-specific)- Returns:
- the embedding vector
-
clear
void clear()Clears any stored files and session/provider state. -
addTool
Registers a custom tool function that the provider may invoke at runtime.The expected argument structure passed to
functionis provider-specific.- 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
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
-
inputsLog
Enables logging of provider inputs to the given directory.- Parameters:
bindexTempDir- directory used for writing log files
-
setWorkingDir
Configures the working directory used for file and tool operations.- Parameters:
workingDir- the working directory
-
usage
Usage usage()Returns token usage metrics for the most recentperform()invocation.- Returns:
- usage metrics; implementations may return zero values if not supported
-