Skip to content

Commit

Permalink
Remove unused types
Browse files Browse the repository at this point in the history
  • Loading branch information
marikaner committed Aug 28, 2024
1 parent 4bf5019 commit 066b730
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
14 changes: 6 additions & 8 deletions packages/gen-ai-hub/src/client/openai/openai-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { type HttpRequestConfig } from '@sap-cloud-sdk/http-client';
import { type CustomRequestConfig, executeRequest } from '@sap-ai-sdk/core';
import { mergeIgnoreCase, pickValueIgnoreCase } from '@sap-cloud-sdk/util';
import {
type DeploymentConfiguration,
type ModelDeployment,
type FoundationModel,
type ModelConfiguration,
type Model,
isDeploymentIdConfiguration,
resolveDeployment
} from '../../utils/deployment-resolver.js';
Expand Down Expand Up @@ -32,7 +32,7 @@ export class OpenAiClient {
*/
async chatCompletion(
data: OpenAiChatCompletionParameters,
deploymentConfig: DeploymentConfiguration<OpenAiChatModel>,
deploymentConfig: ModelDeployment<OpenAiChatModel>,
requestConfig?: CustomRequestConfig
): Promise<OpenAiChatCompletionOutput> {
const deploymentId = await getDeploymentId(deploymentConfig, requestConfig);
Expand All @@ -56,7 +56,7 @@ export class OpenAiClient {
*/
async embeddings(
data: OpenAiEmbeddingParameters,
deploymentConfig: DeploymentConfiguration<OpenAiEmbeddingModel>,
deploymentConfig: ModelDeployment<OpenAiEmbeddingModel>,
requestConfig?: CustomRequestConfig
): Promise<OpenAiEmbeddingOutput> {
const deploymentId = await getDeploymentId(deploymentConfig);
Expand All @@ -70,7 +70,7 @@ export class OpenAiClient {
}

async function getDeploymentId(
deploymentConfig: DeploymentConfiguration,
deploymentConfig: ModelDeployment,
requestConfig?: CustomRequestConfig
) {
if (isDeploymentIdConfiguration(deploymentConfig)) {
Expand All @@ -87,9 +87,7 @@ async function getDeploymentId(
).id;
}

function translateToFoundationModel(
modelConfig: ModelConfiguration
): FoundationModel {
function translateToFoundationModel(modelConfig: Model): FoundationModel {
if (typeof modelConfig === 'string') {
return { name: modelConfig };
}
Expand Down
20 changes: 5 additions & 15 deletions packages/gen-ai-hub/src/utils/deployment-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ModelConfiguration<ModelNameT = string> =
/**
* The deployment configuration when using a deployment ID.
*/
export interface DeploymentIdConfiguration {
export interface DeploymentId {
/**
* The deployment ID.
*/
Expand All @@ -31,33 +31,23 @@ export interface DeploymentIdConfiguration {
* The deployment configuration can be either a model configuration or a deployment ID configuration.
* @typeParam ModelNameT - String literal type representing the name of the model.
*/
export type DeploymentConfiguration<ModelNameT = string> =
export type ModelDeployment<ModelNameT = string> =
| ModelConfiguration<ModelNameT>
| DeploymentIdConfiguration;
| DeploymentId;

/**
* Type guard to check if the given deployment configuration is a deployment ID configuration.
* @param deploymentConfig - Configuration to check.
* @returns `true` if the configuration is a deployment ID configuration, `false` otherwise.
*/
export function isDeploymentIdConfiguration(
deploymentConfig: DeploymentConfiguration
): deploymentConfig is DeploymentIdConfiguration {
deploymentConfig: ModelDeployment
): deploymentConfig is DeploymentId {
return (
typeof deploymentConfig === 'object' && 'deploymentId' in deploymentConfig
);
}

/**
* A deployment resolver can be either a deployment ID or a function that returns a full deployment object.
*/
export type DeploymentResolver = DeploymentId | (() => Promise<AiDeployment>);

/**
* A deployment ID is a string that uniquely identifies a deployment.
*/
export type DeploymentId = string;

/**
* A foundation model is identified by its name and potentially a version.
*/
Expand Down

0 comments on commit 066b730

Please sign in to comment.