@@ -88,47 +88,33 @@ public HttpDestination getBaseDestination()
8888 }
8989
9090 /**
91- * Get a new endpoint object, targeting a specific deployment ID.
91+ * Get a destination to perform inference calls against a deployment under the default resource
92+ * group on AI Core.
9293 *
93- * @param deploymentId The deployment id to be used for the new endpoint.
94- * @return the new instance.
95- */
96- @ Nonnull
97- public HttpDestination getDestinationForDeploymentById (
98- @ Nonnull final String resourceGroup , @ Nonnull final String deploymentId ) {
99- return toInferenceDestination (resourceGroup , deploymentId );
100- }
101-
102- /**
103- * Get a destination to perform inference calls for a specific model. If there are multiple
104- * deployments of the same model, the first one is returned.
105- *
106- * @param model The model to be used for inference calls.
107- * @return A new instance of the AI Core Deployment.
108- * @throws DeploymentResolutionException if no running deployment is found for the model.
94+ * @return The destination pointing to the specific deployment ID.
95+ * @throws DestinationAccessException If there was an issue creating the base destination, e.g. in
96+ * case of invalid credentials.
97+ * @throws DestinationNotFoundException If there was an issue creating the base destination, e.g.
98+ * in case of missing credentials.
99+ * @see #getInferenceDestination(String) for specifying a custom resource group.
109100 */
110101 @ Nonnull
111- public HttpDestination getDestinationForDeploymentByModel (
112- @ Nonnull final String resourceGroup , @ Nonnull final AiModel model )
113- throws DeploymentResolutionException {
114- val deploymentId = deploymentResolver .getDeploymentIdByModel (resourceGroup , model );
115- return toInferenceDestination (resourceGroup , deploymentId );
102+ public InferenceDestinationBuilder getInferenceDestination ()
103+ throws DestinationAccessException , DestinationNotFoundException {
104+ return new InferenceDestinationBuilder (DEFAULT_RESOURCE_GROUP );
116105 }
117106
118107 /**
119- * Set a specific deployment by scenario id. If there are multiple deployments of the same model,
120- * the first one is returned .
108+ * Get a destination to perform inference calls against a deployment for the given resource group
109+ * on AI Core .
121110 *
122- * @param scenarioId The scenario id to be used for AI Core service calls .
123- * @return A new instance of the AI Core Deployment .
124- * @throws DeploymentResolutionException if no running deployment is found for the scenario .
111+ * @param resourceGroup The resource group to be used for the new endpoint .
112+ * @return The destination pointing to the specific deployment ID .
113+ * @see #getInferenceDestination() for using the default resource group .
125114 */
126115 @ Nonnull
127- public HttpDestination getDestinationForDeploymentByScenario (
128- @ Nonnull final String resourceGroup , @ Nonnull final String scenarioId )
129- throws DeploymentResolutionException {
130- val deploymentId = deploymentResolver .getDeploymentIdByScenario (resourceGroup , scenarioId );
131- return toInferenceDestination (resourceGroup , deploymentId );
116+ public InferenceDestinationBuilder getInferenceDestination (@ Nonnull final String resourceGroup ) {
117+ return new InferenceDestinationBuilder (resourceGroup );
132118 }
133119
134120 /**
@@ -159,17 +145,6 @@ public ApiClient getApiClient() {
159145 return new ApiClient (rt ).setBasePath (destination .asHttp ().getUri ().toString ());
160146 }
161147
162- HttpDestination toInferenceDestination (
163- @ Nonnull final String resourceGroup , @ Nonnull final String deploymentId ) {
164- val destination = getBaseDestination ();
165- val path = buildDeploymentPath (deploymentId );
166-
167- return DefaultHttpDestination .fromDestination (destination )
168- .uri (destination .getUri ().resolve (path ))
169- .property (RESOURCE_GROUP_HEADER_PROPERTY , resourceGroup )
170- .build ();
171- }
172-
173148 /**
174149 * Helper method to build the <b>relative</b> URL path for the inference endpoint of a deployment.
175150 * The result of this together with the base path defined on the destination will be used for
@@ -195,4 +170,73 @@ protected String buildDeploymentPath(@Nonnull final String deploymentId) {
195170 public void reloadCachedDeployments (@ Nonnull final String resourceGroup ) {
196171 deploymentResolver .reloadDeployments (resourceGroup );
197172 }
173+
174+ /** Builder for creating inference destinations. */
175+ @ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
176+ public class InferenceDestinationBuilder {
177+ @ Nonnull private final String resourceGroup ;
178+
179+ /**
180+ * Use a fixed deployment ID to identify the deployment.
181+ *
182+ * @param deploymentId The ID of the deployment to target.
183+ * @return A new destination targeting the specified deployment.
184+ * @throws DestinationAccessException If there was an issue creating the base destination, e.g.
185+ * in case of invalid credentials.
186+ * @throws DestinationNotFoundException If there was an issue creating the base destination,
187+ * e.g. in case of missing credentials.
188+ * @see #forModel(AiModel)
189+ * @see #forScenario(String)
190+ */
191+ @ Nonnull
192+ public HttpDestination usingDeploymentId (@ Nonnull final String deploymentId )
193+ throws DestinationAccessException , DestinationNotFoundException {
194+ return build (deploymentId );
195+ }
196+
197+ /**
198+ * Lookup a deployment based on the given {@link AiModel}. If there are multiple deployments for
199+ * the given model, the first one is returned.
200+ *
201+ * @param model The model to be used for inference calls.
202+ * @return A new destination targeting a deployment for the given model.
203+ * @throws DeploymentResolutionException If no running deployment is found for the model.
204+ * @see #forScenario(String)
205+ * @see #usingDeploymentId(String)
206+ */
207+ @ Nonnull
208+ public HttpDestination forModel (@ Nonnull final AiModel model )
209+ throws DeploymentResolutionException {
210+ val id = deploymentResolver .getDeploymentIdByModel (resourceGroup , model );
211+ return build (id );
212+ }
213+
214+ /**
215+ * Lookup a deployment based on the given scenario. If there are multiple deployments within the
216+ * same scenario, the first one is returned.
217+ *
218+ * @param scenarioId The scenario to discover deployments for.
219+ * @return A new destination targeting a deployment within the given scenario.
220+ * @throws DeploymentResolutionException If no running deployment is found within the scenario.
221+ * @see #forModel(AiModel)
222+ * @see #usingDeploymentId(String)
223+ */
224+ @ Nonnull
225+ public HttpDestination forScenario (@ Nonnull final String scenarioId )
226+ throws DeploymentResolutionException {
227+ val id = deploymentResolver .getDeploymentIdByScenario (resourceGroup , scenarioId );
228+ return build (id );
229+ }
230+
231+ @ Nonnull
232+ HttpDestination build (@ Nonnull final String deploymentId ) {
233+ val destination = getBaseDestination ();
234+ val path = buildDeploymentPath (deploymentId );
235+
236+ return DefaultHttpDestination .fromDestination (destination )
237+ .uri (destination .getUri ().resolve (path ))
238+ .property (RESOURCE_GROUP_HEADER_PROPERTY , resourceGroup )
239+ .build ();
240+ }
241+ }
198242}
0 commit comments