Skip to content

Commit a039890

Browse files
deekshas8cloud-sdk-jsZhongpinWang
authored
feat: Add grounding convenience function (#378)
* grounding convenience * review + tests+ changeset * lint * restructure types * fix: Changes from lint * add type test * fix: Changes from lint * docs * fix: Changes from lint * Apply suggestions from code review * review * review * fix: Changes from lint * update type DocumentGroundingServiceFilter * fix: Changes from lint * docs review * fix: Changes from lint * Apply suggestions from code review * adjust sample for grounding * fix: Changes from lint --------- Co-authored-by: cloud-sdk-js <[email protected]> Co-authored-by: Zhongpin Wang <[email protected]>
1 parent b65e38b commit a039890

File tree

9 files changed

+329
-181
lines changed

9 files changed

+329
-181
lines changed

.changeset/shiny-brooms-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ai-sdk/orchestration': minor
3+
---
4+
5+
[Improvement] Add `buildDocumentGroundingConfig()` convenience function to create document grounding configuration in the Orchestration client.

packages/orchestration/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ return response.getContent();
330330
### Grounding
331331

332332
Grounding enables integrating external, contextually relevant, domain-specific, or real-time data into AI processes.
333+
The grounding configuration can be provided as a raw JSON object or by using the `buildDocumentGroundingConfig()` function, which requires only the minimal mandatory values.
333334

334335
```ts
335336
const orchestrationClient = new OrchestrationClient({
@@ -346,21 +347,16 @@ const orchestrationClient = new OrchestrationClient({
346347
],
347348
defaults: {}
348349
},
349-
grounding: {
350-
type: 'document_grounding_service',
351-
config: {
352-
filters: [
350+
grounding: buildDocumentGroundingConfig(
351+
input_params: ['groundingRequest'],
352+
output_param: 'groundingOutput',
353+
filters: [
353354
{
354355
id: 'filter1',
355-
data_repositories: ['*'],
356-
search_config: {},
357-
data_repository_type: 'vector'
356+
data_repositories: ['repository-id']
358357
}
359358
],
360-
input_params: ['groundingRequest'],
361-
output_param: 'groundingOutput'
362-
}
363-
}
359+
)
364360
});
365361

366362
const response = await orchestrationClient.chatCompletion({

packages/orchestration/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export type {
4242
OrchestrationModuleConfig,
4343
LlmModuleConfig,
4444
Prompt,
45+
DocumentGroundingServiceConfig,
46+
DocumentGroundingServiceFilter,
4547
LlmModelParams
4648
} from './orchestration-types.js';
4749

4850
export { OrchestrationClient } from './orchestration-client.js';
4951

50-
export { buildAzureContentFilter } from './orchestration-utils.js';
52+
export {
53+
buildAzureContentFilter,
54+
buildDocumentGroundingConfig
55+
} from './orchestration-utils.js';
5156

5257
export { OrchestrationResponse } from './orchestration-response.js';
5358

packages/orchestration/src/orchestration-completion-post-request.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { constructCompletionPostRequest } from './orchestration-client.js';
22
import { buildAzureContentFilter } from './orchestration-utils.js';
3-
import type { CompletionPostRequest } from './client/api/schema';
3+
import type { CompletionPostRequest } from './client/api/schema/index.js';
44
import type { OrchestrationModuleConfig } from './orchestration-types.js';
55

66
describe('construct completion post request', () => {

packages/orchestration/src/orchestration-types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { ChatModel } from './model-types.js';
22
import type {
33
ChatMessages,
4+
DataRepositoryType,
5+
DocumentGroundingFilter,
46
FilteringModuleConfig,
57
GroundingModuleConfig,
68
MaskingModuleConfig,
@@ -69,3 +71,36 @@ export interface OrchestrationModuleConfig {
6971
*/
7072
grounding?: GroundingModuleConfig;
7173
}
74+
75+
/**
76+
* Represents a filter configuration for the Document Grounding Service.
77+
*/
78+
export type DocumentGroundingServiceFilter = Omit<
79+
DocumentGroundingFilter,
80+
'data_repository_type'
81+
> & {
82+
/**
83+
* Defines the type of data repository.
84+
* If not set, the default value is 'vector'.
85+
*/
86+
data_repository_type?: DataRepositoryType;
87+
};
88+
89+
/**
90+
* Represents the configuration for the Document Grounding Service.
91+
*/
92+
export interface DocumentGroundingServiceConfig {
93+
/**
94+
* Defines the filters to apply during the grounding process.
95+
*/
96+
filters?: DocumentGroundingServiceFilter[];
97+
/**
98+
* Contains the input parameters used for grounding input questions.
99+
*/
100+
input_params: string[];
101+
/**
102+
* Parameter name used for grounding output.
103+
* @example "groundingOutput"
104+
*/
105+
output_param: string;
106+
}

0 commit comments

Comments
 (0)