Interface GenerativeAIFunctionRequest


@Experimental public interface GenerativeAIFunctionRequest
An object performing a generative AI request with a list of pre-registered functions.
Since:
5.2.250908
  • Method Details

    • addFunction

      void addFunction(@NotNull @NotNull Function function, @NotNull @NotNull GenerativeAIFunction callback)
      Registers a new function to be used for this generative AI request operation.
      Parameters:
      function - The definition of the function.
      callback - The callback for any invocation during a request.
      Throws:
      IllegalArgumentException - If a function with the name already exists.
      Since:
      5.2.250908
    • request

      @NotNull @NotNull Response request(@NotNull @NotNull Request request) throws IOException
      Performs a non-streamed request using the configured functions. This method will automatically perform any FunctionCall and send back the results to the generative AI. The return value of this method is the final response after the AI received the functions results. The TokenUsage contained in the response includes the token usages of all preceding requests.
      Parameters:
      request - The request descriptor.
      Returns:
      The final response of the AI request.
      Throws:
      IOException - If the request failed for some reason.
      Since:
      5.2.250908
    • request

      @NotNull default @NotNull Optional<String> request(@NotNull @NotNull String prompt) throws IOException
      Convenient method for performing a non-streamed text-based user prompt. Behaves the same as request(Request) regarding function evaluation.
      Parameters:
      prompt - The user prompt to be sent.
      Returns:
      The response text, if available.
      Throws:
      IOException - If the request failed for some reason.
      Since:
      5.2.250908
    • evaluate

      @NotNull @NotNull GenerativeAIFunctionRequest.EvaluatedResponse evaluate(@NotNull @NotNull Request request) throws IOException
      Performs a non-streamed request using the configured functions. This method only performs a single AI request using the given prompt. It's the callers responsibility to process the evaluated response accordingly.

      NOTE: The stepwise evaluation of functions is currently not supported when using both client and serverside functions. Therefore, a request with AllowedServerFunction will behave like request(Request), as the function evaluation and follow-up requests are handled on the serverside.

      Parameters:
      request - The request descriptor.
      Returns:
      The completions response for the 1st AI request.
      Throws:
      IOException - If the request failed for some reason.
      Since:
      5.2.250908
    • openStream

      @NotNull @NotNull ResponseStream openStream(@NotNull @NotNull Request request) throws IOException
      Performs a streamed request using the configured functions. This method will automatically perform any FunctionCall and send back the results to the generative AI. The return value of this method is the final ResponseStream after the AI received the functions results. The TokenUsage contained in the response chunks include the token usages of all preceding requests.
      Parameters:
      request - The request descriptor.
      Returns:
      The final response of the AI request.
      Throws:
      IOException - If the request failed for some reason.
      Since:
      5.2.250908
    • evaluateStream

      @NotNull @NotNull GenerativeAIFunctionRequest.EvaluatedResponseStream evaluateStream(@NotNull @NotNull Request request) throws IOException
      Performs a streamed request using the configured functions. This method only performs a single AI request using the given prompt. It's the callers responsibility to process the evaluated response accordingly.

      NOTE: The stepwise evaluation of functions is currently not supported when using both client and serverside functions. Therefore, a request with AllowedServerFunction will behave like request(Request), as the function evaluation and follow-up requests are handled on the serverside.

      Parameters:
      request - The request descriptor.
      Returns:
      The completions response for the 1st AI request.
      Throws:
      IOException - If the request failed for some reason.
      Since:
      5.2.250908