nsarrazin HF Staff commited on
Commit
f13ecff
·
unverified ·
1 Parent(s): 0c29e99

fix(endpoints): make bedrock import optional (#1468)

Browse files
src/lib/server/endpoints/aws/endpointBedrock.ts CHANGED
@@ -1,10 +1,6 @@
1
  import { z } from "zod";
2
  import type { Endpoint } from "../endpoints";
3
  import type { TextGenerationStreamOutput } from "@huggingface/inference";
4
- import {
5
- BedrockRuntimeClient,
6
- InvokeModelWithResponseStreamCommand,
7
- } from "@aws-sdk/client-bedrock-runtime";
8
  import { createImageProcessorOptionsValidator, makeImageProcessor } from "../images";
9
  import type { EndpointMessage } from "../endpoints";
10
  import type { MessageFile } from "$lib/types/Message";
@@ -40,6 +36,16 @@ export async function endpointBedrock(
40
  ): Promise<Endpoint> {
41
  const { region, model, anthropicVersion, multimodal } =
42
  endpointBedrockParametersSchema.parse(input);
 
 
 
 
 
 
 
 
 
 
43
  const client = new BedrockRuntimeClient({
44
  region,
45
  });
 
1
  import { z } from "zod";
2
  import type { Endpoint } from "../endpoints";
3
  import type { TextGenerationStreamOutput } from "@huggingface/inference";
 
 
 
 
4
  import { createImageProcessorOptionsValidator, makeImageProcessor } from "../images";
5
  import type { EndpointMessage } from "../endpoints";
6
  import type { MessageFile } from "$lib/types/Message";
 
36
  ): Promise<Endpoint> {
37
  const { region, model, anthropicVersion, multimodal } =
38
  endpointBedrockParametersSchema.parse(input);
39
+
40
+ let BedrockRuntimeClient, InvokeModelWithResponseStreamCommand;
41
+ try {
42
+ ({ BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } = await import(
43
+ "@aws-sdk/client-bedrock-runtime"
44
+ ));
45
+ } catch (error) {
46
+ throw new Error("Failed to import @aws-sdk/client-bedrock-runtime. Make sure it's installed.");
47
+ }
48
+
49
  const client = new BedrockRuntimeClient({
50
  region,
51
  });