Package org.machanism.machai.ai.provider
Class AbstractAIProvider
java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
- All Implemented Interfaces:
Genai
- Direct Known Subclasses:
ClaudeProvider,OpenAIProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringActive model identifier used inGenai.perform().protected ConfiguratorConfiguration source used to initialize clients and provider features.protected StringEmbedding model identifier used byGenai.embedding(String, long).protected StringOptional instructions applied to the request.protected UsageLatest usage metrics captured from the most recentGenai.perform()call.static final String(package private) static org.slf4j.LoggerLogger instance for this provider.static final longDefault maximum number of tokens the model may generate.protected LongMaximum number of output tokens for responses.protected LongMaximum number of tool calls permitted per response.protected static final Stringprotected LongRequest timeout in seconds;0means SDK defaults are used.protected FileWorking directory passed to tool handlers as contextual information.Fields 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 TypeMethodDescriptionprotected abstract voidprotected abstract voidlongReturns the configured request timeout.voidinit(Configurator config) Initializes the provider from the given configuration.voidEnables request input logging to the given file.voidinstructions(String instructions) Sets system-level instructions applied to subsequent requests.protected booleanisRequiredParameter(String parameterFlag) Determines whether the supplied parameter flag marks a required parameter.protected voidWrites the current request inputs toinputsLogwhen logging is enabled.protected abstract voidlogInputsSpec(Writer streamWriter) protected StringNormalizes a string for case-insensitive comparisons.protected ObjectsafelyInvokeTool(String name, ToolFunction tool, com.fasterxml.jackson.databind.JsonNode params, File workingDir) Safely invokes a tool function and convertsIOExceptions into a textual error payload suitable for the model conversation.voidsetTimeout(long timeout, OpenAIProvider openAIProvider) Sets a request timeout in seconds for new clients created by this provider.voidsetWorkingDir(File workingDir) Sets the working directory passed to tool handlers.usage()Returns token usage metrics captured from the most recentGenai.perform()call.
-
Field Details
-
logger
static org.slf4j.Logger loggerLogger instance for this provider. -
MCP_PROP_NAME_PREFIX
- See Also:
-
MAX_OUTPUT_TOKENS
public static final long MAX_OUTPUT_TOKENSDefault maximum number of tokens the model may generate.- See Also:
-
LOG_SECTION_SEPARATOR
- See Also:
-
chatModel
Active model identifier used inGenai.perform(). -
workingDir
Working directory passed to tool handlers as contextual information. -
timeoutSec
Request timeout in seconds;0means SDK defaults are used. -
lastUsage
Latest usage metrics captured from the most recentGenai.perform()call. -
instructions
Optional instructions applied to the request. -
maxOutputTokens
Maximum number of output tokens for responses. -
maxToolCalls
Maximum number of tool calls permitted per response. -
config
Configuration source used to initialize clients and provider features. -
embeddingModel
Embedding model identifier used byGenai.embedding(String, long).
-
-
Constructor Details
-
AbstractAIProvider
public AbstractAIProvider()
-
-
Method Details
-
init
Initializes the provider from the given configuration. -
addMcpServer
protected abstract void addMcpServer() -
addWebSearch
protected abstract void addWebSearch() -
normalize
Normalizes a string for case-insensitive comparisons.- Parameters:
value- source value- Returns:
- lower-cased value, or an empty string when the input is
null
-
safelyInvokeTool
protected Object safelyInvokeTool(String name, ToolFunction tool, com.fasterxml.jackson.databind.JsonNode params, File workingDir) Safely invokes a tool function and convertsIOExceptions into a textual error payload suitable for the model conversation.- Parameters:
name- tool nametool- tool handlerparams- parsed tool parametersworkingDir- working directory passed to the tool- Returns:
- tool output or a formatted error message
-
logInputs
protected void logInputs()Writes the current request inputs toinputsLogwhen logging is enabled. -
logInputsSpec
- Throws:
IOException
-
isRequiredParameter
Determines whether the supplied parameter flag marks a required parameter.- Parameters:
parameterFlag- descriptor flag value- Returns:
truewhen the flag equalsrequired, ignoring case
-
instructions
Sets system-level instructions applied to subsequent requests.- Specified by:
instructionsin interfaceGenai- Parameters:
instructions- instruction text, ornullto clear
-
inputsLog
Enables request input logging to the given file. -
setWorkingDir
Sets the working directory passed to tool handlers.- Specified by:
setWorkingDirin interfaceGenai- Parameters:
workingDir- working directory, ornull
-
usage
Returns token usage metrics captured from the most recentGenai.perform()call. -
getTimeout
public long getTimeout()Returns the configured request timeout.- Returns:
- timeout in seconds;
0indicates the SDK default
-
setTimeout
Sets a request timeout in seconds for new clients created by this provider.- Parameters:
timeout- timeout in seconds; use0to use SDK defaults
-