@gammatech/aijsx 0.10.0-dev.2024-06-04.2 → 0.10.2-dev.2024-06-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -6,8 +6,8 @@ export { OpenAI as OpenAIClient } from 'openai';
6
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
7
7
  import AnthropicClient from '@anthropic-ai/sdk';
8
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
9
- import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
10
- export { VertexAI } from '@google-cloud/vertexai';
9
+ import { PromptFeedback, GenerateContentRequest, VertexAI, HarmCategory, HarmBlockThreshold } from '@google-cloud/vertexai';
10
+ export { HarmBlockThreshold as GoogleHarmBlockThreshold, HarmCategory as GoogleHarmCategory, VertexAI } from '@google-cloud/vertexai';
11
11
 
12
12
  declare class ChatCompletionError extends Error {
13
13
  readonly chatCompletionRequest: LogChatCompletionRequest;
@@ -87,7 +87,6 @@ declare const tracing: AITraceAPI;
87
87
 
88
88
  declare class SpanTree {
89
89
  roots: SpanTreeNode[];
90
- findSpan: any;
91
90
  addSpan(span: ReadableSpan): boolean;
92
91
  findNode(id: string): SpanTreeNode | null;
93
92
  }
@@ -300,6 +299,10 @@ type GoogleChatCompletionProps = {
300
299
  stop?: string | string[];
301
300
  maxRetries?: number;
302
301
  children: AINode;
302
+ safetySettings?: {
303
+ category: HarmCategory;
304
+ threshold: HarmBlockThreshold;
305
+ }[];
303
306
  };
304
307
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
305
308
 
package/dist/index.d.ts CHANGED
@@ -6,8 +6,8 @@ export { OpenAI as OpenAIClient } from 'openai';
6
6
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionCreateParams } from 'openai/resources';
7
7
  import AnthropicClient from '@anthropic-ai/sdk';
8
8
  export { default as AnthropicClient } from '@anthropic-ai/sdk';
9
- import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
10
- export { VertexAI } from '@google-cloud/vertexai';
9
+ import { PromptFeedback, GenerateContentRequest, VertexAI, HarmCategory, HarmBlockThreshold } from '@google-cloud/vertexai';
10
+ export { HarmBlockThreshold as GoogleHarmBlockThreshold, HarmCategory as GoogleHarmCategory, VertexAI } from '@google-cloud/vertexai';
11
11
 
12
12
  declare class ChatCompletionError extends Error {
13
13
  readonly chatCompletionRequest: LogChatCompletionRequest;
@@ -87,7 +87,6 @@ declare const tracing: AITraceAPI;
87
87
 
88
88
  declare class SpanTree {
89
89
  roots: SpanTreeNode[];
90
- findSpan: any;
91
90
  addSpan(span: ReadableSpan): boolean;
92
91
  findNode(id: string): SpanTreeNode | null;
93
92
  }
@@ -300,6 +299,10 @@ type GoogleChatCompletionProps = {
300
299
  stop?: string | string[];
301
300
  maxRetries?: number;
302
301
  children: AINode;
302
+ safetySettings?: {
303
+ category: HarmCategory;
304
+ threshold: HarmBlockThreshold;
305
+ }[];
303
306
  };
304
307
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
305
308
 
package/dist/index.js CHANGED
@@ -44,6 +44,8 @@ __export(src_exports, {
44
44
  Fallback: () => Fallback,
45
45
  GoogleChatCompletion: () => GoogleChatCompletion,
46
46
  GoogleClientContext: () => GoogleClientContext,
47
+ GoogleHarmBlockThreshold: () => import_vertexai2.HarmBlockThreshold,
48
+ GoogleHarmCategory: () => import_vertexai2.HarmCategory,
47
49
  ImagePart: () => ImagePart,
48
50
  LogImplementation: () => LogImplementation,
49
51
  NoopLogImplementation: () => NoopLogImplementation,
@@ -1587,7 +1589,6 @@ async function* Fallback({ shouldFallback = () => true, fallback, children }, ct
1587
1589
  // src/tracing/SpanTree.ts
1588
1590
  var SpanTree = class {
1589
1591
  roots = [];
1590
- findSpan;
1591
1592
  addSpan(span) {
1592
1593
  const parentId = span.parentSpanId;
1593
1594
  if (!parentId) {
@@ -2574,7 +2575,34 @@ var import_sdk2 = __toESM(require("@anthropic-ai/sdk"));
2574
2575
 
2575
2576
  // src/lib/google/Google.tsx
2576
2577
  var import_vertexai = require("@google-cloud/vertexai");
2577
- var SAFETY_SETTINGS = [
2578
+
2579
+ // src/lib/google/errors.ts
2580
+ var extractStatusFromMessage = (message) => {
2581
+ const RE_STATUS = /status: (\d{3})/;
2582
+ const matchStatus = message.match(RE_STATUS);
2583
+ if (matchStatus !== null) {
2584
+ return parseInt(matchStatus[1]);
2585
+ }
2586
+ const RE_GOOGLE_GENERATIVE_AI_ERROR = /\[VertexAI.GoogleGenerativeAIError\]/;
2587
+ const matchErrorName = message.match(RE_GOOGLE_GENERATIVE_AI_ERROR);
2588
+ if (matchErrorName !== null) {
2589
+ return 500;
2590
+ }
2591
+ return 500;
2592
+ };
2593
+ var errorToChatCompletionError = (error, requestData) => {
2594
+ const status = extractStatusFromMessage(error.message);
2595
+ const shouldRetry4 = status !== 400;
2596
+ return new ChatCompletionError(
2597
+ error.message,
2598
+ requestData,
2599
+ status,
2600
+ shouldRetry4
2601
+ );
2602
+ };
2603
+
2604
+ // src/lib/google/Google.tsx
2605
+ var DEFAULT_SAFETY_SETTINGS = [
2578
2606
  {
2579
2607
  category: import_vertexai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
2580
2608
  threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
@@ -2728,26 +2756,13 @@ async function* GoogleChatCompletionInner(props, ctx) {
2728
2756
  });
2729
2757
  const model = client.getGenerativeModel({
2730
2758
  model: props.model,
2731
- safetySettings: SAFETY_SETTINGS
2759
+ safetySettings: props.safetySettings || DEFAULT_SAFETY_SETTINGS
2732
2760
  });
2733
2761
  let response;
2734
2762
  try {
2735
2763
  response = await model.generateContentStream(googleCompletionRequest);
2736
2764
  } catch (err) {
2737
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2738
- throw new ChatCompletionError(
2739
- err.message,
2740
- logRequestData,
2741
- void 0,
2742
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2743
- true
2744
- );
2745
- } else if (err instanceof Error) {
2746
- const status = void 0;
2747
- const retry = false;
2748
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2749
- }
2750
- throw err;
2765
+ throw errorToChatCompletionError(err, logRequestData);
2751
2766
  }
2752
2767
  let content = "";
2753
2768
  let outputUsage = 0;
@@ -2793,20 +2808,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2793
2808
  }
2794
2809
  }
2795
2810
  } catch (err) {
2796
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2797
- throw new ChatCompletionError(
2798
- err.message,
2799
- logRequestData,
2800
- void 0,
2801
- // always retry these errors they represent non 4xx error cases
2802
- true
2803
- );
2804
- } else if (err instanceof Error) {
2805
- const status = void 0;
2806
- const retry = false;
2807
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2808
- }
2809
- throw err;
2811
+ throw errorToChatCompletionError(err, logRequestData);
2810
2812
  }
2811
2813
  const outputMessage = {
2812
2814
  role: "assistant",
@@ -2882,6 +2884,8 @@ var import_vertexai2 = require("@google-cloud/vertexai");
2882
2884
  Fallback,
2883
2885
  GoogleChatCompletion,
2884
2886
  GoogleClientContext,
2887
+ GoogleHarmBlockThreshold,
2888
+ GoogleHarmCategory,
2885
2889
  ImagePart,
2886
2890
  LogImplementation,
2887
2891
  NoopLogImplementation,
package/dist/index.mjs CHANGED
@@ -1487,7 +1487,6 @@ async function* Fallback({ shouldFallback = () => true, fallback, children }, ct
1487
1487
  // src/tracing/SpanTree.ts
1488
1488
  var SpanTree = class {
1489
1489
  roots = [];
1490
- findSpan;
1491
1490
  addSpan(span) {
1492
1491
  const parentId = span.parentSpanId;
1493
1492
  if (!parentId) {
@@ -2474,12 +2473,38 @@ import AnthropicClient2 from "@anthropic-ai/sdk";
2474
2473
 
2475
2474
  // src/lib/google/Google.tsx
2476
2475
  import {
2477
- VertexAI,
2478
- GoogleGenerativeAIError,
2476
+ HarmBlockThreshold,
2479
2477
  HarmCategory,
2480
- HarmBlockThreshold
2478
+ VertexAI
2481
2479
  } from "@google-cloud/vertexai";
2482
- var SAFETY_SETTINGS = [
2480
+
2481
+ // src/lib/google/errors.ts
2482
+ var extractStatusFromMessage = (message) => {
2483
+ const RE_STATUS = /status: (\d{3})/;
2484
+ const matchStatus = message.match(RE_STATUS);
2485
+ if (matchStatus !== null) {
2486
+ return parseInt(matchStatus[1]);
2487
+ }
2488
+ const RE_GOOGLE_GENERATIVE_AI_ERROR = /\[VertexAI.GoogleGenerativeAIError\]/;
2489
+ const matchErrorName = message.match(RE_GOOGLE_GENERATIVE_AI_ERROR);
2490
+ if (matchErrorName !== null) {
2491
+ return 500;
2492
+ }
2493
+ return 500;
2494
+ };
2495
+ var errorToChatCompletionError = (error, requestData) => {
2496
+ const status = extractStatusFromMessage(error.message);
2497
+ const shouldRetry4 = status !== 400;
2498
+ return new ChatCompletionError(
2499
+ error.message,
2500
+ requestData,
2501
+ status,
2502
+ shouldRetry4
2503
+ );
2504
+ };
2505
+
2506
+ // src/lib/google/Google.tsx
2507
+ var DEFAULT_SAFETY_SETTINGS = [
2483
2508
  {
2484
2509
  category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
2485
2510
  threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
@@ -2633,26 +2658,13 @@ async function* GoogleChatCompletionInner(props, ctx) {
2633
2658
  });
2634
2659
  const model = client.getGenerativeModel({
2635
2660
  model: props.model,
2636
- safetySettings: SAFETY_SETTINGS
2661
+ safetySettings: props.safetySettings || DEFAULT_SAFETY_SETTINGS
2637
2662
  });
2638
2663
  let response;
2639
2664
  try {
2640
2665
  response = await model.generateContentStream(googleCompletionRequest);
2641
2666
  } catch (err) {
2642
- if (err instanceof GoogleGenerativeAIError) {
2643
- throw new ChatCompletionError(
2644
- err.message,
2645
- logRequestData,
2646
- void 0,
2647
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2648
- true
2649
- );
2650
- } else if (err instanceof Error) {
2651
- const status = void 0;
2652
- const retry = false;
2653
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2654
- }
2655
- throw err;
2667
+ throw errorToChatCompletionError(err, logRequestData);
2656
2668
  }
2657
2669
  let content = "";
2658
2670
  let outputUsage = 0;
@@ -2698,20 +2710,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2698
2710
  }
2699
2711
  }
2700
2712
  } catch (err) {
2701
- if (err instanceof GoogleGenerativeAIError) {
2702
- throw new ChatCompletionError(
2703
- err.message,
2704
- logRequestData,
2705
- void 0,
2706
- // always retry these errors they represent non 4xx error cases
2707
- true
2708
- );
2709
- } else if (err instanceof Error) {
2710
- const status = void 0;
2711
- const retry = false;
2712
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2713
- }
2714
- throw err;
2713
+ throw errorToChatCompletionError(err, logRequestData);
2715
2714
  }
2716
2715
  const outputMessage = {
2717
2716
  role: "assistant",
@@ -2769,7 +2768,11 @@ function cleanChatCompletionRequest3(chatCompletionRequest) {
2769
2768
  }
2770
2769
 
2771
2770
  // src/lib/google/index.ts
2772
- import { VertexAI as VertexAI2 } from "@google-cloud/vertexai";
2771
+ import {
2772
+ VertexAI as VertexAI2,
2773
+ HarmBlockThreshold as HarmBlockThreshold2,
2774
+ HarmCategory as HarmCategory2
2775
+ } from "@google-cloud/vertexai";
2773
2776
  export {
2774
2777
  AIFragment,
2775
2778
  AISpanProcessor,
@@ -2786,6 +2789,8 @@ export {
2786
2789
  Fallback,
2787
2790
  GoogleChatCompletion,
2788
2791
  GoogleClientContext,
2792
+ HarmBlockThreshold2 as GoogleHarmBlockThreshold,
2793
+ HarmCategory2 as GoogleHarmCategory,
2789
2794
  ImagePart,
2790
2795
  LogImplementation,
2791
2796
  NoopLogImplementation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gammatech/aijsx",
3
- "version": "0.10.0-dev.2024-06-04.2",
3
+ "version": "0.10.2-dev.2024-06-11",
4
4
  "description": "Rewrite of aijsx",
5
5
  "author": "Jordan Garcia",
6
6
  "license": "MIT",