Skip to content

Commit a062942

Browse files
committed
Fix display of metrics from results
Add new pipeline fields to store result docs (for metrics calc)
1 parent e98bfc6 commit a062942

File tree

9 files changed

+329
-60
lines changed

9 files changed

+329
-60
lines changed

app/components/pipeline/nodes/StepNode.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ export function StepNode({ data }: { data: ProcessingStep }) {
4444
const { averageTiming, averagePrompt, averageCompletion, averageCost } =
4545
useMemo(() => {
4646
// const timings = data.
47-
const results = litlytics.docs;
48-
const resultDocs = litlytics.pipeline.results?.map((r) => r.doc) ?? [];
49-
const res = results.concat(resultDocs).filter((doc) => doc);
47+
const results = litlytics.pipeline.resultDocs ?? [];
48+
const res = results.filter((doc) => doc);
5049
if (!res.length) {
5150
return {};
5251
}

app/components/pipeline/nodes/output/OutputNode.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ export function OutputNode() {
5050

5151
const { timing, prompt, completion, cost } = useMemo(() => {
5252
// const timings = data.
53-
const results = litlytics.docs;
54-
const resultDocs = litlytics.pipeline.results?.map((r) => r.doc) ?? [];
55-
const res = results.concat(resultDocs).filter((doc) => doc);
53+
const results = litlytics.pipeline.resultDocs ?? [];
54+
const res = results.filter((doc) => doc);
5655
if (!res.length) {
5756
return {};
5857
}
@@ -88,6 +87,9 @@ export function OutputNode() {
8887
litlytics.setPipelineStatus(status);
8988
},
9089
});
90+
91+
// write final status to update on end
92+
litlytics.setPipelineStatus({ status: 'done' });
9193
};
9294

9395
const running =

examples/compare.json

+64-9
Large diffs are not rendered by default.

examples/complaints.json

+116-9
Large diffs are not rendered by default.

examples/etsy.json

+50-10
Large diffs are not rendered by default.

examples/jsonld.json

+40-10
Large diffs are not rendered by default.

examples/writing.json

+38-8
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
"results": [
7676
{
7777
"stepId": "step_1",
78-
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to put a smile on my face!\n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
78+
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to put a smile on my face! \n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
7979
"usage": {
80-
"completionTokens": 90,
80+
"completionTokens": 91,
8181
"promptTokens": 139,
82-
"totalTokens": 229
82+
"totalTokens": 230
8383
},
84-
"timingMs": 1649,
84+
"timingMs": 4028,
8585
"doc": {
8686
"id": "textdoc",
8787
"name": "Default document",
@@ -90,16 +90,46 @@
9090
"processingResults": [
9191
{
9292
"stepId": "step_1",
93-
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to put a smile on my face!\n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
93+
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to put a smile on my face! \n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
9494
"usage": {
95-
"completionTokens": 90,
95+
"completionTokens": 91,
9696
"promptTokens": 139,
97-
"totalTokens": 229
97+
"totalTokens": 230
9898
},
99-
"timingMs": 1649
99+
"timingMs": 4028
100100
}
101101
]
102102
}
103103
}
104+
],
105+
"resultDocs": [
106+
{
107+
"id": "textdoc",
108+
"name": "Default document",
109+
"content": "Post is a photo of my cute black cat with white mustache.",
110+
"test": true,
111+
"processingResults": [
112+
{
113+
"stepId": "step_0",
114+
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to make me smile! \n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
115+
"usage": {
116+
"completionTokens": 88,
117+
"promptTokens": 89,
118+
"totalTokens": 177
119+
},
120+
"timingMs": 3736
121+
},
122+
{
123+
"stepId": "step_1",
124+
"result": "🐾 Meet my adorable little buddy! 🐱✨ This is my cute black cat with a charming white mustache! Isn’t he just the cutest? 😻 He always knows how to put a smile on my face! \n\nWhat do you think of his mustache? Let me know in the comments! 💬👇\n\n#CatLovers #CuteCats #BlackCat #CatMustache #FurryFriend #PetLove #Caturday",
125+
"usage": {
126+
"completionTokens": 91,
127+
"promptTokens": 139,
128+
"totalTokens": 230
129+
},
130+
"timingMs": 4028
131+
}
132+
]
133+
}
104134
]
105135
}

packages/litlytics/engine/runPipeline.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export async function runPipeline(
88
litlytics: LitLytics,
99
onStatus: (status: PipelineStatus) => void
1010
) {
11+
const pipeline = structuredClone(litlytics.pipeline);
12+
1113
// get source
12-
const source = litlytics.pipeline.source;
14+
const source = pipeline.source;
1315
// validate source
1416
if (!source) {
1517
throw new Error('Source is required!');
@@ -19,7 +21,7 @@ export async function runPipeline(
1921
onStatus({ status: 'sourcing' });
2022

2123
// get all documents from the source
22-
const docs: Doc[] = litlytics.pipeline.source.docs;
24+
const docs: Doc[] = pipeline.source.docs;
2325
// validate docs
2426
if (!docs?.length) {
2527
throw new Error('At least one document is required!');
@@ -31,7 +33,7 @@ export async function runPipeline(
3133
// get all connections to source
3234
let stepIds = source.connectsTo;
3335
// find all connected steps
34-
let nextStep = litlytics.pipeline.steps.find((s) => stepIds.includes(s.id));
36+
let nextStep = pipeline.steps.find((s) => stepIds.includes(s.id));
3537
// while there are follow-up steps - continue;
3638
while (nextStep !== undefined) {
3739
onStatus({ status: 'step', currentStep: nextStep });
@@ -43,7 +45,7 @@ export async function runPipeline(
4345
litlytics.runStep({
4446
step: nextStep!,
4547
source,
46-
allSteps: litlytics.pipeline.steps,
48+
allSteps: pipeline.steps,
4749
doc,
4850
allDocs: docs,
4951
})
@@ -64,7 +66,7 @@ export async function runPipeline(
6466
aggregateResult = (await litlytics.runStep({
6567
step: nextStep!,
6668
source,
67-
allSteps: litlytics.pipeline.steps,
69+
allSteps: pipeline.steps,
6870
doc: aggregateResult,
6971
allDocs: docs,
7072
})) as Doc;
@@ -74,16 +76,18 @@ export async function runPipeline(
7476
stepIds = nextStep.connectsTo;
7577
// if we're at the output - handle results and break
7678
if (stepIds.includes(OUTPUT_ID)) {
79+
// store processed docs
80+
pipeline.resultDocs = newDocs.filter((doc) => doc);
7781
// process and store final results
78-
litlytics.pipeline.results = getResults(litlytics, newDocs);
82+
pipeline.results = getResults(litlytics, newDocs);
7983
break;
8084
}
81-
nextStep = litlytics.pipeline.steps.find((s) => stepIds.includes(s.id));
85+
nextStep = pipeline.steps.find((s) => stepIds.includes(s.id));
8286
}
8387

8488
onStatus({ status: 'done' });
8589

8690
// save result to pipeline
8791
// pipeline.results = finalResult;
88-
return litlytics.pipeline;
92+
return pipeline;
8993
}

packages/litlytics/pipeline/Pipeline.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Doc } from '../doc/Document';
12
import type { Result } from '../output/Output';
23
import type { ProcessingStep, SourceStep } from '../step/Step';
34

@@ -6,6 +7,7 @@ export interface Pipeline {
67
pipelineDescription?: string;
78
pipelinePlan?: string;
89
source: SourceStep;
10+
resultDocs?: Doc[];
911
results?: Result[];
1012
steps: ProcessingStep[];
1113
provider?: string;

0 commit comments

Comments
 (0)