Package com.sap.ai.sdk.orchestration
Class OrchestrationClient
java.lang.Object
com.sap.ai.sdk.orchestration.OrchestrationClient
Client to execute requests to the orchestration service.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.OrchestrationClient(com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination destination) Constructor with a custom destination, allowing for a custom resource group or otherwise custom destination. -
Method Summary
Modifier and TypeMethodDescriptionchatCompletion(OrchestrationPrompt prompt, OrchestrationModuleConfig config, OrchestrationModuleConfig... fallbackConfigs) Generate a completion for the given prompt.Generate a completion using a referenced Orchestration config.embed(EmbeddingsPostRequest request) Generates embeddings using the low-level API request.embed(OrchestrationEmbeddingRequest request) Generate embeddings for aOrchestrationEmbeddingRequestrequest.executeRequest(CompletionPostRequest request) Serializes the given request, executes it and deserializes the response.executeRequestFromJsonModuleConfig(OrchestrationPrompt prompt, String moduleConfig) Perform a request to the orchestration service using a module configuration provided as JSON string.streamChatCompletion(OrchestrationPrompt prompt, OrchestrationModuleConfig config, OrchestrationModuleConfig... fallbackConfigs) Generate a completion for the given prompt.Generate a completion for the given prompt.toCompletionPostRequest(OrchestrationPrompt prompt, OrchestrationModuleConfig config, OrchestrationModuleConfig... fallbackConfigs) Convert the given prompt and config into a low-level request data object.withHeader(String key, String value) Create a new orchestration client with a custom header added to every call made with this client
-
Constructor Details
-
OrchestrationClient
public OrchestrationClient()Default constructor. -
OrchestrationClient
public OrchestrationClient(@Nonnull com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination destination) Constructor with a custom destination, allowing for a custom resource group or otherwise custom destination. The destination needs to be configured with a URL pointing to an orchestration service deployment. Typically, such a destination should be obtained usingAiCoreService.getInferenceDestination(String).Example:
new OrchestrationClient(new AiCoreService().getInferenceDestination("custom-rg").forScenario("orchestration"));- Parameters:
destination- The specificHttpDestinationto use.- See Also:
-
-
Method Details
-
toCompletionPostRequest
@Nonnull public static CompletionRequestConfiguration toCompletionPostRequest(@Nonnull OrchestrationPrompt prompt, @Nonnull OrchestrationModuleConfig config, @Nonnull OrchestrationModuleConfig... fallbackConfigs) Convert the given prompt and config into a low-level request data object. The data object allows for further customization before sending the request.- Parameters:
prompt- TheOrchestrationPromptto generate a completion for.config- TheOrchestrationConfigconfiguration to use for the completion.fallbackConfigs- Fallback configurations to use.- Returns:
- The low-level request data object to send to orchestration.
-
chatCompletion
@Nonnull public OrchestrationChatResponse chatCompletion(@Nonnull OrchestrationPrompt prompt, @Nonnull OrchestrationModuleConfig config, @Nonnull OrchestrationModuleConfig... fallbackConfigs) throws OrchestrationClientException Generate a completion for the given prompt.- Parameters:
prompt- TheOrchestrationPromptto send to orchestration.config- the configuration to usefallbackConfigs- fallback configurations- Returns:
- the completion output
- Throws:
OrchestrationClientException- if the request fails.
-
streamChatCompletion
@Nonnull public Stream<String> streamChatCompletion(@Nonnull OrchestrationPrompt prompt, @Nonnull OrchestrationModuleConfig config, @Nonnull OrchestrationModuleConfig... fallbackConfigs) throws OrchestrationClientException Generate a completion for the given prompt.- Parameters:
prompt- a text message.config- the configuration to usefallbackConfigs- fallback configurations- Returns:
- a stream of message deltas
- Throws:
OrchestrationClientException- if the request fails or if the finish reason is content_filter- Since:
- 1.1.0
-
executeRequest
@Nonnull public CompletionPostResponse executeRequest(@Nonnull CompletionPostRequest request) throws OrchestrationClientException Serializes the given request, executes it and deserializes the response.Override this method to customize the request execution. For example, to modify the request object before it is sent, use:
@Override protected CompletionPostResponse executeRequest(@Nonnull CompletionPostRequest request) { request.setCustomField("myField", "myValue"); return super.executeRequest(request); }Alternatively, you can call this method directly with a fully custom request object.
- Parameters:
request- The request data object to send to orchestration.- Returns:
- The response data object from orchestration.
- Throws:
OrchestrationClientException- If the request fails.
-
chatCompletionUsingReference
@Beta @Nonnull public OrchestrationChatResponse chatCompletionUsingReference(@Nonnull OrchestrationConfigReference reference) Generate a completion using a referenced Orchestration config.- Parameters:
reference- A reference to an Orchestration config stored in prompt registry- Returns:
- The completion output
- Since:
- 1.15.0
-
executeRequestFromJsonModuleConfig
@Beta @Nonnull public OrchestrationChatResponse executeRequestFromJsonModuleConfig(@Nonnull OrchestrationPrompt prompt, @Nonnull String moduleConfig) throws OrchestrationClientException Perform a request to the orchestration service using a module configuration provided as JSON string. This can be useful when building a configuration in the AI Launchpad UI and exporting it as JSON. Furthermore, this allows for using features that are not yet supported natively by the API.NOTE: This method does not support streaming.
- Parameters:
prompt- The input parameters and optionally message history to use for prompt execution.moduleConfig- The module configuration in JSON format.- Returns:
- The completion response.
- Throws:
OrchestrationClientException- If the request fails.
-
streamChatCompletionDeltas
@Nonnull public Stream<OrchestrationChatCompletionDelta> streamChatCompletionDeltas(@Nonnull CompletionRequestConfiguration request) throws OrchestrationClientException Generate a completion for the given prompt.- Parameters:
request- the prompt, including messages and other parameters.- Returns:
- A stream of chat completion delta elements.
- Throws:
OrchestrationClientException- if the request fails- Since:
- 1.1.0
-
embed
@Nonnull public OrchestrationEmbeddingResponse embed(@Nonnull OrchestrationEmbeddingRequest request) throws OrchestrationClientException Generate embeddings for aOrchestrationEmbeddingRequestrequest.- Parameters:
request- the request containing the input text and other parameters.- Returns:
- the response containing the embeddings.
- Throws:
OrchestrationClientException- if the request fails- Since:
- 1.12.0
-
embed
@Nonnull public EmbeddingsPostResponse embed(@Nonnull EmbeddingsPostRequest request) throws OrchestrationClientException Generates embeddings using the low-level API request.This method provides direct access to the underlying API for advanced use cases. For most scenarios, prefer
embed(OrchestrationEmbeddingRequest).- Parameters:
request- the low-level API request- Returns:
- the low level response object
- Throws:
OrchestrationClientException- if the request fails- Since:
- 1.12.0
- See Also:
-
withHeader
Create a new orchestration client with a custom header added to every call made with this client- Parameters:
key- the key of the custom header to addvalue- the value of the custom header to add- Returns:
- a new client.
- Since:
- 1.11.0
-