@gammatech/aijsx 0.16.2-dev.2024-11-05 → 0.16.4-dev.2024-11-24
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 +42 -4
- package/dist/index.mjs +42 -4
- package/dist/{jsx-dev-runtime-yyAW1PnA.d.mts → jsx-dev-runtime-CwVVc96-.d.mts} +8 -1
- package/dist/{jsx-dev-runtime-yyAW1PnA.d.ts → jsx-dev-runtime-CwVVc96-.d.ts} +8 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, J as JSX } from './jsx-dev-runtime-
|
|
2
|
-
export {
|
|
1
|
+
import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-CwVVc96-.mjs';
|
|
2
|
+
export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-CwVVc96-.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';
|
|
@@ -121,8 +121,10 @@ declare class SpanTreeNode {
|
|
|
121
121
|
addChild(child: SpanTreeNode): void;
|
|
122
122
|
descendents(fn: (node: SpanTreeNode) => void): void;
|
|
123
123
|
everyDescendent(fn: (node: SpanTreeNode) => boolean): boolean;
|
|
124
|
+
getRoot(): SpanTreeNode;
|
|
124
125
|
getRootByName(name: string): SpanTreeNode | null;
|
|
125
126
|
getNearestAttribute<K>(key: string): K | null;
|
|
127
|
+
getRootSpanId(): string;
|
|
126
128
|
getRootAttribute<K>(key: string): K | null;
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -151,6 +153,7 @@ declare class AISpanProcessor implements SpanProcessor {
|
|
|
151
153
|
shutdown(): Promise<void> | undefined;
|
|
152
154
|
onRootPromptDone(rootSpan: ReadableSpan): Promise<void>;
|
|
153
155
|
enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
|
|
156
|
+
protected addRootSpanId(span: ReadableSpan): Promise<ReadableSpan>;
|
|
154
157
|
protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
|
|
155
158
|
protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
|
|
156
159
|
}
|
|
@@ -195,10 +198,12 @@ declare namespace ProcessedAISpanAttributes {
|
|
|
195
198
|
totalCost?: Cost;
|
|
196
199
|
parentPromptKey?: string;
|
|
197
200
|
rootPromptKey?: string;
|
|
201
|
+
rootSpanId: string;
|
|
198
202
|
};
|
|
199
203
|
type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
|
|
200
204
|
parentPromptKey?: string;
|
|
201
205
|
rootPromptKey?: string;
|
|
206
|
+
rootSpanId: string;
|
|
202
207
|
};
|
|
203
208
|
}
|
|
204
209
|
|
|
@@ -210,6 +215,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
|
|
|
210
215
|
schema: I;
|
|
211
216
|
component: AIComponent<z.infer<I>>;
|
|
212
217
|
evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
218
|
+
llmEvaluators?: LlmEvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
213
219
|
metadata?: Record<string, any>;
|
|
214
220
|
outputParser: {
|
|
215
221
|
schema: O;
|
|
@@ -221,6 +227,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
|
|
|
221
227
|
schema: I;
|
|
222
228
|
component: AIComponent<z.infer<I>>;
|
|
223
229
|
evaluators?: EvaluatorFn<z.infer<I>, string>[];
|
|
230
|
+
llmEvaluators?: LlmEvaluatorFn<z.infer<I>, string>[];
|
|
224
231
|
metadata?: Record<string, any>;
|
|
225
232
|
}): Prompt<z.infer<I>>;
|
|
226
233
|
declare function isPromptParsed<V extends Record<string, any>>(prompt: Prompt<V>): prompt is PromptParsed<any, any>;
|
|
@@ -320,4 +327,4 @@ type GoogleChatCompletionProps = {
|
|
|
320
327
|
};
|
|
321
328
|
declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
|
|
322
329
|
|
|
323
|
-
export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, Accumulate, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatCompletionUsage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EvaluatorFn, EvaluatorResult, Fallback, type GetChatCompletionClientAndProvider, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, RetryLastErrorContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createPrompt, createRenderContext, evaluatePrompt, AnthropicPromptCacheDebugger as experimental__AnthropicPromptCacheDebugger, isPromptParsed, tracing };
|
|
330
|
+
export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, Accumulate, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatCompletionUsage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EvaluatorFn, EvaluatorResult, Fallback, type GetChatCompletionClientAndProvider, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LlmEvaluatorFn, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, RetryLastErrorContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createPrompt, createRenderContext, evaluatePrompt, AnthropicPromptCacheDebugger as experimental__AnthropicPromptCacheDebugger, isPromptParsed, tracing };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as PromptParsed, J as JSX } from './jsx-dev-runtime-
|
|
2
|
-
export {
|
|
1
|
+
import { L as LogChatCompletionRequest, A as AINode, C as ChatCompletionUsage, R as RenderContext, a as LogImplementation, S as SpanProcessor, b as ContextValues, c as Context, T as Tracer, d as ReadableSpan, e as SpanAttributes, f as SpanExporter, g as AIComponent, P as Prompt, h as ChatCompletionRequestPayloads, D as DebugMessage, E as EvaluatorResult, i as EvaluatorFn, j as LlmEvaluatorFn, k as PromptParsed, J as JSX } from './jsx-dev-runtime-CwVVc96-.js';
|
|
2
|
+
export { F as AIElement, m as AIFragment, B as BoundLogger, o as ChatMessage, p as ChatRole, w as CombinedLogger, v as ConsoleLogger, I as ImagePart, q as ImagePartProps, x as Literal, r as LogChatCompletionResponse, s as LogLevel, u as Logger, N as NoopLogImplementation, X as OutputParser, H as PropsOfAIComponent, y as RenderResult, G as Renderable, O as Span, K as SpanContext, Q as SpanEvent, M as SpanStatus, V as TracingContext, U as TracingContextKey, W as TracingContextManager, z as attachedContextSymbol, l as createAIElement, n as createContext, t as toDebugMessage } from './jsx-dev-runtime-CwVVc96-.js';
|
|
3
3
|
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
4
4
|
import { OpenAI } from 'openai';
|
|
5
5
|
export { OpenAI as OpenAIClient } from 'openai';
|
|
@@ -121,8 +121,10 @@ declare class SpanTreeNode {
|
|
|
121
121
|
addChild(child: SpanTreeNode): void;
|
|
122
122
|
descendents(fn: (node: SpanTreeNode) => void): void;
|
|
123
123
|
everyDescendent(fn: (node: SpanTreeNode) => boolean): boolean;
|
|
124
|
+
getRoot(): SpanTreeNode;
|
|
124
125
|
getRootByName(name: string): SpanTreeNode | null;
|
|
125
126
|
getNearestAttribute<K>(key: string): K | null;
|
|
127
|
+
getRootSpanId(): string;
|
|
126
128
|
getRootAttribute<K>(key: string): K | null;
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -151,6 +153,7 @@ declare class AISpanProcessor implements SpanProcessor {
|
|
|
151
153
|
shutdown(): Promise<void> | undefined;
|
|
152
154
|
onRootPromptDone(rootSpan: ReadableSpan): Promise<void>;
|
|
153
155
|
enrichSpan(span: ReadableSpan): Promise<ReadableSpan>;
|
|
156
|
+
protected addRootSpanId(span: ReadableSpan): Promise<ReadableSpan>;
|
|
154
157
|
protected addPromptKeys(span: ReadableSpan): Promise<ReadableSpan>;
|
|
155
158
|
protected evaluatePrompt(span: ReadableSpan): Promise<ReadableSpan>;
|
|
156
159
|
}
|
|
@@ -195,10 +198,12 @@ declare namespace ProcessedAISpanAttributes {
|
|
|
195
198
|
totalCost?: Cost;
|
|
196
199
|
parentPromptKey?: string;
|
|
197
200
|
rootPromptKey?: string;
|
|
201
|
+
rootSpanId: string;
|
|
198
202
|
};
|
|
199
203
|
type ChatCompletion<K extends keyof ChatCompletionRequestPayloads = keyof ChatCompletionRequestPayloads> = AISpanAttributes.ChatCompletion<K> & {
|
|
200
204
|
parentPromptKey?: string;
|
|
201
205
|
rootPromptKey?: string;
|
|
206
|
+
rootSpanId: string;
|
|
202
207
|
};
|
|
203
208
|
}
|
|
204
209
|
|
|
@@ -210,6 +215,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
|
|
|
210
215
|
schema: I;
|
|
211
216
|
component: AIComponent<z.infer<I>>;
|
|
212
217
|
evaluators?: EvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
218
|
+
llmEvaluators?: LlmEvaluatorFn<z.infer<I>, z.infer<O>>[];
|
|
213
219
|
metadata?: Record<string, any>;
|
|
214
220
|
outputParser: {
|
|
215
221
|
schema: O;
|
|
@@ -221,6 +227,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
|
|
|
221
227
|
schema: I;
|
|
222
228
|
component: AIComponent<z.infer<I>>;
|
|
223
229
|
evaluators?: EvaluatorFn<z.infer<I>, string>[];
|
|
230
|
+
llmEvaluators?: LlmEvaluatorFn<z.infer<I>, string>[];
|
|
224
231
|
metadata?: Record<string, any>;
|
|
225
232
|
}): Prompt<z.infer<I>>;
|
|
226
233
|
declare function isPromptParsed<V extends Record<string, any>>(prompt: Prompt<V>): prompt is PromptParsed<any, any>;
|
|
@@ -320,4 +327,4 @@ type GoogleChatCompletionProps = {
|
|
|
320
327
|
};
|
|
321
328
|
declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
|
|
322
329
|
|
|
323
|
-
export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, Accumulate, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatCompletionUsage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EvaluatorFn, EvaluatorResult, Fallback, type GetChatCompletionClientAndProvider, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, RetryLastErrorContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createPrompt, createRenderContext, evaluatePrompt, AnthropicPromptCacheDebugger as experimental__AnthropicPromptCacheDebugger, isPromptParsed, tracing };
|
|
330
|
+
export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, Accumulate, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatCompletionUsage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EvaluatorFn, EvaluatorResult, Fallback, type GetChatCompletionClientAndProvider, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LlmEvaluatorFn, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, RetryLastErrorContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createPrompt, createRenderContext, evaluatePrompt, AnthropicPromptCacheDebugger as experimental__AnthropicPromptCacheDebugger, isPromptParsed, tracing };
|
package/dist/index.js
CHANGED
|
@@ -1767,6 +1767,15 @@ var SpanTreeNode = class {
|
|
|
1767
1767
|
});
|
|
1768
1768
|
return result;
|
|
1769
1769
|
}
|
|
1770
|
+
getRoot() {
|
|
1771
|
+
let node = this;
|
|
1772
|
+
let found = this;
|
|
1773
|
+
while (node) {
|
|
1774
|
+
found = node;
|
|
1775
|
+
node = node.parent;
|
|
1776
|
+
}
|
|
1777
|
+
return found;
|
|
1778
|
+
}
|
|
1770
1779
|
getRootByName(name) {
|
|
1771
1780
|
let node = this;
|
|
1772
1781
|
let found = null;
|
|
@@ -1781,6 +1790,9 @@ var SpanTreeNode = class {
|
|
|
1781
1790
|
getNearestAttribute(key) {
|
|
1782
1791
|
return getNearestAttribute(this.parent, key);
|
|
1783
1792
|
}
|
|
1793
|
+
getRootSpanId() {
|
|
1794
|
+
return this.getRoot().span.spanContext.spanId;
|
|
1795
|
+
}
|
|
1784
1796
|
getRootAttribute(key) {
|
|
1785
1797
|
return getFarthestAttribute(this, key);
|
|
1786
1798
|
}
|
|
@@ -1885,7 +1897,22 @@ var AISpanProcessor = class {
|
|
|
1885
1897
|
async enrichSpan(span) {
|
|
1886
1898
|
const result1 = await this.evaluatePrompt(span);
|
|
1887
1899
|
const result2 = await this.addPromptKeys(result1);
|
|
1888
|
-
|
|
1900
|
+
const result3 = await this.addRootSpanId(result2);
|
|
1901
|
+
return result3;
|
|
1902
|
+
}
|
|
1903
|
+
async addRootSpanId(span) {
|
|
1904
|
+
const node = this.spanTree.findNode(span.spanContext.spanId);
|
|
1905
|
+
if (!node) {
|
|
1906
|
+
return span;
|
|
1907
|
+
}
|
|
1908
|
+
const final = {
|
|
1909
|
+
...span,
|
|
1910
|
+
attributes: {
|
|
1911
|
+
...span.attributes,
|
|
1912
|
+
rootSpanId: node.getRootSpanId()
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
return final;
|
|
1889
1916
|
}
|
|
1890
1917
|
async addPromptKeys(span) {
|
|
1891
1918
|
if (!isChatCompletionSpan(span) && !isPromptSpan(span)) {
|
|
@@ -1897,7 +1924,8 @@ var AISpanProcessor = class {
|
|
|
1897
1924
|
}
|
|
1898
1925
|
const extraAttributes = {
|
|
1899
1926
|
parentPromptKey: node.getNearestAttribute("promptKey"),
|
|
1900
|
-
rootPromptKey: node.getRootAttribute("promptKey")
|
|
1927
|
+
rootPromptKey: node.getRootAttribute("promptKey"),
|
|
1928
|
+
rootSpanId: node.getRootSpanId()
|
|
1901
1929
|
};
|
|
1902
1930
|
const final = {
|
|
1903
1931
|
...span,
|
|
@@ -1986,6 +2014,7 @@ function createPrompt(config) {
|
|
|
1986
2014
|
outputParser,
|
|
1987
2015
|
component: component2,
|
|
1988
2016
|
evaluators: evaluators2 = [],
|
|
2017
|
+
llmEvaluators: llmEvaluators2 = [],
|
|
1989
2018
|
metadata: metadata2 = {}
|
|
1990
2019
|
} = config;
|
|
1991
2020
|
return {
|
|
@@ -1995,16 +2024,25 @@ function createPrompt(config) {
|
|
|
1995
2024
|
outputSchema: outputParser.schema,
|
|
1996
2025
|
schema: schema2,
|
|
1997
2026
|
metadata: metadata2,
|
|
1998
|
-
evaluators: evaluators2
|
|
2027
|
+
evaluators: evaluators2,
|
|
2028
|
+
llmEvaluators: llmEvaluators2
|
|
1999
2029
|
};
|
|
2000
2030
|
}
|
|
2001
|
-
const {
|
|
2031
|
+
const {
|
|
2032
|
+
key,
|
|
2033
|
+
schema,
|
|
2034
|
+
component,
|
|
2035
|
+
evaluators = [],
|
|
2036
|
+
llmEvaluators = [],
|
|
2037
|
+
metadata = {}
|
|
2038
|
+
} = config;
|
|
2002
2039
|
return {
|
|
2003
2040
|
key,
|
|
2004
2041
|
component,
|
|
2005
2042
|
schema,
|
|
2006
2043
|
metadata,
|
|
2007
2044
|
evaluators,
|
|
2045
|
+
llmEvaluators,
|
|
2008
2046
|
outputSchema: import_zod.z.string()
|
|
2009
2047
|
};
|
|
2010
2048
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1666,6 +1666,15 @@ var SpanTreeNode = class {
|
|
|
1666
1666
|
});
|
|
1667
1667
|
return result;
|
|
1668
1668
|
}
|
|
1669
|
+
getRoot() {
|
|
1670
|
+
let node = this;
|
|
1671
|
+
let found = this;
|
|
1672
|
+
while (node) {
|
|
1673
|
+
found = node;
|
|
1674
|
+
node = node.parent;
|
|
1675
|
+
}
|
|
1676
|
+
return found;
|
|
1677
|
+
}
|
|
1669
1678
|
getRootByName(name) {
|
|
1670
1679
|
let node = this;
|
|
1671
1680
|
let found = null;
|
|
@@ -1680,6 +1689,9 @@ var SpanTreeNode = class {
|
|
|
1680
1689
|
getNearestAttribute(key) {
|
|
1681
1690
|
return getNearestAttribute(this.parent, key);
|
|
1682
1691
|
}
|
|
1692
|
+
getRootSpanId() {
|
|
1693
|
+
return this.getRoot().span.spanContext.spanId;
|
|
1694
|
+
}
|
|
1683
1695
|
getRootAttribute(key) {
|
|
1684
1696
|
return getFarthestAttribute(this, key);
|
|
1685
1697
|
}
|
|
@@ -1784,7 +1796,22 @@ var AISpanProcessor = class {
|
|
|
1784
1796
|
async enrichSpan(span) {
|
|
1785
1797
|
const result1 = await this.evaluatePrompt(span);
|
|
1786
1798
|
const result2 = await this.addPromptKeys(result1);
|
|
1787
|
-
|
|
1799
|
+
const result3 = await this.addRootSpanId(result2);
|
|
1800
|
+
return result3;
|
|
1801
|
+
}
|
|
1802
|
+
async addRootSpanId(span) {
|
|
1803
|
+
const node = this.spanTree.findNode(span.spanContext.spanId);
|
|
1804
|
+
if (!node) {
|
|
1805
|
+
return span;
|
|
1806
|
+
}
|
|
1807
|
+
const final = {
|
|
1808
|
+
...span,
|
|
1809
|
+
attributes: {
|
|
1810
|
+
...span.attributes,
|
|
1811
|
+
rootSpanId: node.getRootSpanId()
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
return final;
|
|
1788
1815
|
}
|
|
1789
1816
|
async addPromptKeys(span) {
|
|
1790
1817
|
if (!isChatCompletionSpan(span) && !isPromptSpan(span)) {
|
|
@@ -1796,7 +1823,8 @@ var AISpanProcessor = class {
|
|
|
1796
1823
|
}
|
|
1797
1824
|
const extraAttributes = {
|
|
1798
1825
|
parentPromptKey: node.getNearestAttribute("promptKey"),
|
|
1799
|
-
rootPromptKey: node.getRootAttribute("promptKey")
|
|
1826
|
+
rootPromptKey: node.getRootAttribute("promptKey"),
|
|
1827
|
+
rootSpanId: node.getRootSpanId()
|
|
1800
1828
|
};
|
|
1801
1829
|
const final = {
|
|
1802
1830
|
...span,
|
|
@@ -1885,6 +1913,7 @@ function createPrompt(config) {
|
|
|
1885
1913
|
outputParser,
|
|
1886
1914
|
component: component2,
|
|
1887
1915
|
evaluators: evaluators2 = [],
|
|
1916
|
+
llmEvaluators: llmEvaluators2 = [],
|
|
1888
1917
|
metadata: metadata2 = {}
|
|
1889
1918
|
} = config;
|
|
1890
1919
|
return {
|
|
@@ -1894,16 +1923,25 @@ function createPrompt(config) {
|
|
|
1894
1923
|
outputSchema: outputParser.schema,
|
|
1895
1924
|
schema: schema2,
|
|
1896
1925
|
metadata: metadata2,
|
|
1897
|
-
evaluators: evaluators2
|
|
1926
|
+
evaluators: evaluators2,
|
|
1927
|
+
llmEvaluators: llmEvaluators2
|
|
1898
1928
|
};
|
|
1899
1929
|
}
|
|
1900
|
-
const {
|
|
1930
|
+
const {
|
|
1931
|
+
key,
|
|
1932
|
+
schema,
|
|
1933
|
+
component,
|
|
1934
|
+
evaluators = [],
|
|
1935
|
+
llmEvaluators = [],
|
|
1936
|
+
metadata = {}
|
|
1937
|
+
} = config;
|
|
1901
1938
|
return {
|
|
1902
1939
|
key,
|
|
1903
1940
|
component,
|
|
1904
1941
|
schema,
|
|
1905
1942
|
metadata,
|
|
1906
1943
|
evaluators,
|
|
1944
|
+
llmEvaluators,
|
|
1907
1945
|
outputSchema: z.string()
|
|
1908
1946
|
};
|
|
1909
1947
|
}
|
|
@@ -102,10 +102,16 @@ type EvaluatorResult = {
|
|
|
102
102
|
key: string;
|
|
103
103
|
result: EvaluatorPrimitive | EvaluatorPrimitive[];
|
|
104
104
|
passes: boolean;
|
|
105
|
+
score?: number;
|
|
105
106
|
description?: string;
|
|
106
107
|
debug?: string;
|
|
107
108
|
};
|
|
108
109
|
type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
110
|
+
type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any, E = O> = (ctx: RenderContext, options: {
|
|
111
|
+
variables: V;
|
|
112
|
+
output: O;
|
|
113
|
+
expected?: E;
|
|
114
|
+
}) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
109
115
|
type OutputParser<O> = {
|
|
110
116
|
schema: ZodTypeAny;
|
|
111
117
|
parse: (result: string) => O;
|
|
@@ -115,6 +121,7 @@ interface Prompt<V extends Record<string, any> = Record<string, any>> {
|
|
|
115
121
|
component: AIComponent<V>;
|
|
116
122
|
schema: ZodObject<ZodRawShape>;
|
|
117
123
|
evaluators: EvaluatorFn<V>[];
|
|
124
|
+
llmEvaluators: LlmEvaluatorFn<V>[];
|
|
118
125
|
outputSchema: ZodTypeAny;
|
|
119
126
|
metadata: Record<string, any>;
|
|
120
127
|
}
|
|
@@ -362,4 +369,4 @@ declare const jsxs: typeof jsx;
|
|
|
362
369
|
/** @hidden */
|
|
363
370
|
declare const Fragment: typeof AIFragment;
|
|
364
371
|
|
|
365
|
-
export { type AINode as A, BoundLogger as B, type ChatCompletionUsage as C, type DebugMessage as D, type EvaluatorResult as E, type
|
|
372
|
+
export { Fragment as $, type AINode as A, BoundLogger as B, type ChatCompletionUsage as C, type DebugMessage as D, type EvaluatorResult as E, type AIElement as F, type Renderable as G, type PropsOfAIComponent as H, ImagePart as I, JSX as J, type SpanContext as K, type LogChatCompletionRequest as L, type SpanStatus as M, NoopLogImplementation as N, type Span as O, type Prompt as P, type SpanEvent as Q, type RenderContext as R, type SpanProcessor as S, type Tracer as T, type TracingContextKey as U, type TracingContext as V, type TracingContextManager as W, type OutputParser as X, jsx as Y, jsxDEV as Z, jsxs as _, LogImplementation as a, type ContextValues as b, type Context as c, type ReadableSpan as d, type SpanAttributes as e, type SpanExporter as f, type AIComponent as g, type ChatCompletionRequestPayloads as h, type EvaluatorFn as i, type LlmEvaluatorFn as j, type PromptParsed as k, createAIElement as l, AIFragment as m, createContext as n, type ChatMessage as o, type ChatRole as p, type ImagePartProps as q, type LogChatCompletionResponse as r, type LogLevel as s, toDebugMessage as t, type Logger as u, ConsoleLogger as v, CombinedLogger as w, type Literal as x, type RenderResult as y, attachedContextSymbol as z };
|
|
@@ -102,10 +102,16 @@ type EvaluatorResult = {
|
|
|
102
102
|
key: string;
|
|
103
103
|
result: EvaluatorPrimitive | EvaluatorPrimitive[];
|
|
104
104
|
passes: boolean;
|
|
105
|
+
score?: number;
|
|
105
106
|
description?: string;
|
|
106
107
|
debug?: string;
|
|
107
108
|
};
|
|
108
109
|
type EvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any> = (variables: V, result: O) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
110
|
+
type LlmEvaluatorFn<V extends Record<string, any> = Record<string, any>, O = any, E = O> = (ctx: RenderContext, options: {
|
|
111
|
+
variables: V;
|
|
112
|
+
output: O;
|
|
113
|
+
expected?: E;
|
|
114
|
+
}) => Promise<EvaluatorResult | EvaluatorResult[]>;
|
|
109
115
|
type OutputParser<O> = {
|
|
110
116
|
schema: ZodTypeAny;
|
|
111
117
|
parse: (result: string) => O;
|
|
@@ -115,6 +121,7 @@ interface Prompt<V extends Record<string, any> = Record<string, any>> {
|
|
|
115
121
|
component: AIComponent<V>;
|
|
116
122
|
schema: ZodObject<ZodRawShape>;
|
|
117
123
|
evaluators: EvaluatorFn<V>[];
|
|
124
|
+
llmEvaluators: LlmEvaluatorFn<V>[];
|
|
118
125
|
outputSchema: ZodTypeAny;
|
|
119
126
|
metadata: Record<string, any>;
|
|
120
127
|
}
|
|
@@ -362,4 +369,4 @@ declare const jsxs: typeof jsx;
|
|
|
362
369
|
/** @hidden */
|
|
363
370
|
declare const Fragment: typeof AIFragment;
|
|
364
371
|
|
|
365
|
-
export { type AINode as A, BoundLogger as B, type ChatCompletionUsage as C, type DebugMessage as D, type EvaluatorResult as E, type
|
|
372
|
+
export { Fragment as $, type AINode as A, BoundLogger as B, type ChatCompletionUsage as C, type DebugMessage as D, type EvaluatorResult as E, type AIElement as F, type Renderable as G, type PropsOfAIComponent as H, ImagePart as I, JSX as J, type SpanContext as K, type LogChatCompletionRequest as L, type SpanStatus as M, NoopLogImplementation as N, type Span as O, type Prompt as P, type SpanEvent as Q, type RenderContext as R, type SpanProcessor as S, type Tracer as T, type TracingContextKey as U, type TracingContext as V, type TracingContextManager as W, type OutputParser as X, jsx as Y, jsxDEV as Z, jsxs as _, LogImplementation as a, type ContextValues as b, type Context as c, type ReadableSpan as d, type SpanAttributes as e, type SpanExporter as f, type AIComponent as g, type ChatCompletionRequestPayloads as h, type EvaluatorFn as i, type LlmEvaluatorFn as j, type PromptParsed as k, createAIElement as l, AIFragment as m, createContext as n, type ChatMessage as o, type ChatRole as p, type ImagePartProps as q, type LogChatCompletionResponse as r, type LogLevel as s, toDebugMessage as t, type Logger as u, ConsoleLogger as v, CombinedLogger as w, type Literal as x, type RenderResult as y, attachedContextSymbol as z };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.mjs';
|
|
2
2
|
import 'zod';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.js';
|
|
2
2
|
import 'zod';
|
package/dist/jsx-runtime.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.mjs';
|
|
2
2
|
import 'zod';
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { $ as Fragment, J as JSX, Y as jsx, Z as jsxDEV, _ as jsxs } from './jsx-dev-runtime-CwVVc96-.js';
|
|
2
2
|
import 'zod';
|