Skip to content

Commit

Permalink
union type for createAwsBedrockModelProvider api param
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaglick committed Jun 5, 2024
1 parent cf7beb6 commit 7a65c15
Show file tree
Hide file tree
Showing 91 changed files with 234 additions and 185 deletions.
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes/BaseModelProvider.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes/EjsTemplate.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes/HttpModelProvider.html

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/functions/createAwsBedrockModelProvider.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/createCohereModelProvider.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/createGroqModelProvider.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/createLmStudioModelProvider.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/createMistralModelProvider.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/createOpenAiChatModelProvider.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/hierarchy.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/interfaces/Ai21Jurassic2Api.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Ai21Jurassic2Options.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Ai21Jurassic2Response.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/interfaces/AmazonTitanTextApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/AmazonTitanTextOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/AmazonTitanTextResponse.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/AwsAuthConfig.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereAuthConfig.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereChatApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereChatOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereChatResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereGenerateApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereGenerateOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/CohereGenerateResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/GroqAuthConfig.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HfConversationalTaskOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HfConversationalTaskResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HfInferenceApiOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HfTextGenerationTaskOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HfTextGenerationTaskResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HttpClient.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/HuggingfaceAuthConfig.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/interfaces/Llama2ChatApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Llama2ChatOptions.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/interfaces/Llama3ChatApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Llama3ChatOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/LlamaResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MistralAiOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MistralAiResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MistralAuthConfig.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/interfaces/MistralBedrockApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MistralBedrockOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MistralBedrockResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/ModelApi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/ModelProvider.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/ModelRequestOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/OpenAiAuthConfig.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/OpenAiChatOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/OpenAiChatResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Template.html

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions docs/modules.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/ModelId.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/variables/Ai21Jurassic2Api-1.html

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/variables/Ai21Jurassic2Api.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/variables/Ai21Jurassic2Template.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/variables/AmazonTitanTextApi-1.html

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/variables/AmazonTitanTextApi.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/variables/AmazonTitanTextTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/CohereChatApi-1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/CohereChatTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/CohereGenerateApi-1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/CohereGenerateTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/HfConversationalTaskApi.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/HfConversationalTaskTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/HfTextGenerationTaskApi.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/HfTextGenerationTaskTemplate.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/variables/Llama2ChatApi-1.html

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/variables/Llama2ChatApi.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/variables/Llama2ChatTemplate.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/variables/Llama3ChatApi-1.html

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/variables/Llama3ChatApi.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/variables/Llama3ChatTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/MistralAiApi.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/MistralAiTemplate.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/variables/MistralBedrockApi-1.html

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/variables/MistralBedrockApi.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/variables/MistralBedrockTemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/OpenAiChatApi.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/variables/OpenAiChatTemplate.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/core/src/apis/ai21/jurassic2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ export function isAi21Jurassic2Response(
return !isLeft(Ai21Jurassic2ResponseCodec.decode(response));
}

export interface Ai21Jurassic2Api
extends ModelApi<Ai21Jurassic2Options, Ai21Jurassic2Response> {}

/**
*
* ## Reference
Expand All @@ -211,10 +214,7 @@ export function isAi21Jurassic2Response(
* @category Provider: AWS Bedrock
*
*/
export const Ai21Jurassic2Api: ModelApi<
Ai21Jurassic2Options,
Ai21Jurassic2Response
> = {
export const Ai21Jurassic2Api: Ai21Jurassic2Api = {
requestTemplate: Ai21Jurassic2Template,
responseGuard: isAi21Jurassic2Response,
};
8 changes: 4 additions & 4 deletions packages/core/src/apis/amazon/titanText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export function isAmazonTitanTextResponse(
return !isLeft(AmazonTitanTextResponseCodec.decode(response));
}

export interface AmazonTitanTextApi
extends ModelApi<AmazonTitanTextOptions, AmazonTitanTextResponse> {}

/**
*
* ## Reference
Expand All @@ -86,10 +89,7 @@ export function isAmazonTitanTextResponse(
* @category Provider: AWS Bedrock
*
*/
export const AmazonTitanTextApi: ModelApi<
AmazonTitanTextOptions,
AmazonTitanTextResponse
> = {
export const AmazonTitanTextApi: AmazonTitanTextApi = {
requestTemplate: AmazonTitanTextTemplate,
responseGuard: isAmazonTitanTextResponse,
};
5 changes: 4 additions & 1 deletion packages/core/src/apis/meta/llama2ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const Llama2ChatTemplate = new EjsTemplate<Llama2ChatOptions>(
templateSource,
);

export interface Llama2ChatApi
extends ModelApi<Llama2ChatOptions, LlamaResponse> {}

/**
*
* ## Reference
Expand All @@ -49,7 +52,7 @@ export const Llama2ChatTemplate = new EjsTemplate<Llama2ChatOptions>(
* @category Provider: AWS Bedrock
*
*/
export const Llama2ChatApi: ModelApi<Llama2ChatOptions, LlamaResponse> = {
export const Llama2ChatApi: Llama2ChatApi = {
requestTemplate: Llama2ChatTemplate,
responseGuard: isLlamaResponse,
};
5 changes: 4 additions & 1 deletion packages/core/src/apis/meta/llama3ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const Llama3ChatTemplate = new EjsTemplate<Llama3ChatOptions>(
templateSource,
);

export interface Llama3ChatApi
extends ModelApi<Llama3ChatOptions, LlamaResponse> {}

/**
*
* ## Reference
Expand All @@ -48,7 +51,7 @@ export const Llama3ChatTemplate = new EjsTemplate<Llama3ChatOptions>(
* @category Provider: AWS Bedrock
*
*/
export const Llama3ChatApi: ModelApi<Llama3ChatOptions, LlamaResponse> = {
export const Llama3ChatApi: Llama3ChatApi = {
requestTemplate: Llama3ChatTemplate,
responseGuard: isLlamaResponse,
};
8 changes: 4 additions & 4 deletions packages/core/src/apis/mistral/mistralBedrockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export function isMistralBedrockResponse(
return !isLeft(MistralBedrockResponseCodec.decode(response));
}

export interface MistralBedrockApi
extends ModelApi<MistralBedrockOptions, MistralBedrockResponse> {}

/**
*
* ## Reference
Expand All @@ -76,10 +79,7 @@ export function isMistralBedrockResponse(
* @category Provider: AWS Bedrock
*
*/
export const MistralBedrockApi: ModelApi<
MistralBedrockOptions,
MistralBedrockResponse
> = {
export const MistralBedrockApi: MistralBedrockApi = {
requestTemplate: MistralBedrockTemplate,
responseGuard: isMistralBedrockResponse,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import aws4 from "aws4";

import type { ModelApi } from "@typeDefs";

import { AwsBedrockModelProvider } from "./AwsBedrockModelProvider";
import { createAwsBedrockModelProvider } from "./createAwsBedrockModelProvider";

Expand All @@ -14,7 +12,7 @@ describe("AwsBedrockModelProvider", () => {
render: jest.fn().mockReturnValue("dummy-request-template-output"),
},
responseGuard: jest.fn().mockReturnValue(true),
} as unknown as ModelApi;
} as unknown as any;

const mockAuthConfig = {
AWS_ACCESS_KEY_ID: "dummy-access-key-id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import type {
HttpClient,
InferRequestOptions,
InferResponse,
ModelApi,
ModelId,
ModelRequestOptions,
} from "@typeDefs";

import {
Ai21Jurassic2Api,
AmazonTitanTextApi,
CohereGenerateApi,
Llama2ChatApi,
Llama3ChatApi,
MistralBedrockApi,
} from "../../apis";

import { AwsBedrockModelProvider } from "./AwsBedrockModelProvider";

import { AwsAuthConfig } from "./authConfig";

const DEFAULT_REGION = "us-east-1";

type AwsBedrockApi =
| Ai21Jurassic2Api
| AmazonTitanTextApi
| CohereGenerateApi
| Llama2ChatApi
| Llama3ChatApi
| MistralBedrockApi;

/**
*
* Creates an AWS Bedrock {@link ModelProvider} with the provided {@link ModelApi}.
Expand All @@ -31,7 +49,7 @@ const DEFAULT_REGION = "us-east-1";
* console.log(response.results[0]?.outputText);
* ```
*
* ### Known Compatible APIs:
* ### Compatible APIs
* - {@link AmazonTitanTextApi}
* - {@link CohereGenerateApi}
* - {@link Llama2ChatApi}
Expand All @@ -45,12 +63,12 @@ const DEFAULT_REGION = "us-east-1";
* @category Provider: AWS Bedrock
*
* @param {Object} params
* @param {ModelApi} params.api - The API instance to use for making requests.
* @param {AwsBedrockApi} params.api - The API instance to use for making requests.
* @param {string} params.modelId - The model ID as defined by AWS Bedrock.
* @param {HttpClient} [params.client] - HTTP client to use for requests. If not supplied, the built-in fetch-based implementation will be used.
* @param {AwsAuthConfig} [params.auth] - Authentication configuration for AWS. If not supplied, credentials will be loaded from the environment.
* @param {string} [params.region=us-east-1] - AWS region where the Bedrock model is deployed. Defaults to "us-east-1".
* @returns {AwsBedrockModelProvider<TRequestOptions, TResponse>} The AWS Bedrock Model Provider with the specified {@link ModelApi}.
* @returns {AwsBedrockModelProvider} The AWS Bedrock Model Provider with the specified {@link ModelApi}.
*
* @example Multiple APIs
* ```ts
Expand Down Expand Up @@ -100,23 +118,25 @@ const DEFAULT_REGION = "us-east-1";
* ```
*/
export function createAwsBedrockModelProvider<
TRequestOptions extends ModelRequestOptions,
TResponse = unknown,
TAwsBedrockApi extends AwsBedrockApi,
>({
api,
modelId,
client,
auth,
region = DEFAULT_REGION,
}: {
api: ModelApi<TRequestOptions, TResponse>;
api: TAwsBedrockApi;
modelId: ModelId;
client?: HttpClient;
auth?: AwsAuthConfig;
region?: string;
}) {
return new AwsBedrockModelProvider({
api,
api: api as ModelApi<
InferRequestOptions<TAwsBedrockApi>,
InferResponse<TAwsBedrockApi>
>,
modelId,
client,
auth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
ModelApi,
} from "@typeDefs";

import { CohereChatApi, CohereGenerateApi } from "../../apis/cohere";
import { CohereChatApi, CohereGenerateApi } from "../../apis";

import { BearerTokenAuthStrategy, HttpModelProvider } from "../http";

Expand Down Expand Up @@ -40,7 +40,7 @@ type CohereApi = CohereGenerateApi | CohereChatApi;
* @category Provider: Cohere
*
* @param {Object} params
* @param {CohereGenerateApi | CohereChatApi} [params.api] - The API to use for the provider. Defaults to {@link CohereChatApi}.
* @param {CohereApi} [params.api] - The API to use for the provider. Defaults to {@link CohereChatApi}.
* @param {string} params.modelId - The model ID as defined by Cohere.
* @param {HttpClient} [params.client] - HTTP client to use for requests. If not supplied, the built-in fetch-based implementation will be used.
* @param {CohereAuthConfig} [params.auth] - Authentication configuration for Cohere. If not supplied, it will be loaded from the environment.
Expand Down

0 comments on commit 7a65c15

Please sign in to comment.