Package de.espirit.firstspirit.ai
Interface GenerativeAIFunctionRequest
@Experimental
public interface GenerativeAIFunctionRequest
An object performing a generative AI request with a list of pre-registered functions.
- Since:
- 5.2.250908
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Evaluated response of the generative AI, potentially containing function call requests.static interface
Evaluated response stream of the generative AI, potentially containing function call requests.static interface
Information about a specific requested function call. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFunction
(@NotNull Function function, @NotNull GenerativeAIFunction callback) Registers a new function to be used for this generative AI request operation.Performs a non-streamed request using the configured functions.evaluateStream
(@NotNull Request request) Performs a streamed request using the configured functions.@NotNull ResponseStream
openStream
(@NotNull Request request) Performs a streamed request using the configured functions.@NotNull Response
Performs a non-streamed request using the configured functions.Convenient method for performing a non-streamed text-based user prompt.
-
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.- Since:
- 5.2.250908
-
request
Performs a non-streamed request using the configured functions. This method will automatically perform anyFunctionCall
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.- 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 asrequest(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.- 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
Performs a streamed request using the configured functions. This method will automatically perform anyFunctionCall
and send back the results to the generative AI. The return value of this method is the finalResponseStream
after the AI received the functions results.- 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.- 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
-