From 2fda1396268e451b40b4d4293bbaa93b71127f5f Mon Sep 17 00:00:00 2001 From: Matthias Kuhr <52661546+MatKuhr@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:41:43 +0200 Subject: [PATCH] chore: Update orchestration spec (#94) --- eslint.config.js | 3 + .../azure-content-safety-filter-config.ts | 4 +- .../client/api/schema/azure-content-safety.ts | 2 +- .../client/api/schema/chat-message.ts | 6 + .../api/schema/completion-post-request.ts | 12 +- .../api/schema/completion-post-response.ts | 1 + .../client/api/schema/dpi-config.ts | 24 +++ .../client/api/schema/dpi-entities.ts | 12 +- ...masking-config.ts => dpi-entity-config.ts} | 9 +- .../client/api/schema/error-response.ts | 9 + .../api/schema/filtering-module-config.ts | 6 + .../api/schema/generic-module-result.ts | 1 + .../client/api/schema/grounding-filter.ts | 23 +++ .../api/schema/grounding-module-config.ts | 8 +- .../orchestration/client/api/schema/index.ts | 10 +- .../client/api/schema/llm-choice.ts | 3 +- .../client/api/schema/llm-module-config.ts | 10 +- .../client/api/schema/llm-module-result.ts | 5 + .../client/api/schema/masking-config.ts | 10 - .../api/schema/masking-module-config.ts | 10 +- ...ms-entry.ts => masking-provider-config.ts} | 6 +- .../api/schema/masking-provider-type.ts | 10 - .../client/api/schema/masking.ts | 18 -- .../client/api/schema/module-results.ts | 7 +- .../client/api/schema/presidio-entities.ts | 10 - .../api/schema/templating-module-config.ts | 15 +- .../api/schema/templating-module-result.ts | 10 - .../client/api/schema/token-usage.ts | 3 + .../orchestration-client.test.ts | 4 +- ...hestration-completion-post-request.test.ts | 4 +- .../orchestration-filter-utility.test.ts | 2 +- .../src/orchestration/orchestration-types.ts | 3 +- .../src/orchestration/spec/api.yaml | 178 +++++++++++------- 33 files changed, 267 insertions(+), 171 deletions(-) create mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-config.ts rename packages/gen-ai-hub/src/orchestration/client/api/schema/{unmasking-config.ts => dpi-entity-config.ts} (53%) delete mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/masking-config.ts rename packages/gen-ai-hub/src/orchestration/client/api/schema/{input-params-entry.ts => masking-provider-config.ts} (52%) delete mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-type.ts delete mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/masking.ts delete mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/presidio-entities.ts delete mode 100644 packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-result.ts diff --git a/eslint.config.js b/eslint.config.js index c63dabe4..e155c2e2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -21,5 +21,8 @@ export default [ rules: { '@typescript-eslint/explicit-module-boundary-types': 'off' } + }, + { + ignores: ['**/dist-cjs/**/*'] } ]; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety-filter-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety-filter-config.ts index 453e6bd2..2f3e77ff 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety-filter-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety-filter-config.ts @@ -10,10 +10,8 @@ import type { AzureContentSafety } from './azure-content-safety.js'; export type AzureContentSafetyFilterConfig = { /** * String represents name of the filter provider. + * @example "azure_content_safety" */ type: 'azure_content_safety'; - /** - * Filter configuration for Azure Content Azure Content Safety. - */ config?: AzureContentSafety; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety.ts index dc8dc26e..3df7f9dd 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/azure-content-safety.ts @@ -5,7 +5,7 @@ */ import type { AzureThreshold } from './azure-threshold.js'; /** - * Representation of the 'AzureContentSafety' schema. + * Filter configuration for Azure Content Safety. */ export interface AzureContentSafety { Hate?: AzureThreshold; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/chat-message.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/chat-message.ts index 7c442063..e7036602 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/chat-message.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/chat-message.ts @@ -8,6 +8,12 @@ * Representation of the 'ChatMessage' schema. */ export type ChatMessage = { + /** + * @example "user" + */ role: string; + /** + * @example "What is SAP S/4HANA?" + */ content: string; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-request.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-request.ts index 4ba5bdae..f1fbbbbf 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-request.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-request.ts @@ -4,13 +4,21 @@ * This is a generated file powered by the SAP Cloud SDK for JavaScript. */ import type { OrchestrationConfig } from './orchestration-config.js'; -import type { InputParamsEntry } from './input-params-entry.js'; import type { ChatMessages } from './chat-messages.js'; /** * Representation of the 'CompletionPostRequest' schema. */ export type CompletionPostRequest = { orchestration_config: OrchestrationConfig; - input_params?: Record; + /** + * @example { + * "groundingInput": "What is SAP Joule?", + * "inputContext": "optimizing supply chain management" + * } + */ + input_params?: Record; + /** + * History of chat messages. Can be used to provide system and assistant messages to set the context of the conversation. Will be merged with the template message. + */ messages_history?: ChatMessages; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-response.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-response.ts index e27ab6e6..f11d4c09 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-response.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/completion-post-response.ts @@ -11,6 +11,7 @@ import type { LLMModuleResult } from './llm-module-result.js'; export type CompletionPostResponse = { /** * ID of the request. + * @example "d4a67ea1-2bf9-4df7-8105-d48203ccff76" */ request_id: string; module_results: ModuleResults; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-config.ts new file mode 100644 index 00000000..587c862f --- /dev/null +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-config.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + * + * This is a generated file powered by the SAP Cloud SDK for JavaScript. + */ +import type { DPIEntityConfig } from './dpi-entity-config.js'; +/** + * Representation of the 'DPIConfig' schema. + */ +export type DPIConfig = { + /** + * Type of masking service provider. + */ + type: 'sap_data_privacy_integration'; + /** + * Type of masking method to be used. + */ + method: 'anonymization' | 'pseudonymization'; + /** + * List of entities to be masked + * Min Items: 1. + */ + entities: DPIEntityConfig[]; +} & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entities.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entities.ts index b106a4a1..0108b2fa 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entities.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entities.ts @@ -10,16 +10,26 @@ export type DPIEntities = | 'profile-person' | 'profile-org' + | 'profile-university' + | 'profile-location' | 'profile-email' | 'profile-phone' | 'profile-address' | 'profile-sapids-internal' | 'profile-sapids-public' | 'profile-url' + | 'profile-username-password' + | 'profile-nationalid' | 'profile-iban' + | 'profile-ssn' | 'profile-credit-card-number' | 'profile-passport' | 'profile-driverlicense' | 'profile-nationality' + | 'profile-religious-group' | 'profile-political-group' - | 'profile-ethnicity'; + | 'profile-pronouns-gender' + | 'profile-gender' + | 'profile-sexual-orientation' + | 'profile-trade-union' + | 'profile-sensitive-data'; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/unmasking-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entity-config.ts similarity index 53% rename from packages/gen-ai-hub/src/orchestration/client/api/schema/unmasking-config.ts rename to packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entity-config.ts index 305ed4c0..49a2c96e 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/unmasking-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/dpi-entity-config.ts @@ -4,13 +4,12 @@ * This is a generated file powered by the SAP Cloud SDK for JavaScript. */ import type { DPIEntities } from './dpi-entities.js'; -import type { PresidioEntities } from './presidio-entities.js'; /** - * Representation of the 'UnmaskingConfig' schema. + * Representation of the 'DPIEntityConfig' schema. */ -export type UnmaskingConfig = { +export type DPIEntityConfig = { /** - * List of entities to be unmasked. + * Type of entity to be masked. */ - entities: DPIEntities | PresidioEntities[]; + type: DPIEntities; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/error-response.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/error-response.ts index c067aeb2..142c97e0 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/error-response.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/error-response.ts @@ -8,8 +8,17 @@ import type { ModuleResults } from './module-results.js'; * Representation of the 'ErrorResponse' schema. */ export type ErrorResponse = { + /** + * @example "d4a67ea1-2bf9-4df7-8105-d48203ccff76" + */ request_id: string; + /** + * @example 400 + */ code: number; + /** + * @example "Model name must be one of ['gpt-4', ...]" + */ message: string; /** * Where the error occurred. diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/filtering-module-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/filtering-module-config.ts index f27025d3..f4e10b67 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/filtering-module-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/filtering-module-config.ts @@ -8,6 +8,12 @@ import type { FilteringConfig } from './filtering-config.js'; * Representation of the 'FilteringModuleConfig' schema. */ export interface FilteringModuleConfig { + /** + * List of provider type and filters. + */ input?: FilteringConfig; + /** + * List of provider type and filters. + */ output?: FilteringConfig; } diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/generic-module-result.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/generic-module-result.ts index 163f4552..8c7fbf38 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/generic-module-result.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/generic-module-result.ts @@ -10,6 +10,7 @@ export type GenericModuleResult = { /** * Some message created from the module. + * @example "Input to LLM is masked successfully." */ message: string; /** diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-filter.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-filter.ts index 3d99c3dd..2ada4fcf 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-filter.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-filter.ts @@ -8,11 +8,34 @@ * Representation of the 'GroundingFilter' schema. */ export type GroundingFilter = { + /** + * @example "string" + */ id?: string; + /** + * @example {} + */ search_configuration?: Record; + /** + * @example [ + * "*" + * ] + */ data_repositories?: string[]; + /** + * @example "help.sap.com" + */ data_repository_type?: 'vector' | 'help.sap.com'; + /** + * @example [] + */ data_repository_metadata?: Record[]; + /** + * @example [] + */ document_metadata?: Record[]; + /** + * @example [] + */ chunk_metadata?: Record[]; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-module-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-module-config.ts index dab358c1..5523d085 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-module-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/grounding-module-config.ts @@ -8,12 +8,11 @@ import type { GroundingFilter } from './grounding-filter.js'; * Representation of the 'GroundingModuleConfig' schema. */ export type GroundingModuleConfig = { + /** + * @example "document_grounding_service" + */ grounding_service: 'document_grounding_service'; grounding_service_configuration?: { - /** - * Secret name of the generic secret within Gen AI Hub containing document grounding service credentials. - */ - secret_name: string; /** * Document grounding service filters to be used. */ @@ -24,6 +23,7 @@ export type GroundingModuleConfig = { grounding_input_parameters: string[]; /** * Parameter name used for grounding output. + * @example "groundingOutput" */ grounding_output_parameter: string; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/index.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/index.ts index c4eec0e9..7d72e857 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/index.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/index.ts @@ -6,12 +6,10 @@ export * from './completion-post-request.js'; export * from './chat-messages.js'; export * from './chat-message.js'; -export * from './input-params-entry.js'; export * from './completion-post-response.js'; export * from './orchestration-config.js'; export * from './module-configs.js'; export * from './module-results.js'; -export * from './templating-module-result.js'; export * from './llm-module-config.js'; export * from './generic-module-result.js'; export * from './llm-module-result.js'; @@ -25,12 +23,10 @@ export * from './azure-content-safety-filter-config.js'; export * from './azure-content-safety.js'; export * from './azure-threshold.js'; export * from './masking-module-config.js'; -export * from './masking-config.js'; -export * from './masking.js'; -export * from './masking-provider-type.js'; +export * from './masking-provider-config.js'; +export * from './dpi-config.js'; +export * from './dpi-entity-config.js'; export * from './dpi-entities.js'; -export * from './presidio-entities.js'; -export * from './unmasking-config.js'; export * from './grounding-module-config.js'; export * from './grounding-filter.js'; export * from './error-response.js'; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-choice.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-choice.ts index 7f4b2901..8f286a5c 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-choice.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-choice.ts @@ -18,7 +18,8 @@ export type LLMChoice = { */ logprobs?: Record; /** - * Reason for stopping the model. + * Reason the model stopped generating tokens. 'stop' if the model hit a natural stop point or a provided stop sequence, 'length' if the maximum token number was reached, 'content_filter' if content was omitted due to a filter enforced by the LLM model provider or the content filtering module. + * @example "stop" */ finish_reason: string; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-config.ts index a6da100c..cdc48d66 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-config.ts @@ -15,11 +15,17 @@ export type LLMModuleConfig = { model_name: string; /** * Model parameters. + * @example { + * "max_tokens": 300, + * "temperature": 0.1, + * "frequency_penalty": 0, + * "presence_penalty": 0, + * "n": 2 + * } */ model_params: Record; /** - * Version of the model to use. - * @example "2024-08-12T10:11:17.042Z" + * Version of the model to use * Default: "latest". */ model_version?: string; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-result.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-result.ts index aaa02834..79923987 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-result.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/llm-module-result.ts @@ -11,22 +11,27 @@ import type { TokenUsage } from './token-usage.js'; export type LLMModuleResult = { /** * ID of the response. + * @example "chatcmpl-9rO0aLoPKY7RtqkWi1317bazHEVFr" */ id: string; /** * Object type. + * @example "chat.completion" */ object: string; /** * Unix timestamp. + * @example 1722510700 */ created: number; /** * Model name. + * @example "gpt-4" */ model: string; /** * System fingerprint. + * @example "fp_44709d6fcb" */ system_fingerprint?: string; /** diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-config.ts deleted file mode 100644 index c51cc09e..00000000 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-config.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. - * - * This is a generated file powered by the SAP Cloud SDK for JavaScript. - */ -import type { Masking } from './masking.js'; -/** - * Masking services to be used. - */ -export type MaskingConfig = Masking[]; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-module-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-module-config.ts index d713e0ee..cf22074a 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-module-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-module-config.ts @@ -3,12 +3,14 @@ * * This is a generated file powered by the SAP Cloud SDK for JavaScript. */ -import type { MaskingConfig } from './masking-config.js'; -import type { UnmaskingConfig } from './unmasking-config.js'; +import type { MaskingProviderConfig } from './masking-provider-config.js'; /** * Representation of the 'MaskingModuleConfig' schema. */ export interface MaskingModuleConfig { - masking: MaskingConfig; - unmasking?: UnmaskingConfig; + /** + * List of masking service providers + * Min Items: 1. + */ + masking_providers: MaskingProviderConfig[]; } diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/input-params-entry.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-config.ts similarity index 52% rename from packages/gen-ai-hub/src/orchestration/client/api/schema/input-params-entry.ts rename to packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-config.ts index 1a50f1be..9d07d32f 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/input-params-entry.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-config.ts @@ -3,8 +3,8 @@ * * This is a generated file powered by the SAP Cloud SDK for JavaScript. */ - +import type { DPIConfig } from './dpi-config.js'; /** - * Representation of the 'InputParamsEntry' schema. + * Representation of the 'MaskingProviderConfig' schema. */ -export type InputParamsEntry = string | number; +export type MaskingProviderConfig = DPIConfig; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-type.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-type.ts deleted file mode 100644 index 577d0d3c..00000000 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking-provider-type.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. - * - * This is a generated file powered by the SAP Cloud SDK for JavaScript. - */ - -/** - * Representation of the 'MaskingProviderType' schema. - */ -export type MaskingProviderType = 'data_privacy_integration' | 'ms_presidio'; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/masking.ts deleted file mode 100644 index 5e13e89b..00000000 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/masking.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. - * - * This is a generated file powered by the SAP Cloud SDK for JavaScript. - */ -import type { MaskingProviderType } from './masking-provider-type.js'; -import type { DPIEntities } from './dpi-entities.js'; -import type { PresidioEntities } from './presidio-entities.js'; -/** - * Representation of the 'Masking' schema. - */ -export type Masking = { - type: MaskingProviderType; - /** - * List of entities to be masked. - */ - entities: DPIEntities | PresidioEntities[]; -} & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/module-results.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/module-results.ts index 9f2bbade..8f4adc2d 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/module-results.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/module-results.ts @@ -4,17 +4,18 @@ * This is a generated file powered by the SAP Cloud SDK for JavaScript. */ import type { GenericModuleResult } from './generic-module-result.js'; -import type { TemplatingModuleResult } from './templating-module-result.js'; +import type { ChatMessages } from './chat-messages.js'; import type { LLMModuleResult } from './llm-module-result.js'; +import type { LLMChoice } from './llm-choice.js'; /** * Results of each module. */ export interface ModuleResults { grounding?: GenericModuleResult; - templating?: TemplatingModuleResult; + templating?: ChatMessages; input_masking?: GenericModuleResult; input_filtering?: GenericModuleResult; llm?: LLMModuleResult; output_filtering?: GenericModuleResult; - output_unmasking?: GenericModuleResult; + output_unmasking?: LLMChoice[]; } diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/presidio-entities.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/presidio-entities.ts deleted file mode 100644 index dafb62aa..00000000 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/presidio-entities.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. - * - * This is a generated file powered by the SAP Cloud SDK for JavaScript. - */ - -/** - * Representation of the 'PresidioEntities' schema. - */ -export type PresidioEntities = 'URL'; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-config.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-config.ts index 3b718785..fca0a7ff 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-config.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-config.ts @@ -6,12 +6,25 @@ import type { ChatMessages } from './chat-messages.js'; /** * Representation of the 'TemplatingModuleConfig' schema. + * @example { + * "template": [ + * { + * "role": "user", + * "content": "How can the features of AI in SAP BTP specifially {{?groundingOutput}}, be applied to {{?inputContext}}" + * } + * ], + * "defaults": { + * "inputContext": "The default text that will be used in the template if inputContext is not set" + * } + * } */ export type TemplatingModuleConfig = { + /** + * A chat message array to be formatted with values from input_params. Both role and content can be templated. If messages_history is provided, the templated messages will be appended. + */ template: ChatMessages; /** * Optional default values for the template. If a parameter has no default it is required. - * @example "{\"context\": \"I am a default context\"}" */ defaults?: Record; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-result.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-result.ts deleted file mode 100644 index 1dfb6741..00000000 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/templating-module-result.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. - * - * This is a generated file powered by the SAP Cloud SDK for JavaScript. - */ -import type { ChatMessages } from './chat-messages.js'; -/** - * Representation of the 'TemplatingModuleResult' schema. - */ -export type TemplatingModuleResult = ChatMessages; diff --git a/packages/gen-ai-hub/src/orchestration/client/api/schema/token-usage.ts b/packages/gen-ai-hub/src/orchestration/client/api/schema/token-usage.ts index ef5f5ba7..9d31be76 100644 --- a/packages/gen-ai-hub/src/orchestration/client/api/schema/token-usage.ts +++ b/packages/gen-ai-hub/src/orchestration/client/api/schema/token-usage.ts @@ -10,14 +10,17 @@ export type TokenUsage = { /** * Number of tokens used in the input. + * @example 20 */ completion_tokens: number; /** * Number of tokens used in the output. + * @example 30 */ prompt_tokens: number; /** * Total number of tokens used. + * @example 50 */ total_tokens: number; } & Record; diff --git a/packages/gen-ai-hub/src/orchestration/orchestration-client.test.ts b/packages/gen-ai-hub/src/orchestration/orchestration-client.test.ts index 7f9e7bdb..89d2064e 100644 --- a/packages/gen-ai-hub/src/orchestration/orchestration-client.test.ts +++ b/packages/gen-ai-hub/src/orchestration/orchestration-client.test.ts @@ -68,7 +68,7 @@ describe('GenAiHubClient', () => { content: 'Create {{?number}} paraphrases of {{?phrase}}' } ], - template_params: { phrase: 'I hate you.', number: 3 } + template_params: { phrase: 'I hate you.', number: '3' } }, filterConfig: { input: azureContentFilter({ Hate: 4, SelfHarm: 2 }), @@ -109,7 +109,7 @@ describe('GenAiHubClient', () => { content: 'Create {{?number}} paraphrases of {{?phrase}}' } ], - template_params: { phrase: 'I hate you.', number: 3 } + template_params: { phrase: 'I hate you.', number: '3' } }, filterConfig: { input: { diff --git a/packages/gen-ai-hub/src/orchestration/orchestration-completion-post-request.test.ts b/packages/gen-ai-hub/src/orchestration/orchestration-completion-post-request.test.ts index 919c7668..66b2b3d4 100644 --- a/packages/gen-ai-hub/src/orchestration/orchestration-completion-post-request.test.ts +++ b/packages/gen-ai-hub/src/orchestration/orchestration-completion-post-request.test.ts @@ -66,7 +66,7 @@ describe('constructCompletionPostRequest()', () => { content: 'Create {{?number}} paraphrases of {{?phrase}}' } ], - template_params: { phrase: 'I hate you.', number: 3 } + template_params: { phrase: 'I hate you.', number: '3' } }; const expectedCompletionPostRequest: CompletionPostRequest = { orchestration_config: { @@ -85,7 +85,7 @@ describe('constructCompletionPostRequest()', () => { } } }, - input_params: { phrase: 'I hate you.', number: 3 } + input_params: { phrase: 'I hate you.', number: '3' } }; const completionPostRequest: CompletionPostRequest = constructCompletionPostRequest(input); diff --git a/packages/gen-ai-hub/src/orchestration/orchestration-filter-utility.test.ts b/packages/gen-ai-hub/src/orchestration/orchestration-filter-utility.test.ts index bcb665ae..91f8f9c4 100644 --- a/packages/gen-ai-hub/src/orchestration/orchestration-filter-utility.test.ts +++ b/packages/gen-ai-hub/src/orchestration/orchestration-filter-utility.test.ts @@ -16,7 +16,7 @@ describe('Filter utility', () => { template: [ { role: 'user', content: 'Create {number} paraphrases of {phrase}' } ], - template_params: { phrase: 'I hate you.', number: 3 } + template_params: { phrase: 'I hate you.', number: '3' } } }; diff --git a/packages/gen-ai-hub/src/orchestration/orchestration-types.ts b/packages/gen-ai-hub/src/orchestration/orchestration-types.ts index e993be15..37cbb09e 100644 --- a/packages/gen-ai-hub/src/orchestration/orchestration-types.ts +++ b/packages/gen-ai-hub/src/orchestration/orchestration-types.ts @@ -1,7 +1,6 @@ import { ChatMessages, FilteringModuleConfig, - InputParamsEntry, LLMModuleConfig } from './client/api/index.js'; @@ -20,7 +19,7 @@ export interface PromptConfig { /** * Template Parameters. */ - template_params?: Record; + template_params?: Record; } /** diff --git a/packages/gen-ai-hub/src/orchestration/spec/api.yaml b/packages/gen-ai-hub/src/orchestration/spec/api.yaml index 43a7fb6a..f19aee51 100644 --- a/packages/gen-ai-hub/src/orchestration/spec/api.yaml +++ b/packages/gen-ai-hub/src/orchestration/spec/api.yaml @@ -17,6 +17,8 @@ tags: paths: /completion: post: + tags: + - OrchestrationCompletion operationId: orchestration.v1.endpoints.create requestBody: required: true @@ -38,6 +40,8 @@ paths: /healthz: get: + tags: + - OrchestrationHealthz operationId: orchestration.v1.endpoints.healthz responses: '200': @@ -69,12 +73,15 @@ components: $ref: '#/components/schemas/OrchestrationConfig' input_params: type: object + example: + groundingInput: 'What is SAP Joule?' + inputContext: 'optimizing supply chain management' additionalProperties: - $ref: '#/components/schemas/InputParamsEntry' + type: string messages_history: + allOf: + - $ref: '#/components/schemas/ChatMessages' description: History of chat messages. Can be used to provide system and assistant messages to set the context of the conversation. Will be merged with the template message - $ref: '#/components/schemas/ChatMessages' - default: [] ChatMessages: type: array @@ -89,13 +96,10 @@ components: properties: role: type: string + example: user content: type: string - - InputParamsEntry: - oneOf: - - type: string - - type: number + example: 'What is SAP S/4HANA?' CompletionPostResponse: type: object @@ -107,6 +111,7 @@ components: request_id: description: ID of the request type: string + example: 'd4a67ea1-2bf9-4df7-8105-d48203ccff76' module_results: $ref: '#/components/schemas/ModuleResults' orchestration_result: @@ -145,7 +150,7 @@ components: grounding: $ref: '#/components/schemas/GenericModuleResult' templating: - $ref: '#/components/schemas/TemplatingModuleResult' + $ref: '#/components/schemas/ChatMessages' input_masking: $ref: '#/components/schemas/GenericModuleResult' input_filtering: @@ -155,10 +160,9 @@ components: output_filtering: $ref: '#/components/schemas/GenericModuleResult' output_unmasking: - $ref: '#/components/schemas/GenericModuleResult' - - TemplatingModuleResult: - $ref: '#/components/schemas/ChatMessages' + type: array + items: + $ref: '#/components/schemas/LLMChoice' # --- LLM MODULE --- LLMModuleConfig: @@ -169,14 +173,19 @@ components: properties: model_name: description: Model name as in LLM Access configuration - example: gpt-4 + example: 'gpt-4' type: string model_params: description: Model parameters type: object + example: + max_tokens: 300 + temperature: 0.1 + frequency_penalty: 0 + presence_penalty: 0 + n: 2 model_version: description: Version of the model to use - example: 2023-05-15 type: string default: 'latest' @@ -189,6 +198,7 @@ components: message: type: string description: Some message created from the module + example: Input to LLM is masked successfully. data: type: object description: Additional data object from the module @@ -207,18 +217,23 @@ components: id: type: string description: ID of the response + example: 'chatcmpl-9rO0aLoPKY7RtqkWi1317bazHEVFr' object: type: string description: Object type + example: chat.completion created: type: integer description: Unix timestamp + example: 1722510700 model: type: string description: Model name + example: 'gpt-4' system_fingerprint: type: string description: System fingerprint + example: 'fp_44709d6fcb' choices: type: array description: Choices @@ -237,6 +252,7 @@ components: index: type: integer description: Index of the choice + example: 0 message: $ref: '#/components/schemas/ChatMessage' logprobs: @@ -248,7 +264,8 @@ components: type: number finish_reason: type: string - description: Reason for stopping the model + description: "Reason the model stopped generating tokens. 'stop' if the model hit a natural stop point or a provided stop sequence, 'length' if the maximum token number was reached, 'content_filter' if content was omitted due to a filter enforced by the LLM model provider or the content filtering module" + example: stop TokenUsage: type: object @@ -261,12 +278,15 @@ components: completion_tokens: type: integer description: Number of tokens used in the input + example: 20 prompt_tokens: type: integer description: Number of tokens used in the output + example: 30 total_tokens: type: integer description: Total number of tokens used + example: 50 # --- Templating Module --- @@ -276,23 +296,30 @@ components: - template properties: template: + allOf: + - $ref: '#/components/schemas/ChatMessages' description: A chat message array to be formatted with values from input_params. Both role and content can be templated. If messages_history is provided, the templated messages will be appended. - example: "{\n \"role\": \"user\",\n \"content\": \"input text: {​{ ?inputExample }}\"\n }" - $ref: '#/components/schemas/ChatMessages' defaults: description: Optional default values for the template. If a parameter has no default it is required. - example: '{"context": "I am a default context"}' type: object + example: + template: + - role: user + content: 'How can the features of AI in SAP BTP specifially {{?groundingOutput}}, be applied to {{?inputContext}}' + defaults: + inputContext: The default text that will be used in the template if inputContext is not set # --- Filtering Module --- FilteringModuleConfig: type: object properties: input: - $ref: '#/components/schemas/FilteringConfig' + allOf: + - $ref: '#/components/schemas/FilteringConfig' description: List of provider type and filters output: - $ref: '#/components/schemas/FilteringConfig' + allOf: + - $ref: '#/components/schemas/FilteringConfig' description: List of provider type and filters additionalProperties: false @@ -322,12 +349,12 @@ components: type: string enum: - azure_content_safety + example: azure_content_safety config: - description: Filter configuration for Azure Content Azure Content Safety - oneOf: - - $ref: '#/components/schemas/AzureContentSafety' + $ref: '#/components/schemas/AzureContentSafety' AzureContentSafety: + description: Filter configuration for Azure Content Safety type: object additionalProperties: false properties: @@ -347,50 +374,61 @@ components: - 2 - 4 - 6 + example: 0 # --- Masking module --- MaskingModuleConfig: type: object required: - - masking + - masking_providers properties: - masking: - $ref: '#/components/schemas/MaskingConfig' - description: List of masking providers and entities - unmasking: - $ref: '#/components/schemas/UnmaskingConfig' - description: List of entities to unmask + masking_providers: + type: array + minItems: 1 + items: + $ref: '#/components/schemas/MaskingProviderConfig' + description: List of masking service providers additionalProperties: false - MaskingConfig: - type: array - items: - $ref: '#/components/schemas/Masking' - description: Masking services to be used + MaskingProviderConfig: + oneOf: + - $ref: '#/components/schemas/DPIConfig' - Masking: + DPIConfig: type: object required: - type + - method - entities properties: type: - description: 'Type of masking service provider' - $ref: '#/components/schemas/MaskingProviderType' + description: Type of masking service provider + type: string + enum: + - sap_data_privacy_integration + method: + description: Type of masking method to be used + type: string + enum: + - anonymization + - pseudonymization entities: description: List of entities to be masked type: array + minItems: 1 items: - oneOf: - - $ref: '#/components/schemas/DPIEntities' - - $ref: '#/components/schemas/PresidioEntities' + $ref: '#/components/schemas/DPIEntityConfig' - MaskingProviderType: - type: string - enum: - - data_privacy_integration - - ms_presidio + DPIEntityConfig: + type: object + required: + - type + properties: + type: + description: Type of entity to be masked + allOf: + - $ref: '#/components/schemas/DPIEntities' DPIEntities: description: Default entities supported by data privacy and integration service @@ -398,36 +436,29 @@ components: enum: - profile-person - profile-org + - profile-university + - profile-location - profile-email - profile-phone - profile-address - profile-sapids-internal - profile-sapids-public - profile-url + - profile-username-password + - profile-nationalid - profile-iban + - profile-ssn - profile-credit-card-number - profile-passport - profile-driverlicense - profile-nationality + - profile-religious-group - profile-political-group - - profile-ethnicity - - PresidioEntities: - type: string - enum: - - URL - - UnmaskingConfig: - required: - - entities - properties: - entities: - type: array - description: List of entities to be unmasked - items: - anyOf: - - $ref: '#/components/schemas/DPIEntities' - - $ref: '#/components/schemas/PresidioEntities' + - profile-pronouns-gender + - profile-gender + - profile-sexual-orientation + - profile-trade-union + - profile-sensitive-data # --- Grounding Module --- @@ -440,16 +471,13 @@ components: type: string enum: - document_grounding_service + example: document_grounding_service grounding_service_configuration: type: object required: - - secret_name - grounding_input_parameters - grounding_output_parameter properties: - secret_name: - type: string - description: Secret name of the generic secret within Gen AI Hub containing document grounding service credentials filters: type: array items: @@ -459,38 +487,47 @@ components: type: array items: type: string + example: groundingInput description: Contains the input parameters used for grounding input questions grounding_output_parameter: type: string description: Parameter name used for grounding output + example: groundingOutput GroundingFilter: type: object properties: id: type: string + example: 'string' search_configuration: type: object + example: {} data_repositories: type: array items: type: string + example: ['*'] data_repository_type: type: string enum: - vector - help.sap.com + example: help.sap.com data_repository_metadata: type: array items: type: object + example: [] document_metadata: type: array items: type: object + example: [] chunk_metadata: type: array items: type: object + example: [] ErrorResponse: type: object @@ -502,10 +539,13 @@ components: properties: request_id: type: string + example: 'd4a67ea1-2bf9-4df7-8105-d48203ccff76' code: type: integer + example: 400 message: type: string + example: "Model name must be one of ['gpt-4', ...]" location: type: string description: Where the error occurred