Interface AiClient

All Known Implementing Classes:
GeminiAdapter, LlamaCppAdapter, OllamaAdapter, OpenAiAdapter

public interface AiClient
AI Client adapter interface.

This interface defines the underlying AI Standard contract for model service communication. It will be various specific AI Model API(For example OpenAI、Gemini、Ollama、Llama.cpp)abstracted into unified methods, This enables upper-layer engines and agents to focus on business logic without caring about underlying network communication and protocol differences.

  • Method Details

    • generate

      Response generate(PromptContext ctx, AiClientConfig config) throws AiSpectException
      Generates a single response in a blocking manner.

      The client will report to the underlying AI The model sends the prompt context and waits for the complete calculation result. Suitable for non-streaming scenarios where the final result needs to be obtained in one go.

      Parameters:
      ctx - Prompt context of the current request, including system prompts, historical messages, etc.
      config - Configuration parameters requested by the client, such as model name, temperature, maximum Token Count and so on
      Returns:
      Full response generated by the model Response
      Throws:
      AiSpectException - Thrown when the network request fails, times out, or the model service returns an exception status code
    • streamGenerate

      Stream<Response> streamGenerate(PromptContext ctx, AiClientConfig config) throws AiSpectException
      via streaming (Server-Sent Events mode) generates a response.

      The client will continue to receive partial results generated by the model in the form of a stream. The stream will be terminated when the model has been generated or the connection is interrupted. Ideal for chat applications or long text generation scenarios that require a real-time "typewriter" output experience.

      Parameters:
      ctx - Prompt context of the current request, including system prompts, historical messages, etc.
      config - Configuration parameters requested by the client (make sure to declare stream=true)
      Returns:
      Include Response Sequential flow of data blocks, automatically closed when receiving the terminator
      Throws:
      AiSpectException - Thrown when the streaming request initialization fails or a connection error occurs