Class ClaudeProvider

java.lang.Object
org.machanism.machai.ai.provider.AbstractAIProvider
org.machanism.machai.ai.provider.claude.ClaudeProvider
All Implemented Interfaces:
Genai

public class ClaudeProvider extends AbstractAIProvider
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 Details

  • Constructor Details

    • ClaudeProvider

      public ClaudeProvider()
  • Method Details

    • addMcpServer

      protected void addMcpServer()
      Specified by:
      addMcpServer in class AbstractAIProvider
    • addWebSearch

      protected void addWebSearch()
      Specified by:
      addWebSearch in class AbstractAIProvider
    • prompt

      public void prompt(String text)
      Adds a text prompt to the current request input.
      Parameters:
      text - the prompt string
    • perform

      public String perform()
      Executes a request using the currently configured model and accumulated inputs.
      Returns:
      the final model response text, or null if no text was produced
    • clear

      public void clear()
      Clears all accumulated inputs for the next request.
    • addTool

      public void addTool(String name, String description, ToolFunction function, String... paramsDesc)
      Registers a function tool for the current provider instance. (Not implemented for Claude in this version.)
      Parameters:
      name - tool function name
      description - tool description
      function - handler callback for tool execution
      paramsDesc - parameter descriptors
    • embedding

      public List<Double> embedding(String text, long dimensions)
      Requests an embedding vector for the given input text. (Not implemented for Claude in this version.)
      Parameters:
      text - input to embed
      dimensions - number of dimensions requested from the embedding model
      Returns:
      embedding as a list of double values, or an empty list if not supported
    • getClient

      protected com.anthropic.client.AnthropicClient getClient()
      Returns the underlying Anthropic client.
      Returns:
      Anthropic client
    • logInputsSpec

      protected void logInputsSpec(Writer streamWriter) throws IOException
      Specified by:
      logInputsSpec in class AbstractAIProvider
      Throws:
      IOException