@gammatech/aijsx 0.9.1-dev.2024-05-28 → 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 -4
- package/dist/index.mjs +48 -5
- 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;
|
|
@@ -2546,10 +2568,10 @@ var GoogleClientContext = createContext(() => {
|
|
|
2546
2568
|
return defaultClient3;
|
|
2547
2569
|
});
|
|
2548
2570
|
var defaultClient3 = null;
|
|
2549
|
-
var buildGoogleMessages = (
|
|
2571
|
+
var buildGoogleMessages = (chatMessages) => {
|
|
2550
2572
|
let systemInstruction;
|
|
2551
2573
|
const messages = [];
|
|
2552
|
-
|
|
2574
|
+
chatMessages.forEach(({ role, content }) => {
|
|
2553
2575
|
if (role === "system") {
|
|
2554
2576
|
systemInstruction = content;
|
|
2555
2577
|
return;
|
|
@@ -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);
|
|
@@ -2690,7 +2715,6 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2690
2715
|
try {
|
|
2691
2716
|
for await (const event of response.stream) {
|
|
2692
2717
|
if (event.candidates) {
|
|
2693
|
-
const chunk = event.candidates[0].content;
|
|
2694
2718
|
if (event.candidates[0]?.finishReason) {
|
|
2695
2719
|
finishReason = event.candidates[0].finishReason;
|
|
2696
2720
|
}
|
|
@@ -2702,6 +2726,23 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2702
2726
|
outputUsage = event.usageMetadata.candidatesTokenCount;
|
|
2703
2727
|
}
|
|
2704
2728
|
}
|
|
2729
|
+
const chunk = event.candidates[0].content;
|
|
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
|
+
}
|
|
2744
|
+
continue;
|
|
2745
|
+
}
|
|
2705
2746
|
for (const block of chunk.parts) {
|
|
2706
2747
|
if (block.text) {
|
|
2707
2748
|
content += block.text;
|
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;
|
|
@@ -2448,10 +2472,10 @@ var GoogleClientContext = createContext(() => {
|
|
|
2448
2472
|
return defaultClient3;
|
|
2449
2473
|
});
|
|
2450
2474
|
var defaultClient3 = null;
|
|
2451
|
-
var buildGoogleMessages = (
|
|
2475
|
+
var buildGoogleMessages = (chatMessages) => {
|
|
2452
2476
|
let systemInstruction;
|
|
2453
2477
|
const messages = [];
|
|
2454
|
-
|
|
2478
|
+
chatMessages.forEach(({ role, content }) => {
|
|
2455
2479
|
if (role === "system") {
|
|
2456
2480
|
systemInstruction = content;
|
|
2457
2481
|
return;
|
|
@@ -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);
|
|
@@ -2592,7 +2619,6 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2592
2619
|
try {
|
|
2593
2620
|
for await (const event of response.stream) {
|
|
2594
2621
|
if (event.candidates) {
|
|
2595
|
-
const chunk = event.candidates[0].content;
|
|
2596
2622
|
if (event.candidates[0]?.finishReason) {
|
|
2597
2623
|
finishReason = event.candidates[0].finishReason;
|
|
2598
2624
|
}
|
|
@@ -2604,6 +2630,23 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2604
2630
|
outputUsage = event.usageMetadata.candidatesTokenCount;
|
|
2605
2631
|
}
|
|
2606
2632
|
}
|
|
2633
|
+
const chunk = event.candidates[0].content;
|
|
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
|
+
}
|
|
2648
|
+
continue;
|
|
2649
|
+
}
|
|
2607
2650
|
for (const block of chunk.parts) {
|
|
2608
2651
|
if (block.text) {
|
|
2609
2652
|
content += block.text;
|