Skip to content

Commit

Permalink
refactor: separate models
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongpinWang committed Sep 16, 2024
1 parent 53a56d0 commit f9b490a
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 45 deletions.
7 changes: 0 additions & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 0 additions & 1 deletion packages/core/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './context.js';
export * from './http-client.js';
export * from './openapi-request-builder.js';
export * from './model-types.js';
4 changes: 4 additions & 0 deletions packages/foundation-models/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export {
OpenAiEmbeddingClient,
OpenAiChatCompletionResponse
} from './openai/index.js';
export {
AzureOpenAiChatModel,
AzureOpenAiEmbeddingModel
} from './model-types.js';
20 changes: 20 additions & 0 deletions packages/foundation-models/src/model-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);

/**
* 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'
>;
7 changes: 2 additions & 5 deletions packages/foundation-models/src/openai/openai-chat-client.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/orchestration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,39 @@ type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
* 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'
| 'anthropic--claude-3.5-sonnet'
>;

/**
* 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
>;
2 changes: 1 addition & 1 deletion packages/orchestration/src/orchestration-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatModel } from '@sap-ai-sdk/core';
import { ChatModel } from './model-types.js';
import {
ChatMessages,
FilteringModuleConfig,
Expand Down
5 changes: 0 additions & 5 deletions tests/type-tests/test/model.test-d.ts

This file was deleted.

6 changes: 5 additions & 1 deletion tests/type-tests/test/openai.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
OpenAiChatClient,
OpenAiEmbeddingClient,
OpenAiChatCompletionResponse,
OpenAiUsage
OpenAiUsage,
AzureOpenAiChatModel
} from '@sap-ai-sdk/foundation-models';

/**
Expand Down Expand Up @@ -126,3 +127,6 @@ expectType<Promise<OpenAiEmbeddingOutput>>(
}
)
);

expect<AzureOpenAiChatModel>('custom-model');
expect<AzureOpenAiChatModel>('gpt-4-32k');
6 changes: 5 additions & 1 deletion tests/type-tests/test/orchestration.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
OrchestrationClient,
CompletionPostResponse,
OrchestrationResponse,
TokenUsage
TokenUsage,
ChatModel
} from '@sap-ai-sdk/orchestration';

/**
Expand Down Expand Up @@ -191,3 +192,6 @@ expectType<Promise<OrchestrationResponse>>(
}
}).chatCompletion()
);

expect<ChatModel>('custom-model');
expect<ChatModel>('gemini-1.0-pro');

0 comments on commit f9b490a

Please sign in to comment.