类 OllamaHttpClient

java.lang.Object
io.agentscope.core.model.OllamaHttpClient

public class OllamaHttpClient extends Object
HTTP client for Ollama API.

This client handles communication with Ollama's chat and embedding APIs. It provides both synchronous and asynchronous (streaming) request capabilities with proper JSON serialization/deserialization and error handling.

Features:

  • Synchronous and streaming request support
  • NDJSON stream parsing for streaming responses
  • Automatic JSON serialization/deserialization with snake_case naming
  • Proper error handling with detailed exception information
  • Configurable base URL and HTTP transport

Default base URL is http://localhost:11434, which is the standard Ollama server address.

  • 字段详细资料

    • DEFAULT_BASE_URL

      public static final String DEFAULT_BASE_URL
      Default base URL for Ollama API.
      另请参阅:
    • CHAT_ENDPOINT

      public static final String CHAT_ENDPOINT
      Chat API endpoint.
      另请参阅:
    • EMBED_ENDPOINT

      public static final String EMBED_ENDPOINT
      Embed API endpoint.
      另请参阅:
  • 构造器详细资料

    • OllamaHttpClient

      public OllamaHttpClient(HttpTransport transport, String baseUrl)
      Create a new OllamaHttpClient.
      参数:
      transport - the HTTP transport to use
      baseUrl - the base URL (null for default)
  • 方法详细资料

    • chat

      public OllamaResponse chat(OllamaRequest request)
      Make a synchronous Chat API call.
      参数:
      request - the Ollama request
      返回:
      the Ollama response
    • embed

      Make a synchronous Embed API call.
      参数:
      request - the Embed request
      返回:
      the Embed response
    • call

      public OllamaResponse call(String endpoint, Object request)
      Make a synchronous API call to specific endpoint.
      参数:
      endpoint - the API endpoint
      request - the request object
      返回:
      the Ollama response
    • call

      public <T> T call(String endpoint, Object request, Class<T> responseType)
      Make a synchronous API call to specific endpoint with custom response type.
      类型参数:
      T - the response type
      参数:
      endpoint - the API endpoint
      request - the request object
      responseType - the response class
      返回:
      the response object
    • stream

      public reactor.core.publisher.Flux<OllamaResponse> stream(OllamaRequest request)
      Make a streaming Chat API call.
      参数:
      request - the Ollama request
      返回:
      a Flux of Ollama responses
    • getBaseUrl

      public String getBaseUrl()
      Get the base URL.
      返回:
      the base URL
    • close

      public void close()
      Close the transport.
    • builder

      public static OllamaHttpClient.Builder builder()
      Create a new builder for OllamaHttpClient.
      返回:
      a new Builder instance