@gammatech/aijsx 0.6.2-dev.2024-05-02 → 0.7.0-dev.2024-05-14
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 +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +24 -0
- package/dist/index.mjs +23 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,13 @@ type RetryProps = {
|
|
|
27
27
|
};
|
|
28
28
|
declare function Retry({ shouldRetry, retries, maxRetries, children }: RetryProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
29
29
|
|
|
30
|
+
type FallbackProps = {
|
|
31
|
+
fallback: AINode;
|
|
32
|
+
shouldFallback: (error: Error) => boolean;
|
|
33
|
+
children: AINode;
|
|
34
|
+
};
|
|
35
|
+
declare function Fallback({ shouldFallback, fallback, children }: FallbackProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
36
|
+
|
|
30
37
|
declare class AITraceAPI {
|
|
31
38
|
private static _instance?;
|
|
32
39
|
private enabled;
|
|
@@ -145,7 +152,7 @@ declare module '@gammatech/aijsx' {
|
|
|
145
152
|
openai: OpenAIChatCompletionRequest;
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
|
-
type ValidOpenAIChatModel = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
|
|
155
|
+
type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
|
|
149
156
|
declare const OpenAIClientContext: Context<() => ChatCompletionClientAndProvider<OpenAI>>;
|
|
150
157
|
type OpenAIChatCompletionProps = {
|
|
151
158
|
model: ValidOpenAIChatModel;
|
|
@@ -158,7 +165,7 @@ type OpenAIChatCompletionProps = {
|
|
|
158
165
|
};
|
|
159
166
|
declare function OpenAIChatCompletion(props: OpenAIChatCompletionProps, ctx: RenderContext): AINode;
|
|
160
167
|
|
|
161
|
-
type ValidOpenAIVisionModel = 'gpt-4-vision-preview';
|
|
168
|
+
type ValidOpenAIVisionModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4-vision-preview';
|
|
162
169
|
declare const ContentTypeImage: (_props: {
|
|
163
170
|
url: string;
|
|
164
171
|
dimensions?: {
|
|
@@ -226,4 +233,4 @@ type ClaudeImageBlockUrl = {
|
|
|
226
233
|
type ClaudeImageBlockProps = ClaudeImageBlockBase64 | ClaudeImageBlockUrl;
|
|
227
234
|
declare const ClaudeImageBlock: (props: ClaudeImageBlockProps) => Promise<JSX.Element>;
|
|
228
235
|
|
|
229
|
-
export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
|
|
236
|
+
export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ type RetryProps = {
|
|
|
27
27
|
};
|
|
28
28
|
declare function Retry({ shouldRetry, retries, maxRetries, children }: RetryProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
29
29
|
|
|
30
|
+
type FallbackProps = {
|
|
31
|
+
fallback: AINode;
|
|
32
|
+
shouldFallback: (error: Error) => boolean;
|
|
33
|
+
children: AINode;
|
|
34
|
+
};
|
|
35
|
+
declare function Fallback({ shouldFallback, fallback, children }: FallbackProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
36
|
+
|
|
30
37
|
declare class AITraceAPI {
|
|
31
38
|
private static _instance?;
|
|
32
39
|
private enabled;
|
|
@@ -145,7 +152,7 @@ declare module '@gammatech/aijsx' {
|
|
|
145
152
|
openai: OpenAIChatCompletionRequest;
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
|
-
type ValidOpenAIChatModel = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
|
|
155
|
+
type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
|
|
149
156
|
declare const OpenAIClientContext: Context<() => ChatCompletionClientAndProvider<OpenAI>>;
|
|
150
157
|
type OpenAIChatCompletionProps = {
|
|
151
158
|
model: ValidOpenAIChatModel;
|
|
@@ -158,7 +165,7 @@ type OpenAIChatCompletionProps = {
|
|
|
158
165
|
};
|
|
159
166
|
declare function OpenAIChatCompletion(props: OpenAIChatCompletionProps, ctx: RenderContext): AINode;
|
|
160
167
|
|
|
161
|
-
type ValidOpenAIVisionModel = 'gpt-4-vision-preview';
|
|
168
|
+
type ValidOpenAIVisionModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4-vision-preview';
|
|
162
169
|
declare const ContentTypeImage: (_props: {
|
|
163
170
|
url: string;
|
|
164
171
|
dimensions?: {
|
|
@@ -226,4 +233,4 @@ type ClaudeImageBlockUrl = {
|
|
|
226
233
|
type ClaudeImageBlockProps = ClaudeImageBlockBase64 | ClaudeImageBlockUrl;
|
|
227
234
|
declare const ClaudeImageBlock: (props: ClaudeImageBlockProps) => Promise<JSX.Element>;
|
|
228
235
|
|
|
229
|
-
export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
|
|
236
|
+
export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ __export(src_exports, {
|
|
|
44
44
|
ContentTypeImage: () => ContentTypeImage,
|
|
45
45
|
DefaultMaxRetriesContext: () => DefaultMaxRetriesContext,
|
|
46
46
|
EnrichingSpanProcessor: () => EnrichingSpanProcessor,
|
|
47
|
+
Fallback: () => Fallback,
|
|
47
48
|
LogImplementation: () => LogImplementation,
|
|
48
49
|
NoopLogImplementation: () => NoopLogImplementation,
|
|
49
50
|
OpenAIChatCompletion: () => OpenAIChatCompletion,
|
|
@@ -1470,6 +1471,24 @@ async function* Retry({ shouldRetry: shouldRetry4, retries = 0, maxRetries = 3,
|
|
|
1470
1471
|
}
|
|
1471
1472
|
}
|
|
1472
1473
|
|
|
1474
|
+
// src/fallback.tsx
|
|
1475
|
+
async function* Fallback({ shouldFallback, fallback, children }, ctx) {
|
|
1476
|
+
const { render } = ctx;
|
|
1477
|
+
let hasYieldedData = false;
|
|
1478
|
+
try {
|
|
1479
|
+
const result = render(children);
|
|
1480
|
+
for await (const value of result) {
|
|
1481
|
+
hasYieldedData = true;
|
|
1482
|
+
yield value;
|
|
1483
|
+
}
|
|
1484
|
+
} catch (e) {
|
|
1485
|
+
if (hasYieldedData || !shouldFallback(e)) {
|
|
1486
|
+
throw e;
|
|
1487
|
+
}
|
|
1488
|
+
yield* render(fallback);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1473
1492
|
// src/prompt/evaluatePrompt.ts
|
|
1474
1493
|
async function evaluatePrompt(prompt, variables, result) {
|
|
1475
1494
|
const { error, parsedVariables } = parseVariables(prompt.schema, variables);
|
|
@@ -1723,6 +1742,10 @@ function tokenLimitForChatModel(model) {
|
|
|
1723
1742
|
case "gpt-4-32k-0314":
|
|
1724
1743
|
case "gpt-4-32k-0613":
|
|
1725
1744
|
return 32768 - TOKENS_CONSUMED_BY_REPLY_PREFIX;
|
|
1745
|
+
case "gpt-4o":
|
|
1746
|
+
case "gpt-4o-2024-05-13":
|
|
1747
|
+
case "gpt-4-turbo-2024-04-09":
|
|
1748
|
+
case "gpt-4-turbo":
|
|
1726
1749
|
case "gpt-4-1106-preview":
|
|
1727
1750
|
case "gpt-4-0125-preview":
|
|
1728
1751
|
return 128e3 - TOKENS_CONSUMED_BY_REPLY_PREFIX;
|
|
@@ -2642,6 +2665,7 @@ var import_tokenizer4 = require("@anthropic-ai/tokenizer");
|
|
|
2642
2665
|
ContentTypeImage,
|
|
2643
2666
|
DefaultMaxRetriesContext,
|
|
2644
2667
|
EnrichingSpanProcessor,
|
|
2668
|
+
Fallback,
|
|
2645
2669
|
LogImplementation,
|
|
2646
2670
|
NoopLogImplementation,
|
|
2647
2671
|
OpenAIChatCompletion,
|
package/dist/index.mjs
CHANGED
|
@@ -1367,6 +1367,24 @@ async function* Retry({ shouldRetry: shouldRetry4, retries = 0, maxRetries = 3,
|
|
|
1367
1367
|
}
|
|
1368
1368
|
}
|
|
1369
1369
|
|
|
1370
|
+
// src/fallback.tsx
|
|
1371
|
+
async function* Fallback({ shouldFallback, fallback, children }, ctx) {
|
|
1372
|
+
const { render } = ctx;
|
|
1373
|
+
let hasYieldedData = false;
|
|
1374
|
+
try {
|
|
1375
|
+
const result = render(children);
|
|
1376
|
+
for await (const value of result) {
|
|
1377
|
+
hasYieldedData = true;
|
|
1378
|
+
yield value;
|
|
1379
|
+
}
|
|
1380
|
+
} catch (e) {
|
|
1381
|
+
if (hasYieldedData || !shouldFallback(e)) {
|
|
1382
|
+
throw e;
|
|
1383
|
+
}
|
|
1384
|
+
yield* render(fallback);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1370
1388
|
// src/prompt/evaluatePrompt.ts
|
|
1371
1389
|
async function evaluatePrompt(prompt, variables, result) {
|
|
1372
1390
|
const { error, parsedVariables } = parseVariables(prompt.schema, variables);
|
|
@@ -1620,6 +1638,10 @@ function tokenLimitForChatModel(model) {
|
|
|
1620
1638
|
case "gpt-4-32k-0314":
|
|
1621
1639
|
case "gpt-4-32k-0613":
|
|
1622
1640
|
return 32768 - TOKENS_CONSUMED_BY_REPLY_PREFIX;
|
|
1641
|
+
case "gpt-4o":
|
|
1642
|
+
case "gpt-4o-2024-05-13":
|
|
1643
|
+
case "gpt-4-turbo-2024-04-09":
|
|
1644
|
+
case "gpt-4-turbo":
|
|
1623
1645
|
case "gpt-4-1106-preview":
|
|
1624
1646
|
case "gpt-4-0125-preview":
|
|
1625
1647
|
return 128e3 - TOKENS_CONSUMED_BY_REPLY_PREFIX;
|
|
@@ -2538,6 +2560,7 @@ export {
|
|
|
2538
2560
|
ContentTypeImage,
|
|
2539
2561
|
DefaultMaxRetriesContext,
|
|
2540
2562
|
EnrichingSpanProcessor,
|
|
2563
|
+
Fallback,
|
|
2541
2564
|
LogImplementation,
|
|
2542
2565
|
NoopLogImplementation,
|
|
2543
2566
|
OpenAIChatCompletion,
|