@@ -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 /**
@@ -160,17 +146,6 @@ public ApiClient getApiClient() {
160146 return new ApiClient (rt ).setBasePath (destination .asHttp ().getUri ().toString ());
161147 }
162148
163- HttpDestination toInferenceDestination (
164- @ Nonnull final String resourceGroup , @ Nonnull final String deploymentId ) {
165- val destination = getBaseDestination ();
166- val path = buildDeploymentPath (deploymentId );
167-
168- return DefaultHttpDestination .fromDestination (destination )
169- .uri (destination .getUri ().resolve (path ))
170- .property (RESOURCE_GROUP_HEADER_PROPERTY , resourceGroup )
171- .build ();
172- }
173-
174149 /**
175150 * Helper method to build the <b>relative</b> URL path for the inference endpoint of a deployment.
176151 * The result of this together with the base path defined on the destination will be used for
@@ -196,4 +171,73 @@ protected String buildDeploymentPath(@Nonnull final String deploymentId) {
196171 public void reloadCachedDeployments (@ Nonnull final String resourceGroup ) {
197172 deploymentResolver .reloadDeployments (resourceGroup );
198173 }
174+
175+ /** Builder for creating inference destinations. */
176+ @ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
177+ public class InferenceDestinationBuilder {
178+ @ Nonnull private final String resourceGroup ;
179+
180+ /**
181+ * Use a fixed deployment ID to identify the deployment.
182+ *
183+ * @param deploymentId The ID of the deployment to target.
184+ * @return A new destination targeting the specified deployment.
185+ * @throws DestinationAccessException If there was an issue creating the base destination, e.g.
186+ * in case of invalid credentials.
187+ * @throws DestinationNotFoundException If there was an issue creating the base destination,
188+ * e.g. in case of missing credentials.
189+ * @see #forModel(AiModel)
190+ * @see #forScenario(String)
191+ */
192+ @ Nonnull
193+ public HttpDestination usingDeploymentId (@ Nonnull final String deploymentId )
194+ throws DestinationAccessException , DestinationNotFoundException {
195+ return build (deploymentId );
196+ }
197+
198+ /**
199+ * Lookup a deployment based on the given {@link AiModel}. If there are multiple deployments for
200+ * the given model, the first one is returned.
201+ *
202+ * @param model The model to be used for inference calls.
203+ * @return A new destination targeting a deployment for the given model.
204+ * @throws DeploymentResolutionException If no running deployment is found for the model.
205+ * @see #forScenario(String)
206+ * @see #usingDeploymentId(String)
207+ */
208+ @ Nonnull
209+ public HttpDestination forModel (@ Nonnull final AiModel model )
210+ throws DeploymentResolutionException {
211+ val id = deploymentResolver .getDeploymentIdByModel (resourceGroup , model );
212+ return build (id );
213+ }
214+
215+ /**
216+ * Lookup a deployment based on the given scenario. If there are multiple deployments within the
217+ * same scenario, the first one is returned.
218+ *
219+ * @param scenarioId The scenario to discover deployments for.
220+ * @return A new destination targeting a deployment within the given scenario.
221+ * @throws DeploymentResolutionException If no running deployment is found within the scenario.
222+ * @see #forModel(AiModel)
223+ * @see #usingDeploymentId(String)
224+ */
225+ @ Nonnull
226+ public HttpDestination forScenario (@ Nonnull final String scenarioId )
227+ throws DeploymentResolutionException {
228+ val id = deploymentResolver .getDeploymentIdByScenario (resourceGroup , scenarioId );
229+ return build (id );
230+ }
231+
232+ @ Nonnull
233+ HttpDestination build (@ Nonnull final String deploymentId ) {
234+ val destination = getBaseDestination ();
235+ val path = buildDeploymentPath (deploymentId );
236+
237+ return DefaultHttpDestination .fromDestination (destination )
238+ .uri (destination .getUri ().resolve (path ))
239+ .property (RESOURCE_GROUP_HEADER_PROPERTY , resourceGroup )
240+ .build ();
241+ }
242+ }
199243}
0 commit comments