Class ClaudeProvider
java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
org.machanism.machai.ai.provider.claude.ClaudeProvider
- All Implemented Interfaces:
Genai
Anthropic-backed implementation of MachAI's
Genai abstraction.
This provider adapts the Anthropic Java SDK to MachAI's provider interface. It supports prompting, configuration, and basic usage tracking.
Configuration
chatModel(required): model identifier for Anthropic API (e.g., "claude-3-opus-20240229").ANTHROPIC_API_KEY(required): API key for Anthropic API.ANTHROPIC_BASE_URL(optional): base URL for Anthropic-compatible endpoints. If unset, SDK default is used.GENAI_TIMEOUT(optional): request timeout in seconds. If missing, 0, or negative, SDK default is used.MAX_OUTPUT_TOKENS(optional): maximum number of output tokens. Defaults to 18000L.MAX_TOOL_CALLS(optional): maximum number of tool calls per response. 0 leaves the limit unset.embedding.model(optional): embedding model identifier (not used in this implementation).
- Since:
- 1.1.13
- Author:
- Viktor Tovstyi
-
Field Summary
FieldsFields inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
chatModel, config, embeddingModel, instructions, lastUsage, LOG_SECTION_SEPARATOR, MAX_OUTPUT_TOKENS, maxOutputTokens, maxToolCalls, MCP_PROP_NAME_PREFIX, timeoutSec, workingDirFields 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 voidvoidaddTool(String name, String description, ToolFunction function, String... paramsDesc) Registers a function tool for the current provider instance.protected voidvoidclear()Clears all accumulated inputs for the next request.Requests an embedding vector for the given input text.protected com.anthropic.client.AnthropicClientReturns the underlying Anthropic client.protected voidlogInputsSpec(Writer streamWriter) perform()Executes a request using the currently configured model and accumulated inputs.voidAdds a text prompt to the current request input.Methods inherited from class org.machanism.machai.ai.provider.AbstractAIProvider
getTimeout, init, inputsLog, instructions, isRequiredParameter, logInputs, normalize, safelyInvokeTool, setTimeout, setWorkingDir, usage
-
Field Details
-
ANTHROPIC_API_KEY
- See Also:
-
ANTHROPIC_BASE_URL
- See Also:
-
-
Constructor Details
-
ClaudeProvider
public ClaudeProvider()
-
-
Method Details
-
addMcpServer
protected void addMcpServer()- Specified by:
addMcpServerin classAbstractAIProvider
-
addWebSearch
protected void addWebSearch()- Specified by:
addWebSearchin classAbstractAIProvider
-
prompt
Adds a text prompt to the current request input.- Parameters:
text- the prompt string
-
perform
Executes a request using the currently configured model and accumulated inputs.- Returns:
- the final model response text, or
nullif no text was produced
-
clear
public void clear()Clears all accumulated inputs for the next request. -
addTool
Registers a function tool for the current provider instance. (Not implemented for Claude in this version.)- Parameters:
name- tool function namedescription- tool descriptionfunction- handler callback for tool executionparamsDesc- parameter descriptors
-
embedding
Requests an embedding vector for the given input text. (Not implemented for Claude in this version.)- Parameters:
text- input to embeddimensions- number of dimensions requested from the embedding model- Returns:
- embedding as a list of
doublevalues, or an empty list if not supported
-
getClient
protected com.anthropic.client.AnthropicClient getClient()Returns the underlying Anthropic client.- Returns:
- Anthropic client
-
logInputsSpec
- Specified by:
logInputsSpecin classAbstractAIProvider- Throws:
IOException
-