@gammatech/aijsx 0.9.2-dev.2024-05-30 → 0.9.3-dev.2024-05-31
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 +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +45 -13
- package/dist/index.mjs +48 -14
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ 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 { GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
|
|
9
|
+
import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
|
|
10
10
|
export { VertexAI } from '@google-cloud/vertexai';
|
|
11
11
|
|
|
12
12
|
declare class ChatCompletionError extends Error {
|
|
@@ -168,6 +168,7 @@ declare namespace AISpanAttributes {
|
|
|
168
168
|
finishReason: string | null;
|
|
169
169
|
output: string;
|
|
170
170
|
tokensUsed: Usage;
|
|
171
|
+
[key: string]: any;
|
|
171
172
|
};
|
|
172
173
|
}
|
|
173
174
|
declare namespace ProcessedAISpanAttributes {
|
|
@@ -280,6 +281,11 @@ declare module '@gammatech/aijsx' {
|
|
|
280
281
|
interface ChatCompletionRequestPayloads {
|
|
281
282
|
google: GoogleChatCompletionRequest;
|
|
282
283
|
}
|
|
284
|
+
interface ChatCompletionResponseFields {
|
|
285
|
+
google: {
|
|
286
|
+
promptFeedback?: PromptFeedback;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
283
289
|
}
|
|
284
290
|
type ValidGoogleChatModel = 'gemini-1.5-pro' | 'gemini-1.5-flash';
|
|
285
291
|
declare const GoogleClientContext: Context<() => ChatCompletionClientAndProvider<VertexAI>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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 { GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
|
|
9
|
+
import { PromptFeedback, GenerateContentRequest, VertexAI } from '@google-cloud/vertexai';
|
|
10
10
|
export { VertexAI } from '@google-cloud/vertexai';
|
|
11
11
|
|
|
12
12
|
declare class ChatCompletionError extends Error {
|
|
@@ -168,6 +168,7 @@ declare namespace AISpanAttributes {
|
|
|
168
168
|
finishReason: string | null;
|
|
169
169
|
output: string;
|
|
170
170
|
tokensUsed: Usage;
|
|
171
|
+
[key: string]: any;
|
|
171
172
|
};
|
|
172
173
|
}
|
|
173
174
|
declare namespace ProcessedAISpanAttributes {
|
|
@@ -280,6 +281,11 @@ declare module '@gammatech/aijsx' {
|
|
|
280
281
|
interface ChatCompletionRequestPayloads {
|
|
281
282
|
google: GoogleChatCompletionRequest;
|
|
282
283
|
}
|
|
284
|
+
interface ChatCompletionResponseFields {
|
|
285
|
+
google: {
|
|
286
|
+
promptFeedback?: PromptFeedback;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
283
289
|
}
|
|
284
290
|
type ValidGoogleChatModel = 'gemini-1.5-pro' | 'gemini-1.5-flash';
|
|
285
291
|
declare const GoogleClientContext: Context<() => ChatCompletionClientAndProvider<VertexAI>>;
|
package/dist/index.js
CHANGED
|
@@ -2533,6 +2533,28 @@ var import_sdk2 = __toESM(require("@anthropic-ai/sdk"));
|
|
|
2533
2533
|
|
|
2534
2534
|
// src/lib/google/Google.tsx
|
|
2535
2535
|
var import_vertexai = require("@google-cloud/vertexai");
|
|
2536
|
+
var SAFETY_SETTINGS = [
|
|
2537
|
+
{
|
|
2538
|
+
category: import_vertexai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
2539
|
+
threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2540
|
+
},
|
|
2541
|
+
{
|
|
2542
|
+
category: import_vertexai.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
|
2543
|
+
threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2544
|
+
},
|
|
2545
|
+
{
|
|
2546
|
+
category: import_vertexai.HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
2547
|
+
threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2548
|
+
},
|
|
2549
|
+
{
|
|
2550
|
+
category: import_vertexai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
2551
|
+
threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2552
|
+
},
|
|
2553
|
+
{
|
|
2554
|
+
category: import_vertexai.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
|
2555
|
+
threshold: import_vertexai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2556
|
+
}
|
|
2557
|
+
];
|
|
2536
2558
|
var GoogleClientContext = createContext(() => {
|
|
2537
2559
|
if (defaultClient3) {
|
|
2538
2560
|
return defaultClient3;
|
|
@@ -2663,7 +2685,10 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2663
2685
|
inputMessages,
|
|
2664
2686
|
retryCount
|
|
2665
2687
|
});
|
|
2666
|
-
const model = client.getGenerativeModel({
|
|
2688
|
+
const model = client.getGenerativeModel({
|
|
2689
|
+
model: props.model,
|
|
2690
|
+
safetySettings: SAFETY_SETTINGS
|
|
2691
|
+
});
|
|
2667
2692
|
let response;
|
|
2668
2693
|
try {
|
|
2669
2694
|
response = await model.generateContentStream(googleCompletionRequest);
|
|
@@ -2702,21 +2727,28 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2702
2727
|
}
|
|
2703
2728
|
}
|
|
2704
2729
|
const chunk = event.candidates[0].content;
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2730
|
+
const noChunk = !chunk || !chunk.parts;
|
|
2731
|
+
if (event.promptFeedback) {
|
|
2732
|
+
span.setAttributes({
|
|
2733
|
+
promptFeedback: event.promptFeedback
|
|
2734
|
+
});
|
|
2735
|
+
}
|
|
2736
|
+
if (noChunk) {
|
|
2737
|
+
if (event.promptFeedback) {
|
|
2738
|
+
const blockReason = event.promptFeedback.blockReason;
|
|
2739
|
+
logger.error(
|
|
2740
|
+
`Could not finish chat completion, blockReason: ${blockReason}`,
|
|
2741
|
+
event.promptFeedback
|
|
2742
|
+
);
|
|
2743
|
+
}
|
|
2711
2744
|
continue;
|
|
2712
2745
|
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
yield block.text;
|
|
2718
|
-
}
|
|
2746
|
+
for (const block of chunk.parts) {
|
|
2747
|
+
if (block.text) {
|
|
2748
|
+
content += block.text;
|
|
2749
|
+
yield block.text;
|
|
2719
2750
|
}
|
|
2751
|
+
}
|
|
2720
2752
|
}
|
|
2721
2753
|
}
|
|
2722
2754
|
} catch (err) {
|
package/dist/index.mjs
CHANGED
|
@@ -2433,8 +2433,32 @@ import AnthropicClient2 from "@anthropic-ai/sdk";
|
|
|
2433
2433
|
// src/lib/google/Google.tsx
|
|
2434
2434
|
import {
|
|
2435
2435
|
VertexAI,
|
|
2436
|
-
GoogleGenerativeAIError
|
|
2436
|
+
GoogleGenerativeAIError,
|
|
2437
|
+
HarmCategory,
|
|
2438
|
+
HarmBlockThreshold
|
|
2437
2439
|
} from "@google-cloud/vertexai";
|
|
2440
|
+
var SAFETY_SETTINGS = [
|
|
2441
|
+
{
|
|
2442
|
+
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
2443
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2444
|
+
},
|
|
2445
|
+
{
|
|
2446
|
+
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
|
2447
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2448
|
+
},
|
|
2449
|
+
{
|
|
2450
|
+
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
2451
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2452
|
+
},
|
|
2453
|
+
{
|
|
2454
|
+
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
2455
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2456
|
+
},
|
|
2457
|
+
{
|
|
2458
|
+
category: HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
|
2459
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
2460
|
+
}
|
|
2461
|
+
];
|
|
2438
2462
|
var GoogleClientContext = createContext(() => {
|
|
2439
2463
|
if (defaultClient3) {
|
|
2440
2464
|
return defaultClient3;
|
|
@@ -2565,7 +2589,10 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2565
2589
|
inputMessages,
|
|
2566
2590
|
retryCount
|
|
2567
2591
|
});
|
|
2568
|
-
const model = client.getGenerativeModel({
|
|
2592
|
+
const model = client.getGenerativeModel({
|
|
2593
|
+
model: props.model,
|
|
2594
|
+
safetySettings: SAFETY_SETTINGS
|
|
2595
|
+
});
|
|
2569
2596
|
let response;
|
|
2570
2597
|
try {
|
|
2571
2598
|
response = await model.generateContentStream(googleCompletionRequest);
|
|
@@ -2604,21 +2631,28 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2604
2631
|
}
|
|
2605
2632
|
}
|
|
2606
2633
|
const chunk = event.candidates[0].content;
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2634
|
+
const noChunk = !chunk || !chunk.parts;
|
|
2635
|
+
if (event.promptFeedback) {
|
|
2636
|
+
span.setAttributes({
|
|
2637
|
+
promptFeedback: event.promptFeedback
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
if (noChunk) {
|
|
2641
|
+
if (event.promptFeedback) {
|
|
2642
|
+
const blockReason = event.promptFeedback.blockReason;
|
|
2643
|
+
logger.error(
|
|
2644
|
+
`Could not finish chat completion, blockReason: ${blockReason}`,
|
|
2645
|
+
event.promptFeedback
|
|
2646
|
+
);
|
|
2647
|
+
}
|
|
2613
2648
|
continue;
|
|
2614
2649
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
yield block.text;
|
|
2620
|
-
}
|
|
2650
|
+
for (const block of chunk.parts) {
|
|
2651
|
+
if (block.text) {
|
|
2652
|
+
content += block.text;
|
|
2653
|
+
yield block.text;
|
|
2621
2654
|
}
|
|
2655
|
+
}
|
|
2622
2656
|
}
|
|
2623
2657
|
}
|
|
2624
2658
|
} catch (err) {
|