From f9b490a0662efcc370195f3640d51b8e1914d0a2 Mon Sep 17 00:00:00 2001 From: Zhongpin Wang Date: Mon, 16 Sep 2024 12:31:27 +0200 Subject: [PATCH 1/5] refactor: separate models --- packages/core/src/index.ts | 7 ---- packages/core/src/internal.ts | 1 - packages/foundation-models/src/index.ts | 4 +++ packages/foundation-models/src/model-types.ts | 20 +++++++++++ .../src/openai/openai-chat-client.ts | 7 ++-- .../src/openai/openai-embedding-client.ts | 7 ++-- packages/orchestration/src/index.ts | 8 +++++ .../src/model-types.ts | 33 ++++++++----------- .../orchestration/src/orchestration-types.ts | 2 +- tests/type-tests/test/model.test-d.ts | 5 --- tests/type-tests/test/openai.test-d.ts | 6 +++- tests/type-tests/test/orchestration.test-d.ts | 6 +++- 12 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 packages/foundation-models/src/model-types.ts rename packages/{core => orchestration}/src/model-types.ts (51%) delete mode 100644 tests/type-tests/test/model.test-d.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5128a08c..3cc6a523 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,10 +7,3 @@ export type { export { executeRequest } from './http-client.js'; export { getAiCoreDestination } from './context.js'; export { OpenApiRequestBuilder } from './openapi-request-builder.js'; -export type { - AzureOpenAiChatModel, - AzureOpenAiEmbeddingModel, - GcpVertexAiChatModel, - AwsBedrockChatModel, - ChatModel -} from './model-types.js'; diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts index 979cc12c..7af67b5d 100644 --- a/packages/core/src/internal.ts +++ b/packages/core/src/internal.ts @@ -1,4 +1,3 @@ export * from './context.js'; export * from './http-client.js'; export * from './openapi-request-builder.js'; -export * from './model-types.js'; diff --git a/packages/foundation-models/src/index.ts b/packages/foundation-models/src/index.ts index d891b6bd..bbab71eb 100644 --- a/packages/foundation-models/src/index.ts +++ b/packages/foundation-models/src/index.ts @@ -31,3 +31,7 @@ export { OpenAiEmbeddingClient, OpenAiChatCompletionResponse } from './openai/index.js'; +export { + AzureOpenAiChatModel, + AzureOpenAiEmbeddingModel +} from './model-types.js'; diff --git a/packages/foundation-models/src/model-types.ts b/packages/foundation-models/src/model-types.ts new file mode 100644 index 00000000..d71b29e0 --- /dev/null +++ b/packages/foundation-models/src/model-types.ts @@ -0,0 +1,20 @@ +type LiteralUnion = T | (U & Record); + +/** + * Azure OpenAI models for chat completion. + */ +export type AzureOpenAiChatModel = LiteralUnion< + | 'gpt-4o-mini' + | 'gpt-4o' + | 'gpt-4' + | 'gpt-4-32k' + | 'gpt-35-turbo' + | 'gpt-35-turbo-16k' +>; + +/** + * Azure OpenAI models for embedding. + */ +export type AzureOpenAiEmbeddingModel = LiteralUnion< + 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large' +>; diff --git a/packages/foundation-models/src/openai/openai-chat-client.ts b/packages/foundation-models/src/openai/openai-chat-client.ts index 28140bb1..f9d08261 100644 --- a/packages/foundation-models/src/openai/openai-chat-client.ts +++ b/packages/foundation-models/src/openai/openai-chat-client.ts @@ -1,12 +1,9 @@ -import { - type CustomRequestConfig, - type AzureOpenAiChatModel, - executeRequest -} from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; +import type { AzureOpenAiChatModel } from '../model-types.js'; import type { OpenAiChatCompletionParameters } from './openai-types.js'; import { OpenAiChatCompletionResponse } from './openai-response.js'; diff --git a/packages/foundation-models/src/openai/openai-embedding-client.ts b/packages/foundation-models/src/openai/openai-embedding-client.ts index b6f4bfbc..82e15cb4 100644 --- a/packages/foundation-models/src/openai/openai-embedding-client.ts +++ b/packages/foundation-models/src/openai/openai-embedding-client.ts @@ -1,12 +1,9 @@ -import { - type CustomRequestConfig, - type AzureOpenAiEmbeddingModel, - executeRequest -} from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; +import type { AzureOpenAiEmbeddingModel } from '../model-types.js'; import type { OpenAiEmbeddingParameters, OpenAiEmbeddingOutput diff --git a/packages/orchestration/src/index.ts b/packages/orchestration/src/index.ts index 5c5a4516..2b78c03c 100644 --- a/packages/orchestration/src/index.ts +++ b/packages/orchestration/src/index.ts @@ -39,3 +39,11 @@ export { OrchestrationClient } from './orchestration-client.js'; export { azureContentFilter } from './orchestration-filter-utility.js'; export { OrchestrationResponse } from './orchestration-response.js'; + +export type { + AzureOpenAiChatModel, + AicoreOpensourceChatModel, + GcpVertexAiChatModel, + AwsBedrockChatModel, + ChatModel +} from './model-types.js'; diff --git a/packages/core/src/model-types.ts b/packages/orchestration/src/model-types.ts similarity index 51% rename from packages/core/src/model-types.ts rename to packages/orchestration/src/model-types.ts index b42139da..5b205eff 100644 --- a/packages/core/src/model-types.ts +++ b/packages/orchestration/src/model-types.ts @@ -4,35 +4,20 @@ type LiteralUnion = T | (U & Record); * Azure OpenAI models for chat completion. */ export type AzureOpenAiChatModel = LiteralUnion< - | 'gpt-4o-mini' - | 'gpt-4o' - | 'gpt-4' - | 'gpt-4-32k' - | 'gpt-35-turbo' - | 'gpt-35-turbo-0125' - | 'gpt-35-turbo-16k' ->; - -/** - * Azure OpenAI models for embedding. - */ -export type AzureOpenAiEmbeddingModel = LiteralUnion< - 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large' + 'gpt-4o' | 'gpt-4' | 'gpt-4-32k' | 'gpt-35-turbo' | 'gpt-35-turbo-16k' >; /** * GCP Vertex AI models for chat completion. */ export type GcpVertexAiChatModel = LiteralUnion< - 'gemini-1.0-pro' | 'gemini-1.5-pro' | 'gemini-1.5-flash' | 'chat-bison' + 'gemini-1.0-pro' | 'gemini-1.5-pro' | 'gemini-1.5-flash' >; /** * AWS Bedrock models for chat completion. */ export type AwsBedrockChatModel = LiteralUnion< - | 'amazon--titan-text-express' - | 'amazon--titan-text-lite' | 'anthropic--claude-3-haiku' | 'anthropic--claude-3-opus' | 'anthropic--claude-3-sonnet' @@ -40,8 +25,18 @@ export type AwsBedrockChatModel = LiteralUnion< >; /** - * All available models for chat completion. + * Aicore Opensource models for chat completion. + */ +export type AicoreOpensourceChatModel = LiteralUnion< + 'mistralai--mixtral-8x7b-instruct-v01' | 'meta--llama3-70b-instruct' +>; + +/** + * Supported chat models for orchestration. */ export type ChatModel = LiteralUnion< - AzureOpenAiChatModel | GcpVertexAiChatModel | AwsBedrockChatModel + | AzureOpenAiChatModel + | GcpVertexAiChatModel + | AwsBedrockChatModel + | AicoreOpensourceChatModel >; diff --git a/packages/orchestration/src/orchestration-types.ts b/packages/orchestration/src/orchestration-types.ts index aa26fb1c..ef6332d7 100644 --- a/packages/orchestration/src/orchestration-types.ts +++ b/packages/orchestration/src/orchestration-types.ts @@ -1,4 +1,4 @@ -import { ChatModel } from '@sap-ai-sdk/core'; +import { ChatModel } from './model-types.js'; import { ChatMessages, FilteringModuleConfig, diff --git a/tests/type-tests/test/model.test-d.ts b/tests/type-tests/test/model.test-d.ts deleted file mode 100644 index cdb3153b..00000000 --- a/tests/type-tests/test/model.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ChatModel, AzureOpenAiChatModel } from '@sap-ai-sdk/core'; - -expect('custom-model'); -expect('custom-model'); -expect('gpt-4-32k'); diff --git a/tests/type-tests/test/openai.test-d.ts b/tests/type-tests/test/openai.test-d.ts index 2e6bef9c..f5335719 100644 --- a/tests/type-tests/test/openai.test-d.ts +++ b/tests/type-tests/test/openai.test-d.ts @@ -5,7 +5,8 @@ import { OpenAiChatClient, OpenAiEmbeddingClient, OpenAiChatCompletionResponse, - OpenAiUsage + OpenAiUsage, + AzureOpenAiChatModel } from '@sap-ai-sdk/foundation-models'; /** @@ -126,3 +127,6 @@ expectType>( } ) ); + +expect('custom-model'); +expect('gpt-4-32k'); diff --git a/tests/type-tests/test/orchestration.test-d.ts b/tests/type-tests/test/orchestration.test-d.ts index 3fbcd57f..1ef64037 100644 --- a/tests/type-tests/test/orchestration.test-d.ts +++ b/tests/type-tests/test/orchestration.test-d.ts @@ -3,7 +3,8 @@ import { OrchestrationClient, CompletionPostResponse, OrchestrationResponse, - TokenUsage + TokenUsage, + ChatModel } from '@sap-ai-sdk/orchestration'; /** @@ -191,3 +192,6 @@ expectType>( } }).chatCompletion() ); + +expect('custom-model'); +expect('gemini-1.0-pro'); From 59620048e38b2888f9b416f3347e9db948519958 Mon Sep 17 00:00:00 2001 From: Zhongpin Wang Date: Mon, 16 Sep 2024 14:20:05 +0200 Subject: [PATCH 2/5] refactor: reuse models from core --- packages/core/src/index.ts | 7 +++ packages/core/src/internal.ts | 1 + packages/core/src/model-types.ts | 44 +++++++++++++++++++ packages/foundation-models/src/index.ts | 2 +- packages/foundation-models/src/model-types.ts | 20 --------- .../src/openai/model-types.ts | 14 ++++++ .../src/openai/openai-chat-client.ts | 2 +- .../src/openai/openai-embedding-client.ts | 2 +- packages/orchestration/src/index.ts | 8 +--- packages/orchestration/src/model-types.ts | 43 ++++-------------- 10 files changed, 79 insertions(+), 64 deletions(-) create mode 100644 packages/core/src/model-types.ts delete mode 100644 packages/foundation-models/src/model-types.ts create mode 100644 packages/foundation-models/src/openai/model-types.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 3cc6a523..de7b5e39 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,3 +7,10 @@ export type { export { executeRequest } from './http-client.js'; export { getAiCoreDestination } from './context.js'; export { OpenApiRequestBuilder } from './openapi-request-builder.js'; +export { + AzureOpenAiChatModel, + AzureOpenAiEmbeddingModel, + GcpVertexAiChatModel, + AwsBedrockChatModel, + AicoreOpensourceChatModel +} from './model-types.js'; diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts index 7af67b5d..979cc12c 100644 --- a/packages/core/src/internal.ts +++ b/packages/core/src/internal.ts @@ -1,3 +1,4 @@ export * from './context.js'; export * from './http-client.js'; export * from './openapi-request-builder.js'; +export * from './model-types.js'; diff --git a/packages/core/src/model-types.ts b/packages/core/src/model-types.ts new file mode 100644 index 00000000..4291c219 --- /dev/null +++ b/packages/core/src/model-types.ts @@ -0,0 +1,44 @@ +type LiteralUnion = T | (U & Record); + +/** + * Azure OpenAI models for chat completion. + */ +export type AzureOpenAiChatModel = LiteralUnion< + | 'gpt-4o-mini' + | 'gpt-4o' + | 'gpt-4' + | 'gpt-4-32k' + | 'gpt-35-turbo' + | 'gpt-35-turbo-16k' +>; + +/** + * Azure OpenAI models for embedding. + */ +export type AzureOpenAiEmbeddingModel = LiteralUnion< + 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large' +>; + +/** + * GCP Vertex AI models for chat completion. + */ +export type GcpVertexAiChatModel = LiteralUnion< + 'gemini-1.0-pro' | 'gemini-1.5-pro' | 'gemini-1.5-flash' +>; + +/** + * AWS Bedrock models for chat completion. + */ +export type AwsBedrockChatModel = LiteralUnion< + | 'anthropic--claude-3-haiku' + | 'anthropic--claude-3-opus' + | 'anthropic--claude-3-sonnet' + | 'anthropic--claude-3.5-sonnet' +>; + +/** + * Aicore Opensource models for chat completion. + */ +export type AicoreOpensourceChatModel = LiteralUnion< + 'mistralai--mixtral-8x7b-instruct-v01' | 'meta--llama3-70b-instruct' +>; diff --git a/packages/foundation-models/src/index.ts b/packages/foundation-models/src/index.ts index bbab71eb..90e19e9e 100644 --- a/packages/foundation-models/src/index.ts +++ b/packages/foundation-models/src/index.ts @@ -34,4 +34,4 @@ export { export { AzureOpenAiChatModel, AzureOpenAiEmbeddingModel -} from './model-types.js'; +} from './openai/model-types.js'; diff --git a/packages/foundation-models/src/model-types.ts b/packages/foundation-models/src/model-types.ts deleted file mode 100644 index d71b29e0..00000000 --- a/packages/foundation-models/src/model-types.ts +++ /dev/null @@ -1,20 +0,0 @@ -type LiteralUnion = T | (U & Record); - -/** - * Azure OpenAI models for chat completion. - */ -export type AzureOpenAiChatModel = LiteralUnion< - | 'gpt-4o-mini' - | 'gpt-4o' - | 'gpt-4' - | 'gpt-4-32k' - | 'gpt-35-turbo' - | 'gpt-35-turbo-16k' ->; - -/** - * Azure OpenAI models for embedding. - */ -export type AzureOpenAiEmbeddingModel = LiteralUnion< - 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large' ->; diff --git a/packages/foundation-models/src/openai/model-types.ts b/packages/foundation-models/src/openai/model-types.ts new file mode 100644 index 00000000..defa6e8b --- /dev/null +++ b/packages/foundation-models/src/openai/model-types.ts @@ -0,0 +1,14 @@ +import type { + AzureOpenAiChatModel as CoreAzureOpenAiChatModel, + AzureOpenAiEmbeddingModel as CoreAzureOpenAiEmbeddingModel +} from '@sap-ai-sdk/core'; + +/** + * Azure OpenAI models for chat completion. + */ +export type AzureOpenAiChatModel = CoreAzureOpenAiChatModel; + +/** + * Azure OpenAI models for embedding. + */ +export type AzureOpenAiEmbeddingModel = CoreAzureOpenAiEmbeddingModel; diff --git a/packages/foundation-models/src/openai/openai-chat-client.ts b/packages/foundation-models/src/openai/openai-chat-client.ts index f9d08261..547e8498 100644 --- a/packages/foundation-models/src/openai/openai-chat-client.ts +++ b/packages/foundation-models/src/openai/openai-chat-client.ts @@ -3,7 +3,7 @@ import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; -import type { AzureOpenAiChatModel } from '../model-types.js'; +import type { AzureOpenAiChatModel } from './model-types.js'; import type { OpenAiChatCompletionParameters } from './openai-types.js'; import { OpenAiChatCompletionResponse } from './openai-response.js'; diff --git a/packages/foundation-models/src/openai/openai-embedding-client.ts b/packages/foundation-models/src/openai/openai-embedding-client.ts index 82e15cb4..a1d3d783 100644 --- a/packages/foundation-models/src/openai/openai-embedding-client.ts +++ b/packages/foundation-models/src/openai/openai-embedding-client.ts @@ -3,7 +3,7 @@ import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; -import type { AzureOpenAiEmbeddingModel } from '../model-types.js'; +import type { AzureOpenAiEmbeddingModel } from './model-types.js'; import type { OpenAiEmbeddingParameters, OpenAiEmbeddingOutput diff --git a/packages/orchestration/src/index.ts b/packages/orchestration/src/index.ts index 2b78c03c..232594ac 100644 --- a/packages/orchestration/src/index.ts +++ b/packages/orchestration/src/index.ts @@ -40,10 +40,4 @@ export { azureContentFilter } from './orchestration-filter-utility.js'; export { OrchestrationResponse } from './orchestration-response.js'; -export type { - AzureOpenAiChatModel, - AicoreOpensourceChatModel, - GcpVertexAiChatModel, - AwsBedrockChatModel, - ChatModel -} from './model-types.js'; +export type { ChatModel } from './model-types.js'; diff --git a/packages/orchestration/src/model-types.ts b/packages/orchestration/src/model-types.ts index 5b205eff..a4870611 100644 --- a/packages/orchestration/src/model-types.ts +++ b/packages/orchestration/src/model-types.ts @@ -1,42 +1,17 @@ -type LiteralUnion = T | (U & Record); - -/** - * Azure OpenAI models for chat completion. - */ -export type AzureOpenAiChatModel = LiteralUnion< - 'gpt-4o' | 'gpt-4' | 'gpt-4-32k' | 'gpt-35-turbo' | 'gpt-35-turbo-16k' ->; - -/** - * GCP Vertex AI models for chat completion. - */ -export type GcpVertexAiChatModel = LiteralUnion< - 'gemini-1.0-pro' | 'gemini-1.5-pro' | 'gemini-1.5-flash' ->; - -/** - * AWS Bedrock models for chat completion. - */ -export type AwsBedrockChatModel = LiteralUnion< - | 'anthropic--claude-3-haiku' - | 'anthropic--claude-3-opus' - | 'anthropic--claude-3-sonnet' - | 'anthropic--claude-3.5-sonnet' ->; - -/** - * Aicore Opensource models for chat completion. - */ -export type AicoreOpensourceChatModel = LiteralUnion< - 'mistralai--mixtral-8x7b-instruct-v01' | 'meta--llama3-70b-instruct' ->; +import { + AicoreOpensourceChatModel, + AwsBedrockChatModel, + AzureOpenAiChatModel, + GcpVertexAiChatModel +} from '@sap-ai-sdk/core'; /** * Supported chat models for orchestration. */ -export type ChatModel = LiteralUnion< +export type ChatModel = Exclude< | AzureOpenAiChatModel | GcpVertexAiChatModel | AwsBedrockChatModel - | AicoreOpensourceChatModel + | AicoreOpensourceChatModel, + 'gpt-4o-mini' >; From f512f8d8cdb2f3d1fd3067585bb0c4b6d6f2a144 Mon Sep 17 00:00:00 2001 From: Zhongpin Wang Date: Mon, 16 Sep 2024 15:30:23 +0200 Subject: [PATCH 3/5] fix: code review --- packages/core/src/index.ts | 2 +- packages/core/src/model-types.ts | 4 ++-- packages/foundation-models/src/index.ts | 4 ---- .../foundation-models/src/openai/model-types.ts | 14 -------------- .../src/openai/openai-chat-client.ts | 3 +-- .../src/openai/openai-embedding-client.ts | 3 +-- packages/orchestration/src/model-types.ts | 10 ++++------ tests/type-tests/test/openai.test-d.ts | 4 ++-- 8 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 packages/foundation-models/src/openai/model-types.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index de7b5e39..3f7f55ac 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -12,5 +12,5 @@ export { AzureOpenAiEmbeddingModel, GcpVertexAiChatModel, AwsBedrockChatModel, - AicoreOpensourceChatModel + AiCoreOpenSourceChatModel } from './model-types.js'; diff --git a/packages/core/src/model-types.ts b/packages/core/src/model-types.ts index 4291c219..65d298f1 100644 --- a/packages/core/src/model-types.ts +++ b/packages/core/src/model-types.ts @@ -37,8 +37,8 @@ export type AwsBedrockChatModel = LiteralUnion< >; /** - * Aicore Opensource models for chat completion. + * AI Core open source models for chat completion. */ -export type AicoreOpensourceChatModel = LiteralUnion< +export type AiCoreOpenSourceChatModel = LiteralUnion< 'mistralai--mixtral-8x7b-instruct-v01' | 'meta--llama3-70b-instruct' >; diff --git a/packages/foundation-models/src/index.ts b/packages/foundation-models/src/index.ts index 90e19e9e..d891b6bd 100644 --- a/packages/foundation-models/src/index.ts +++ b/packages/foundation-models/src/index.ts @@ -31,7 +31,3 @@ export { OpenAiEmbeddingClient, OpenAiChatCompletionResponse } from './openai/index.js'; -export { - AzureOpenAiChatModel, - AzureOpenAiEmbeddingModel -} from './openai/model-types.js'; diff --git a/packages/foundation-models/src/openai/model-types.ts b/packages/foundation-models/src/openai/model-types.ts deleted file mode 100644 index defa6e8b..00000000 --- a/packages/foundation-models/src/openai/model-types.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { - AzureOpenAiChatModel as CoreAzureOpenAiChatModel, - AzureOpenAiEmbeddingModel as CoreAzureOpenAiEmbeddingModel -} from '@sap-ai-sdk/core'; - -/** - * Azure OpenAI models for chat completion. - */ -export type AzureOpenAiChatModel = CoreAzureOpenAiChatModel; - -/** - * Azure OpenAI models for embedding. - */ -export type AzureOpenAiEmbeddingModel = CoreAzureOpenAiEmbeddingModel; diff --git a/packages/foundation-models/src/openai/openai-chat-client.ts b/packages/foundation-models/src/openai/openai-chat-client.ts index 547e8498..ae5e036d 100644 --- a/packages/foundation-models/src/openai/openai-chat-client.ts +++ b/packages/foundation-models/src/openai/openai-chat-client.ts @@ -1,9 +1,8 @@ -import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, type AzureOpenAiChatModel, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; -import type { AzureOpenAiChatModel } from './model-types.js'; import type { OpenAiChatCompletionParameters } from './openai-types.js'; import { OpenAiChatCompletionResponse } from './openai-response.js'; diff --git a/packages/foundation-models/src/openai/openai-embedding-client.ts b/packages/foundation-models/src/openai/openai-embedding-client.ts index a1d3d783..9933e11d 100644 --- a/packages/foundation-models/src/openai/openai-embedding-client.ts +++ b/packages/foundation-models/src/openai/openai-embedding-client.ts @@ -1,9 +1,8 @@ -import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, type AzureOpenAiEmbeddingModel, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; -import type { AzureOpenAiEmbeddingModel } from './model-types.js'; import type { OpenAiEmbeddingParameters, OpenAiEmbeddingOutput diff --git a/packages/orchestration/src/model-types.ts b/packages/orchestration/src/model-types.ts index a4870611..5fe9ccb4 100644 --- a/packages/orchestration/src/model-types.ts +++ b/packages/orchestration/src/model-types.ts @@ -1,5 +1,5 @@ import { - AicoreOpensourceChatModel, + AiCoreOpenSourceChatModel, AwsBedrockChatModel, AzureOpenAiChatModel, GcpVertexAiChatModel @@ -8,10 +8,8 @@ import { /** * Supported chat models for orchestration. */ -export type ChatModel = Exclude< - | AzureOpenAiChatModel +export type ChatModel = + | Exclude | GcpVertexAiChatModel | AwsBedrockChatModel - | AicoreOpensourceChatModel, - 'gpt-4o-mini' ->; + | AiCoreOpenSourceChatModel; diff --git a/tests/type-tests/test/openai.test-d.ts b/tests/type-tests/test/openai.test-d.ts index f5335719..8dc49076 100644 --- a/tests/type-tests/test/openai.test-d.ts +++ b/tests/type-tests/test/openai.test-d.ts @@ -1,4 +1,5 @@ -import { expectError, expectType } from 'tsd'; +import { expectType } from 'tsd'; +import { type AzureOpenAiChatModel } from '@sap-ai-sdk/core'; import { OpenAiChatCompletionOutput, OpenAiEmbeddingOutput, @@ -6,7 +7,6 @@ import { OpenAiEmbeddingClient, OpenAiChatCompletionResponse, OpenAiUsage, - AzureOpenAiChatModel } from '@sap-ai-sdk/foundation-models'; /** From 93b5c3fc3a106528a6cf97b587437d296be17b68 Mon Sep 17 00:00:00 2001 From: cloud-sdk-js Date: Mon, 16 Sep 2024 13:31:05 +0000 Subject: [PATCH 4/5] fix: Changes from lint --- packages/foundation-models/src/openai/openai-chat-client.ts | 6 +++++- .../foundation-models/src/openai/openai-embedding-client.ts | 6 +++++- tests/type-tests/test/openai.test-d.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/foundation-models/src/openai/openai-chat-client.ts b/packages/foundation-models/src/openai/openai-chat-client.ts index ae5e036d..28140bb1 100644 --- a/packages/foundation-models/src/openai/openai-chat-client.ts +++ b/packages/foundation-models/src/openai/openai-chat-client.ts @@ -1,4 +1,8 @@ -import { type CustomRequestConfig, type AzureOpenAiChatModel, executeRequest } from '@sap-ai-sdk/core'; +import { + type CustomRequestConfig, + type AzureOpenAiChatModel, + executeRequest +} from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment diff --git a/packages/foundation-models/src/openai/openai-embedding-client.ts b/packages/foundation-models/src/openai/openai-embedding-client.ts index 9933e11d..b6f4bfbc 100644 --- a/packages/foundation-models/src/openai/openai-embedding-client.ts +++ b/packages/foundation-models/src/openai/openai-embedding-client.ts @@ -1,4 +1,8 @@ -import { type CustomRequestConfig, type AzureOpenAiEmbeddingModel, executeRequest } from '@sap-ai-sdk/core'; +import { + type CustomRequestConfig, + type AzureOpenAiEmbeddingModel, + executeRequest +} from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment diff --git a/tests/type-tests/test/openai.test-d.ts b/tests/type-tests/test/openai.test-d.ts index 8dc49076..c7ca0b9c 100644 --- a/tests/type-tests/test/openai.test-d.ts +++ b/tests/type-tests/test/openai.test-d.ts @@ -6,7 +6,7 @@ import { OpenAiChatClient, OpenAiEmbeddingClient, OpenAiChatCompletionResponse, - OpenAiUsage, + OpenAiUsage } from '@sap-ai-sdk/foundation-models'; /** From 5769c48987c5d545586a7fc8a64055c7d38a1841 Mon Sep 17 00:00:00 2001 From: Zhongpin Wang Date: Mon, 16 Sep 2024 16:53:06 +0200 Subject: [PATCH 5/5] revert: re-exporting models --- packages/foundation-models/src/index.ts | 4 +++- packages/foundation-models/src/openai/index.ts | 1 + .../foundation-models/src/openai/model-types.ts | 14 ++++++++++++++ .../src/openai/openai-chat-client.ts | 7 ++----- .../src/openai/openai-embedding-client.ts | 7 ++----- tests/type-tests/test/openai.test-d.ts | 4 ++-- 6 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 packages/foundation-models/src/openai/model-types.ts diff --git a/packages/foundation-models/src/index.ts b/packages/foundation-models/src/index.ts index d891b6bd..50fe7902 100644 --- a/packages/foundation-models/src/index.ts +++ b/packages/foundation-models/src/index.ts @@ -24,7 +24,9 @@ export type { OpenAiContentFilterResultBase, OpenAiContentFilterDetectedResult, OpenAiContentFilterSeverityResult, - OpenAiEmbeddingOutput + OpenAiEmbeddingOutput, + AzureOpenAiChatModel, + AzureOpenAiEmbeddingModel } from './openai/index.js'; export { OpenAiChatClient, diff --git a/packages/foundation-models/src/openai/index.ts b/packages/foundation-models/src/openai/index.ts index 5ec4b8b5..3c28162e 100644 --- a/packages/foundation-models/src/openai/index.ts +++ b/packages/foundation-models/src/openai/index.ts @@ -2,3 +2,4 @@ export * from './openai-types.js'; export * from './openai-chat-client.js'; export * from './openai-embedding-client.js'; export * from './openai-response.js'; +export * from './model-types.js'; diff --git a/packages/foundation-models/src/openai/model-types.ts b/packages/foundation-models/src/openai/model-types.ts new file mode 100644 index 00000000..defa6e8b --- /dev/null +++ b/packages/foundation-models/src/openai/model-types.ts @@ -0,0 +1,14 @@ +import type { + AzureOpenAiChatModel as CoreAzureOpenAiChatModel, + AzureOpenAiEmbeddingModel as CoreAzureOpenAiEmbeddingModel +} from '@sap-ai-sdk/core'; + +/** + * Azure OpenAI models for chat completion. + */ +export type AzureOpenAiChatModel = CoreAzureOpenAiChatModel; + +/** + * Azure OpenAI models for embedding. + */ +export type AzureOpenAiEmbeddingModel = CoreAzureOpenAiEmbeddingModel; diff --git a/packages/foundation-models/src/openai/openai-chat-client.ts b/packages/foundation-models/src/openai/openai-chat-client.ts index 28140bb1..547e8498 100644 --- a/packages/foundation-models/src/openai/openai-chat-client.ts +++ b/packages/foundation-models/src/openai/openai-chat-client.ts @@ -1,12 +1,9 @@ -import { - type CustomRequestConfig, - type AzureOpenAiChatModel, - executeRequest -} from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; +import type { AzureOpenAiChatModel } from './model-types.js'; import type { OpenAiChatCompletionParameters } from './openai-types.js'; import { OpenAiChatCompletionResponse } from './openai-response.js'; diff --git a/packages/foundation-models/src/openai/openai-embedding-client.ts b/packages/foundation-models/src/openai/openai-embedding-client.ts index b6f4bfbc..a1d3d783 100644 --- a/packages/foundation-models/src/openai/openai-embedding-client.ts +++ b/packages/foundation-models/src/openai/openai-embedding-client.ts @@ -1,12 +1,9 @@ -import { - type CustomRequestConfig, - type AzureOpenAiEmbeddingModel, - executeRequest -} from '@sap-ai-sdk/core'; +import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core'; import { getDeploymentId, type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js'; +import type { AzureOpenAiEmbeddingModel } from './model-types.js'; import type { OpenAiEmbeddingParameters, OpenAiEmbeddingOutput diff --git a/tests/type-tests/test/openai.test-d.ts b/tests/type-tests/test/openai.test-d.ts index c7ca0b9c..8b000b55 100644 --- a/tests/type-tests/test/openai.test-d.ts +++ b/tests/type-tests/test/openai.test-d.ts @@ -1,12 +1,12 @@ import { expectType } from 'tsd'; -import { type AzureOpenAiChatModel } from '@sap-ai-sdk/core'; import { OpenAiChatCompletionOutput, OpenAiEmbeddingOutput, OpenAiChatClient, OpenAiEmbeddingClient, OpenAiChatCompletionResponse, - OpenAiUsage + OpenAiUsage, + type AzureOpenAiChatModel } from '@sap-ai-sdk/foundation-models'; /**