Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add grounding convenience function #378

Merged
merged 28 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
555a5cc
grounding convenience
deekshas8 Dec 17, 2024
61dcda0
Merge branch 'main' into grounding-convenience
deekshas8 Dec 17, 2024
562a66a
review + tests+ changeset
deekshas8 Dec 23, 2024
995f080
Merge branch 'main' into grounding-convenience
deekshas8 Dec 27, 2024
f8d2f72
lint
deekshas8 Dec 27, 2024
2454181
restructure types
deekshas8 Dec 27, 2024
1acf278
fix: Changes from lint
Dec 27, 2024
b7f4a63
add type test
deekshas8 Dec 27, 2024
c5569a1
fix: Changes from lint
Dec 27, 2024
8fdc014
docs
deekshas8 Dec 27, 2024
b4b5951
fix: Changes from lint
Dec 27, 2024
555e750
Apply suggestions from code review
deekshas8 Dec 27, 2024
fd5366a
Merge branch 'main' into grounding-convenience
deekshas8 Jan 2, 2025
8badfab
review
deekshas8 Jan 2, 2025
1a07017
Merge branch 'main' into grounding-convenience
ZhongpinWang Jan 3, 2025
8c99894
Merge branch 'main' into grounding-convenience
deekshas8 Jan 6, 2025
43c0643
review
deekshas8 Jan 7, 2025
b26782c
fix: Changes from lint
Jan 7, 2025
366825d
Merge branch 'main' into grounding-convenience
deekshas8 Jan 9, 2025
417837e
update type DocumentGroundingServiceFilter
deekshas8 Jan 9, 2025
f9c143c
fix: Changes from lint
Jan 9, 2025
6bf31d6
docs review
deekshas8 Jan 9, 2025
b3acc13
fix: Changes from lint
Jan 9, 2025
bb6274b
Apply suggestions from code review
deekshas8 Jan 10, 2025
9583364
Merge branch 'main' into grounding-convenience
deekshas8 Jan 10, 2025
dc0938a
adjust sample for grounding
deekshas8 Jan 13, 2025
1ac972e
fix: Changes from lint
Jan 13, 2025
6a9d673
Merge branch 'main' into grounding-convenience
deekshas8 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shiny-brooms-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

Check warning on line 1 in .changeset/shiny-brooms-punch.md

View workflow job for this annotation

GitHub Actions / grammar-check

[vale] reported by reviewdog 🐶 [SAP.Readability] The text is very complex! It has a grade score of >14. Raw Output: {"message": "[SAP.Readability] The text is very complex! It has a grade score of \u003e14.", "location": {"path": ".changeset/shiny-brooms-punch.md", "range": {"start": {"line": 1, "column": 1}}}, "severity": "WARNING"}
'@sap-ai-sdk/orchestration': minor
---

[Improvement] Add convenience function for creating document grounding configuration
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions packages/orchestration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ const response = await orchestrationClient.chatCompletion({
return response.getContent();
```

`buildDocumentGroundingConfig` function provides convenience to create the document grounding service configuration using the minimal set of required values:
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved

```ts
import {
buildDocumentGroundingConfig
} from '@sap-ai-sdk/orchestration';

const orchestrationConfig: {
...,
grounding: buildDocumentGroundingConfig(
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
input_params: ['groundingInput'],
output_param: 'groundingOutput',
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
filters: [{id: 'filter-id', data_repositories: ['repository-id'],}]
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
)
}
```

### Using a JSON Configuration from AI Launchpad

If you already have an orchestration workflow created in AI Launchpad, you can either download the configuration as a JSON file or copy the JSON string directly to use it with the orchestration client.
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ export type {
export type {
OrchestrationModuleConfig,
LlmModuleConfig,
Prompt
Prompt,
DocumentGroundingServiceConfig,
DocumentGroundingServiceFilter
} from './orchestration-types.js';

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

export { buildAzureContentFilter } from './orchestration-filter-utility.js';
export {
buildAzureContentFilter,
buildDocumentGroundingConfig
} from './orchestration-util.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './orchestration-client.js';
export * from './orchestration-filter-utility.js';
export * from './orchestration-util.js';
export * from './orchestration-types.js';
export * from './orchestration-response.js';
2 changes: 1 addition & 1 deletion packages/orchestration/src/orchestration-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
constructCompletionPostRequest,
OrchestrationClient
} from './orchestration-client.js';
import { buildAzureContentFilter } from './orchestration-filter-utility.js';
import { buildAzureContentFilter } from './orchestration-util.js';
import { OrchestrationResponse } from './orchestration-response.js';
import type { CompletionPostResponse } from './client/api/schema/index.js';
import type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { constructCompletionPostRequest } from './orchestration-client.js';
import { buildAzureContentFilter } from './orchestration-filter-utility.js';
import type { CompletionPostRequest } from './client/api/schema';
import { buildAzureContentFilter } from './orchestration-util.js';
import type { CompletionPostRequest } from './client/api/schema/index.js';
import type { OrchestrationModuleConfig } from './orchestration-types.js';

describe('construct completion post request', () => {
Expand Down
176 changes: 0 additions & 176 deletions packages/orchestration/src/orchestration-filter-utility.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions packages/orchestration/src/orchestration-filter-utility.ts

This file was deleted.

41 changes: 41 additions & 0 deletions packages/orchestration/src/orchestration-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ChatModel } from './model-types.js';
import type {
ChatMessages,
DataRepositoryType,
DocumentGroundingFilter,
FilteringModuleConfig,
GroundingModuleConfig,
MaskingModuleConfig,
Expand Down Expand Up @@ -56,3 +58,42 @@ export interface OrchestrationModuleConfig {
*/
grounding?: GroundingModuleConfig;
}

/**
* Represents a filter configuration for the Document Grounding Service.
*
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
*/
export type DocumentGroundingServiceFilter = Pick<
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
DocumentGroundingFilter,
| 'id'
| 'search_config'
| 'data_repositories'
| 'data_repository_metadata'
| 'document_metadata'
| 'chunk_metadata'
> & {
/**
* Defines the type of data repository.
* If not set, the default value is 'vector'.
*/
data_repository_type?: DataRepositoryType;
};

/**
* Represents the configuration for the Document Grounding Service.
*/
export interface DocumentGroundingServiceConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] To understand for myself better. Why did you choose to declare this as an interface instead of a type?
I see the original config that gets generated is a type.

/**
* Define the filters to apply during the grounding process.
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
*/
filters?: DocumentGroundingServiceFilter[];
/**
* Contains the input parameters used for grounding input questions.
*/
input_params: string[];
/**
* Parameter name used for grounding output.
* @example "groundingOutput"
deekshas8 marked this conversation as resolved.
Show resolved Hide resolved
*/
output_param: string;
}
Loading
Loading