Skip to content

Commit 08810c1

Browse files
committed
Migrate from public static factory method to constructor
1 parent 1bda813 commit 08810c1

File tree

3 files changed

+23
-40
lines changed

3 files changed

+23
-40
lines changed

grounding/src/main/java/com/sap/ai/sdk/grounding/GroundingClient.java

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,36 @@
66
import com.sap.ai.sdk.grounding.api.VectorApi;
77
import javax.annotation.Nonnull;
88
import lombok.AccessLevel;
9+
import lombok.Getter;
910
import lombok.RequiredArgsConstructor;
11+
import lombok.experimental.Tolerate;
1012

1113
/**
1214
* Service class for the Grounding APIs.
1315
*
1416
* @since 1.3.0
1517
*/
16-
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
18+
@RequiredArgsConstructor(access = AccessLevel.PUBLIC)
19+
@Getter(value = AccessLevel.PROTECTED)
1720
public class GroundingClient {
18-
19-
final AiCoreService aiCoreService;
20-
final String basePath;
21+
@Nonnull private final AiCoreService service;
22+
@Nonnull private final String basePath;
2123

2224
static final String DEFAULT_BASE_PATH = "lm/document-grounding/";
2325

24-
/**
25-
* Create a new instance of the GroundingService.
26-
*
27-
* @return A new instance of the GroundingService.
28-
*/
29-
@Nonnull
30-
public static GroundingClient create() {
31-
return create(new AiCoreService());
32-
}
33-
34-
/**
35-
* Create a new instance of the GroundingService.
36-
*
37-
* @param aiCoreService The AiCoreService instance to use.
38-
* @return A new instance of the GroundingService.
39-
*/
40-
@Nonnull
41-
public static GroundingClient create(@Nonnull final AiCoreService aiCoreService) {
42-
return create(aiCoreService, DEFAULT_BASE_PATH);
26+
/** Default constructor. */
27+
@Tolerate
28+
public GroundingClient() {
29+
this(new AiCoreService());
4330
}
4431

4532
/**
46-
* Create a new instance of the GroundingService.
33+
* Constructor with custom AI Core service instance.
4734
*
48-
* @param aiCoreService The AiCoreService instance to use.
49-
* @param basePath The base path to use for the API calls.
50-
* @return A new instance of the GroundingService.
35+
* @param service The instance of AI Core service
5136
*/
52-
@Nonnull
53-
public static GroundingClient create(
54-
@Nonnull final AiCoreService aiCoreService, @Nonnull final String basePath) {
55-
return new GroundingClient(aiCoreService, basePath);
37+
public GroundingClient(final @Nonnull AiCoreService service) {
38+
this(service, DEFAULT_BASE_PATH);
5639
}
5740

5841
/**
@@ -62,7 +45,7 @@ public static GroundingClient create(
6245
*/
6346
@Nonnull
6447
public PipelinesApi pipelines() {
65-
return new PipelinesApi(aiCoreService.getApiClient().setBasePath(basePath));
48+
return new PipelinesApi(getService().getApiClient().setBasePath(getBasePath()));
6649
}
6750

6851
/**
@@ -72,7 +55,7 @@ public PipelinesApi pipelines() {
7255
*/
7356
@Nonnull
7457
public VectorApi vector() {
75-
return new VectorApi(aiCoreService.getApiClient().setBasePath(basePath));
58+
return new VectorApi(getService().getApiClient().setBasePath(getBasePath()));
7659
}
7760

7861
/**
@@ -82,6 +65,6 @@ public VectorApi vector() {
8265
*/
8366
@Nonnull
8467
public RetrievalApi retrieval() {
85-
return new RetrievalApi(aiCoreService.getApiClient().setBasePath(basePath));
68+
return new RetrievalApi(getService().getApiClient().setBasePath(getBasePath()));
8669
}
8770
}

grounding/src/test/java/com/sap/ai/sdk/grounding/GroundingClientTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GroundingClientTest {
3333

3434
@Test
3535
void testPipelines() {
36-
final PipelinesApi api = GroundingClient.create(SERVICE).pipelines();
36+
final PipelinesApi api = new GroundingClient(SERVICE).pipelines();
3737

3838
final Pipelines allPipelines = api.getAllPipelines("reosurceGroup");
3939
assertThat(allPipelines).isNotNull();
@@ -42,7 +42,7 @@ void testPipelines() {
4242

4343
@Test
4444
void testVector() {
45-
final VectorApi api = GroundingClient.create(SERVICE).vector();
45+
final VectorApi api = new GroundingClient(SERVICE).vector();
4646

4747
final CollectionsListResponse collections = api.getAllCollections("reosurceGroup");
4848
assertThat(collections).isNotNull();
@@ -107,7 +107,7 @@ void testVector() {
107107

108108
@Test
109109
void testRetrieval() {
110-
final RetrievalApi api = GroundingClient.create(SERVICE).retrieval();
110+
final RetrievalApi api = new GroundingClient(SERVICE).retrieval();
111111

112112
DataRepositories repositories = api.getDataRepositories("reosurceGroup");
113113
assertThat(repositories).isNotNull();

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/GroundingController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
@RequestMapping("/grounding")
4646
class GroundingController {
4747

48-
private static final PipelinesApi CLIENT_PIPELINES = GroundingClient.create().pipelines();
49-
private static final RetrievalApi CLIENT_RETRIEVAL = GroundingClient.create().retrieval();
50-
private static final VectorApi CLIENT_VECTOR = GroundingClient.create().vector();
48+
private static final PipelinesApi CLIENT_PIPELINES = new GroundingClient().pipelines();
49+
private static final RetrievalApi CLIENT_RETRIEVAL = new GroundingClient().retrieval();
50+
private static final VectorApi CLIENT_VECTOR = new GroundingClient().vector();
5151
private static final String RESOURCE_GROUP = "ai-sdk-java-e2e";
5252

5353
/**

0 commit comments

Comments
 (0)