@gammatech/aijsx 0.5.0-beta.1 → 0.5.0-dev.2024-03-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/README.md +2 -0
- package/dist/index.d.mts +91 -390
- package/dist/index.d.ts +91 -390
- package/dist/index.js +1131 -1040
- package/dist/index.mjs +1125 -1035
- package/dist/{createElement--C_Hwi_c.d.mts → jsx-dev-runtime-zWb34twz.d.mts} +234 -109
- package/dist/{createElement--C_Hwi_c.d.ts → jsx-dev-runtime-zWb34twz.d.ts} +234 -109
- package/dist/jsx-dev-runtime.d.mts +1 -2
- package/dist/jsx-dev-runtime.d.ts +1 -2
- package/dist/jsx-runtime.d.mts +1 -29
- package/dist/jsx-runtime.d.ts +1 -29
- package/package.json +3 -2
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,402 +1,93 @@
|
|
|
1
|
-
import { R as RenderContext, C as ContextValues,
|
|
2
|
-
export {
|
|
1
|
+
import { R as RenderContext, L as LogImplementation, S as SpanProcessor, C as ContextValues, T as Tracer, a as ReadableSpan, b as SpanExporter, A as AIComponent, c as AINode, d as SpanAttributes, E as EvaluatorFn, P as PromptParsed, e as Prompt, N as NotAsyncGenerator, F as FunctionChain, f as StreamChain, g as EvaluatorResult, h as Context, J as JSX } from './jsx-dev-runtime-zWb34twz.mjs';
|
|
2
|
+
export { H as AIElement, j as AIFragment, n as AssistantMessage, B as BoundLogger, q as ChatCompletionError, r as ChatCompletionRequestPayloads, l as ChatCompletionRole, y as CombinedLogger, x as ConsoleLogger, z as Literal, s as LogChatCompletionRequest, t as LogChatCompletionResponse, u as LogLevel, v as Logger, w as NoopLogImplementation, Z as OutputParser, K as PropsOfAIComponent, D as RenderResult, I as Renderable, o as RenderedConversationMessage, Q as Span, M as SpanContext, V as SpanEvent, O as SpanStatus, m as SystemMessage, X as TracingContext, W as TracingContextKey, Y as TracingContextManager, U as UserMessage, G as attachedContextSymbol, p as computeUsage, i as createAIElement, k as createContext } from './jsx-dev-runtime-zWb34twz.mjs';
|
|
3
3
|
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
4
4
|
import { OpenAI } from 'openai';
|
|
5
5
|
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 { ImageBlockParam } from '@anthropic-ai/sdk/resources';
|
|
9
10
|
export { countTokens as countAnthropicTokens } from '@anthropic-ai/tokenizer';
|
|
10
11
|
|
|
11
|
-
interface ExceptionWithCode {
|
|
12
|
-
code: string | number;
|
|
13
|
-
name?: string;
|
|
14
|
-
message?: string;
|
|
15
|
-
stack?: string;
|
|
16
|
-
}
|
|
17
|
-
interface ExceptionWithMessage {
|
|
18
|
-
code?: string | number;
|
|
19
|
-
message: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
stack?: string;
|
|
22
|
-
}
|
|
23
|
-
interface ExceptionWithName {
|
|
24
|
-
code?: string | number;
|
|
25
|
-
message?: string;
|
|
26
|
-
name: string;
|
|
27
|
-
stack?: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Defines Exception.
|
|
31
|
-
*
|
|
32
|
-
* string or an object with one of (message or name or code) and optional stack
|
|
33
|
-
*/
|
|
34
|
-
type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
|
|
35
|
-
|
|
36
|
-
declare class HrTime {
|
|
37
|
-
readonly time: [number, number];
|
|
38
|
-
constructor(time: [number, number]);
|
|
39
|
-
static now(): HrTime;
|
|
40
|
-
toISOString(): string;
|
|
41
|
-
minus(other: HrTime): number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type SpanAttributes = Record<string, any>;
|
|
45
|
-
interface SpanStatus {
|
|
46
|
-
/** The status code of this message. */
|
|
47
|
-
code: SpanStatusCode;
|
|
48
|
-
/** A developer-facing error message. */
|
|
49
|
-
message?: string;
|
|
50
|
-
}
|
|
51
|
-
interface SpanEvent {
|
|
52
|
-
timestamp: string;
|
|
53
|
-
time: [number, number];
|
|
54
|
-
name: string;
|
|
55
|
-
attributes: Record<string, any>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* An enumeration of status codes.
|
|
59
|
-
*/
|
|
60
|
-
declare enum SpanStatusCode {
|
|
61
|
-
/**
|
|
62
|
-
* The default status.
|
|
63
|
-
*/
|
|
64
|
-
UNSET = 0,
|
|
65
|
-
/**
|
|
66
|
-
* The operation has been validated by an Application developer or
|
|
67
|
-
* Operator to have completed successfully.
|
|
68
|
-
*/
|
|
69
|
-
OK = 1,
|
|
70
|
-
/**
|
|
71
|
-
* The operation contains an error.
|
|
72
|
-
*/
|
|
73
|
-
ERROR = 2
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* A SpanContext represents the portion of a {@link Span} which must be
|
|
77
|
-
* serialized and propagated along side of a {@link Baggage}.
|
|
78
|
-
*/
|
|
79
|
-
interface SpanContext {
|
|
80
|
-
/**
|
|
81
|
-
* The ID of the trace that this span belongs to. It is worldwide unique
|
|
82
|
-
* with practically sufficient probability by being made as 16 randomly
|
|
83
|
-
* generated bytes, encoded as a 32 lowercase hex characters corresponding to
|
|
84
|
-
* 128 bits.
|
|
85
|
-
*/
|
|
86
|
-
traceId: string;
|
|
87
|
-
/**
|
|
88
|
-
* The ID of the Span. It is globally unique with practically sufficient
|
|
89
|
-
* probability by being made as 8 randomly generated bytes, encoded as a 16
|
|
90
|
-
* lowercase hex characters corresponding to 64 bits.
|
|
91
|
-
*/
|
|
92
|
-
spanId: string;
|
|
93
|
-
}
|
|
94
|
-
interface Span {
|
|
95
|
-
name: string;
|
|
96
|
-
parentSpanId: string | null;
|
|
97
|
-
startTime: string;
|
|
98
|
-
endTime: string | null;
|
|
99
|
-
duration: number;
|
|
100
|
-
events: SpanEvent[];
|
|
101
|
-
/**
|
|
102
|
-
* Returns the {@link SpanContext} object associated with this Span.
|
|
103
|
-
*
|
|
104
|
-
* Get an immutable, serializable identifier for this span that can be used
|
|
105
|
-
* to create new child spans. Returned SpanContext is usable even after the
|
|
106
|
-
* span ends.
|
|
107
|
-
*
|
|
108
|
-
* @returns the SpanContext object associated with this Span.
|
|
109
|
-
*/
|
|
110
|
-
spanContext(): SpanContext;
|
|
111
|
-
attributes: SpanAttributes;
|
|
112
|
-
/**
|
|
113
|
-
* Sets an attribute to the span.
|
|
114
|
-
*
|
|
115
|
-
* Sets a single Attribute with the key and value passed as arguments.
|
|
116
|
-
*
|
|
117
|
-
* @param key the key for this attribute.
|
|
118
|
-
* @param value the value for this attribute. Setting a value null or
|
|
119
|
-
* undefined is invalid and will result in undefined behavior.
|
|
120
|
-
*/
|
|
121
|
-
setAttribute(key: string, value: any): this;
|
|
122
|
-
/**
|
|
123
|
-
* Sets attributes to the span.
|
|
124
|
-
*
|
|
125
|
-
* @param attributes the attributes that will be added.
|
|
126
|
-
* null or undefined attribute values
|
|
127
|
-
* are invalid and will result in undefined behavior.
|
|
128
|
-
*/
|
|
129
|
-
setAttributes(attributes: Record<string, any>): this;
|
|
130
|
-
/**
|
|
131
|
-
* Adds an event to the Span.
|
|
132
|
-
*
|
|
133
|
-
* @param name the name of the event.
|
|
134
|
-
* @param [attributesOrStartTime] the attributes that will be added; these are
|
|
135
|
-
* associated with this event. Can be also a start time
|
|
136
|
-
* if type is {@type TimeInput} and 3rd param is undefined
|
|
137
|
-
* @param [startTime] start time of the event.
|
|
138
|
-
*/
|
|
139
|
-
addEvent(name: string, attributes: SpanAttributes, startTime?: HrTime): this;
|
|
140
|
-
setData(key: string, value: any): this;
|
|
141
|
-
getData<K = unknown>(key: string): K | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* Sets a status to the span. If used, this will override the default Span
|
|
144
|
-
* status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
|
|
145
|
-
* of previous calls to SetStatus on the Span.
|
|
146
|
-
*
|
|
147
|
-
* @param status the SpanStatus to set.
|
|
148
|
-
*/
|
|
149
|
-
setStatus(status: SpanStatus): this;
|
|
150
|
-
/**
|
|
151
|
-
* Updates the Span name.
|
|
152
|
-
*
|
|
153
|
-
* This will override the name provided via {@link Tracer.startSpan}.
|
|
154
|
-
*
|
|
155
|
-
* Upon this update, any sampling behavior based on Span name will depend on
|
|
156
|
-
* the implementation.
|
|
157
|
-
*
|
|
158
|
-
* @param name the Span name.
|
|
159
|
-
*/
|
|
160
|
-
updateName(name: string): this;
|
|
161
|
-
/**
|
|
162
|
-
* Marks the end of Span execution.
|
|
163
|
-
*
|
|
164
|
-
* Call to End of a Span MUST not have any effects on child spans. Those may
|
|
165
|
-
* still be running and can be ended later.
|
|
166
|
-
*
|
|
167
|
-
* Do not return `this`. The Span generally should not be used after it
|
|
168
|
-
* is ended so chaining is not desired in this context.
|
|
169
|
-
*
|
|
170
|
-
* @param [endTime] the time to set as Span's end time. If not provided,
|
|
171
|
-
* use the current time as the span's end time.
|
|
172
|
-
*/
|
|
173
|
-
end(endTime?: HrTime): void;
|
|
174
|
-
/**
|
|
175
|
-
* Returns the flag whether this span will be recorded.
|
|
176
|
-
*
|
|
177
|
-
* @returns true if this Span is active and recording information like events
|
|
178
|
-
* with the `AddEvent` operation and attributes using `setAttributes`.
|
|
179
|
-
*/
|
|
180
|
-
isRecording(): boolean;
|
|
181
|
-
/**
|
|
182
|
-
* Sets exception as a span event
|
|
183
|
-
* @param exception the exception the only accepted values are string or Error
|
|
184
|
-
* @param [time] the time to set as Span's event time. If not provided,
|
|
185
|
-
* use the current time.
|
|
186
|
-
*/
|
|
187
|
-
recordException(exception: Exception, time?: HrTime): this;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
interface TracingContextKey<_T> {
|
|
191
|
-
key: symbol;
|
|
192
|
-
}
|
|
193
|
-
interface TracingContext {
|
|
194
|
-
/**
|
|
195
|
-
* Get a value from the context.
|
|
196
|
-
*
|
|
197
|
-
* @param key key which identifies a context value
|
|
198
|
-
*/
|
|
199
|
-
getValue<T>(key: TracingContextKey<T>): T | undefined;
|
|
200
|
-
/**
|
|
201
|
-
* Create a new context which inherits from this context and has
|
|
202
|
-
* the given key set to the given value.
|
|
203
|
-
*
|
|
204
|
-
* @param key context key for which to set the value
|
|
205
|
-
* @param value value to set for the given key
|
|
206
|
-
*/
|
|
207
|
-
setValue<T>(key: TracingContextKey<T>, value: T): TracingContext;
|
|
208
|
-
/**
|
|
209
|
-
* Return a new context which inherits from this context but does
|
|
210
|
-
* not contain a value for the given key.
|
|
211
|
-
*
|
|
212
|
-
* @param key context key for which to clear a value
|
|
213
|
-
*/
|
|
214
|
-
deleteValue<T>(key: TracingContextKey<T>): TracingContext;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
interface SpanOptions {
|
|
218
|
-
/** A span's attributes */
|
|
219
|
-
attributes?: SpanAttributes;
|
|
220
|
-
/** A manually specified start time for the created `Span` object. */
|
|
221
|
-
startTime?: number;
|
|
222
|
-
/** The new span should be a root span. (Ignore parent from context). */
|
|
223
|
-
root?: boolean;
|
|
224
|
-
}
|
|
225
|
-
interface Tracer {
|
|
226
|
-
/**
|
|
227
|
-
* Starts a new {@link Span}. Start the span without setting it on context.
|
|
228
|
-
*
|
|
229
|
-
* This method do NOT modify the current Context.
|
|
230
|
-
*
|
|
231
|
-
* @param name The name of the span
|
|
232
|
-
* @param [options] SpanOptions used for span creation
|
|
233
|
-
* @param [context] Context to use to extract parent
|
|
234
|
-
* @returns Span The newly created span
|
|
235
|
-
* @example
|
|
236
|
-
* const span = tracer.startSpan('op');
|
|
237
|
-
* span.setAttribute('key', 'value');
|
|
238
|
-
* span.end();
|
|
239
|
-
*/
|
|
240
|
-
startSpan(name: string, options?: SpanOptions, context?: TracingContext): Span;
|
|
241
|
-
/**
|
|
242
|
-
* Starts a new {@link Span} and calls the given function passing it the
|
|
243
|
-
* created span as first argument.
|
|
244
|
-
* Additionally the new span gets set in context and this context is activated
|
|
245
|
-
* for the duration of the function call.
|
|
246
|
-
*
|
|
247
|
-
* @param name The name of the span
|
|
248
|
-
* @param [options] SpanOptions used for span creation
|
|
249
|
-
* @param [context] Context to use to extract parent
|
|
250
|
-
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
251
|
-
* @returns return value of fn
|
|
252
|
-
* @example
|
|
253
|
-
* const something = tracer.startActiveSpan('op', span => {
|
|
254
|
-
* try {
|
|
255
|
-
* do some work
|
|
256
|
-
* span.setStatus({code: SpanStatusCode.OK});
|
|
257
|
-
* return something;
|
|
258
|
-
* } catch (err) {
|
|
259
|
-
* span.setStatus({
|
|
260
|
-
* code: SpanStatusCode.ERROR,
|
|
261
|
-
* message: err.message,
|
|
262
|
-
* });
|
|
263
|
-
* throw err;
|
|
264
|
-
* } finally {
|
|
265
|
-
* span.end();
|
|
266
|
-
* }
|
|
267
|
-
* });
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* const span = tracer.startActiveSpan('op', span => {
|
|
271
|
-
* try {
|
|
272
|
-
* do some work
|
|
273
|
-
* return span;
|
|
274
|
-
* } catch (err) {
|
|
275
|
-
* span.setStatus({
|
|
276
|
-
* code: SpanStatusCode.ERROR,
|
|
277
|
-
* message: err.message,
|
|
278
|
-
* });
|
|
279
|
-
* throw err;
|
|
280
|
-
* }
|
|
281
|
-
* });
|
|
282
|
-
* do some more work
|
|
283
|
-
* span.end();
|
|
284
|
-
*/
|
|
285
|
-
startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
|
|
286
|
-
startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
|
|
287
|
-
startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: TracingContext, fn: F): ReturnType<F>;
|
|
288
|
-
getActiveSpan(): Span | undefined;
|
|
289
|
-
setSpanContext(spanContext: SpanContext): TracingContext;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
12
|
type CreateRenderContextOptions = {
|
|
293
|
-
parentSpanId?: string | null;
|
|
294
|
-
traceId?: string | null;
|
|
295
|
-
contextValues?: ContextValues;
|
|
296
13
|
logger?: LogImplementation;
|
|
14
|
+
traceId?: string;
|
|
15
|
+
processor?: SpanProcessor;
|
|
16
|
+
contextValues?: ContextValues;
|
|
297
17
|
};
|
|
298
|
-
declare function createRenderContext({
|
|
299
|
-
|
|
300
|
-
interface TracingContextManager {
|
|
301
|
-
/**
|
|
302
|
-
* Get the current active context
|
|
303
|
-
*/
|
|
304
|
-
active(): TracingContext;
|
|
305
|
-
/**
|
|
306
|
-
* Run the fn callback with object set as the current active context
|
|
307
|
-
* @param context Any object to set as the current active context
|
|
308
|
-
* @param fn A callback to be immediately run within a specific context
|
|
309
|
-
* @param thisArg optional receiver to be used for calling fn
|
|
310
|
-
* @param args optional arguments forwarded to fn
|
|
311
|
-
*/
|
|
312
|
-
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: TracingContext, fn: F, ...args: A): ReturnType<F>;
|
|
313
|
-
/**
|
|
314
|
-
* Bind an object as the current context (or a specific one)
|
|
315
|
-
* @param [context] Optionally specify the context which you want to assign
|
|
316
|
-
* @param target Any object to which a context need to be set
|
|
317
|
-
*/
|
|
318
|
-
bind<T>(context: TracingContext, target: T): T;
|
|
319
|
-
/**
|
|
320
|
-
* Enable context management
|
|
321
|
-
*/
|
|
322
|
-
enable(): this;
|
|
323
|
-
/**
|
|
324
|
-
* Disable context management
|
|
325
|
-
*/
|
|
326
|
-
disable(): this;
|
|
327
|
-
}
|
|
18
|
+
declare function createRenderContext({ logger, traceId, processor, contextValues, }?: CreateRenderContextOptions): RenderContext;
|
|
328
19
|
|
|
329
|
-
interface SpanProcessor {
|
|
330
|
-
/**
|
|
331
|
-
* Forces to export all finished spans
|
|
332
|
-
*/
|
|
333
|
-
forceFlush(): Promise<void>;
|
|
334
|
-
/**
|
|
335
|
-
* Called when a {@link Span} is started, if the `span.isRecording()`
|
|
336
|
-
* returns true.
|
|
337
|
-
* @param span the Span that just started.
|
|
338
|
-
*/
|
|
339
|
-
onStart(span: Span, parentContext: TracingContext): void;
|
|
340
|
-
/**
|
|
341
|
-
* Called when a {@link ReadableSpan} is ended, if the `span.isRecording()`
|
|
342
|
-
* returns true.
|
|
343
|
-
* @param span the Span that just ended.
|
|
344
|
-
*/
|
|
345
|
-
onEnd(span: Span): void;
|
|
346
|
-
/**
|
|
347
|
-
* Shuts down the processor. Called when SDK is shut down. This is an
|
|
348
|
-
* opportunity for processor to do any cleanup required.
|
|
349
|
-
*/
|
|
350
|
-
shutdown(): Promise<void>;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Root public API
|
|
355
|
-
*/
|
|
356
|
-
type AITraceInitOptions = {
|
|
357
|
-
spanProcessors?: SpanProcessor[];
|
|
358
|
-
contextManager?: TracingContextManager;
|
|
359
|
-
};
|
|
360
20
|
declare class AITraceAPI {
|
|
361
21
|
private static _instance?;
|
|
362
|
-
private
|
|
22
|
+
private enabled;
|
|
363
23
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
364
24
|
private constructor();
|
|
365
25
|
/** Get the singleton instance of the Trace API */
|
|
366
26
|
static getInstance(): AITraceAPI;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
27
|
+
createTracer(opts?: {
|
|
28
|
+
traceId?: string;
|
|
29
|
+
processor?: SpanProcessor;
|
|
30
|
+
}): Tracer;
|
|
31
|
+
enable(): void;
|
|
371
32
|
disable(): void;
|
|
372
|
-
bind<T>(target: T): T;
|
|
373
33
|
}
|
|
34
|
+
declare const tracing: AITraceAPI;
|
|
374
35
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
36
|
+
type CostFn = (tokensUsed: {
|
|
37
|
+
prompt: number;
|
|
38
|
+
completion: number;
|
|
39
|
+
total: number;
|
|
40
|
+
}, opts: {
|
|
41
|
+
provider?: string;
|
|
42
|
+
providerRegion?: string;
|
|
43
|
+
model: string;
|
|
44
|
+
}) => number;
|
|
45
|
+
/**
|
|
46
|
+
* Handles the following transformation / enrichment
|
|
47
|
+
* 1. deletes references to prompt (used for evaluation)
|
|
48
|
+
* 2. evaluatorResults
|
|
49
|
+
* 3. sum totalCost on the root span
|
|
50
|
+
* 4. sum totalUsage on the root span
|
|
51
|
+
*/
|
|
52
|
+
declare abstract class EnrichingSpanProcessor implements SpanProcessor {
|
|
53
|
+
private readonly exporter;
|
|
54
|
+
protected finalSpans: {
|
|
55
|
+
status: 'running' | 'processing' | 'done';
|
|
56
|
+
span: ReadableSpan;
|
|
57
|
+
}[];
|
|
58
|
+
protected onAllDonePromise: Promise<void> | null;
|
|
59
|
+
protected onAllDonePromiseResolve: (() => void) | null;
|
|
60
|
+
constructor(exporter: SpanExporter);
|
|
61
|
+
onStart(span: ReadableSpan): Promise<void>;
|
|
62
|
+
onEnd(span: ReadableSpan): Promise<void>;
|
|
63
|
+
abstract onTraceComplete(rootSpan: ReadableSpan): Promise<void>;
|
|
64
|
+
abstract enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
|
|
65
|
+
shutdown(): Promise<void> | undefined;
|
|
66
|
+
}
|
|
67
|
+
declare class AISpanProcessor extends EnrichingSpanProcessor {
|
|
68
|
+
private readonly opts;
|
|
69
|
+
protected totalCost: number;
|
|
70
|
+
protected totalUsage: {
|
|
71
|
+
prompt: number;
|
|
72
|
+
completion: number;
|
|
73
|
+
total: number;
|
|
74
|
+
};
|
|
75
|
+
constructor(exporter: SpanExporter, opts?: {
|
|
76
|
+
costFn?: CostFn;
|
|
77
|
+
});
|
|
78
|
+
onTraceComplete(rootSpan: ReadableSpan): Promise<void>;
|
|
79
|
+
enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
|
|
80
|
+
protected computeCost(span: ReadableSpan): Promise<ReadableSpan>;
|
|
81
|
+
protected updateUsage(span: ReadableSpan): Promise<ReadableSpan>;
|
|
82
|
+
protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
|
|
391
83
|
}
|
|
392
84
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
85
|
+
type TraceProps = {
|
|
86
|
+
children: AINode;
|
|
87
|
+
name: string;
|
|
88
|
+
attributes?: SpanAttributes;
|
|
89
|
+
};
|
|
90
|
+
declare const Trace: AIComponent<TraceProps>;
|
|
400
91
|
|
|
401
92
|
/**
|
|
402
93
|
* This is a helper function to create a JsxPrompt type
|
|
@@ -433,10 +124,6 @@ declare function createStreamChain<I extends ZodObject<ZodRawShape>, M extends Z
|
|
|
433
124
|
messageSchema?: M;
|
|
434
125
|
}): StreamChain<z.infer<I>, R>;
|
|
435
126
|
|
|
436
|
-
declare class PromptParseVariablesError extends Error {
|
|
437
|
-
}
|
|
438
|
-
declare class ChainParseVariablesError extends Error {
|
|
439
|
-
}
|
|
440
127
|
declare class ParseVariablesError extends Error {
|
|
441
128
|
}
|
|
442
129
|
declare class PromptInvalidOutputError extends Error {
|
|
@@ -463,7 +150,7 @@ type OpenAIChatCompletionProps = {
|
|
|
463
150
|
provider?: string;
|
|
464
151
|
providerRegion?: string;
|
|
465
152
|
};
|
|
466
|
-
declare function OpenAIChatCompletion(props: OpenAIChatCompletionProps, { render,
|
|
153
|
+
declare function OpenAIChatCompletion(props: OpenAIChatCompletionProps, { logger, render, tracer, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
467
154
|
|
|
468
155
|
type ValidOpenAIVisionModel = 'gpt-4-vision-preview';
|
|
469
156
|
declare const ContentTypeImage: (_props: {
|
|
@@ -482,7 +169,7 @@ type OpenAIVisionChatCompletionProps = {
|
|
|
482
169
|
provider?: string;
|
|
483
170
|
providerRegion?: string;
|
|
484
171
|
};
|
|
485
|
-
declare function OpenAIVisionChatCompletion(props: OpenAIVisionChatCompletionProps, { render,
|
|
172
|
+
declare function OpenAIVisionChatCompletion(props: OpenAIVisionChatCompletionProps, { logger, render, tracer, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
486
173
|
|
|
487
174
|
declare const tokenizer: {
|
|
488
175
|
encode: (text: string) => number[];
|
|
@@ -492,7 +179,7 @@ declare function tokenLimitForChatModel(model: ValidOpenAIChatModel): number | u
|
|
|
492
179
|
declare function tokenCountForOpenAIMessage(message: OpenAIChatMessage): number;
|
|
493
180
|
declare function tokenCountForOpenAIVisionMessage(message: OpenAIChatMessage): number;
|
|
494
181
|
|
|
495
|
-
type AnthropicChatCompletionRequest = AnthropicClient.
|
|
182
|
+
type AnthropicChatCompletionRequest = AnthropicClient.Messages.MessageStreamParams;
|
|
496
183
|
declare module '@gammatech/aijsx' {
|
|
497
184
|
interface ChatCompletionRequestPayloads {
|
|
498
185
|
anthropic: AnthropicChatCompletionRequest;
|
|
@@ -502,12 +189,8 @@ declare module '@gammatech/aijsx' {
|
|
|
502
189
|
* The set of valid Claude models.
|
|
503
190
|
* @see https://docs.anthropic.com/claude/reference/selecting-a-model
|
|
504
191
|
*/
|
|
505
|
-
type ValidAnthropicChatModel = 'claude-instant-1.2' | 'claude-2.1';
|
|
192
|
+
type ValidAnthropicChatModel = 'claude-instant-1.2' | 'claude-2.1' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229';
|
|
506
193
|
declare const AnthropicClientContext: Context<() => AnthropicClient>;
|
|
507
|
-
/**
|
|
508
|
-
* If you use an Anthropic model without specifying the max tokens for the completion, this value will be used as the default.
|
|
509
|
-
*/
|
|
510
|
-
declare const defaultMaxTokens = 4096;
|
|
511
194
|
type AnthropicChatCompletionProps = {
|
|
512
195
|
model: ValidAnthropicChatModel;
|
|
513
196
|
maxTokens?: number;
|
|
@@ -523,6 +206,24 @@ type AnthropicChatCompletionProps = {
|
|
|
523
206
|
* @param completionModel The completion model to use.
|
|
524
207
|
* @param client The Anthropic client.
|
|
525
208
|
*/
|
|
526
|
-
declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render,
|
|
209
|
+
declare function AnthropicChatCompletion(props: AnthropicChatCompletionProps, { render, logger, tracer, getContext }: RenderContext): AsyncGenerator<string, void, unknown>;
|
|
210
|
+
|
|
211
|
+
type ClaudeImageBlockBase64 = {
|
|
212
|
+
data: string;
|
|
213
|
+
dimensions?: {
|
|
214
|
+
width: number;
|
|
215
|
+
height: number;
|
|
216
|
+
};
|
|
217
|
+
mediaType: ImageBlockParam.Source['media_type'];
|
|
218
|
+
};
|
|
219
|
+
type ClaudeImageBlockUrl = {
|
|
220
|
+
url: string;
|
|
221
|
+
dimensions?: {
|
|
222
|
+
width: number;
|
|
223
|
+
height: number;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
type ClaudeImageBlockProps = ClaudeImageBlockBase64 | ClaudeImageBlockUrl;
|
|
227
|
+
declare const ClaudeImageBlock: (props: ClaudeImageBlockProps) => Promise<JSX.Element>;
|
|
527
228
|
|
|
528
|
-
export { AIComponent, AINode, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext,
|
|
229
|
+
export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
|