-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_node_test.go
More file actions
136 lines (108 loc) · 3.67 KB
/
workflow_node_test.go
File metadata and controls
136 lines (108 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package unstructured
import (
"maps"
"strings"
"testing"
)
func TestWorkflowNodeOrder(t *testing.T) {
t.Parallel()
partitioners := map[string]WorkflowNode{
"none": nil,
"partition_auto": &PartitionerAuto{},
"partition_vlm": &PartitionerVLM{},
"partition_hires": &PartitionerHiRes{},
"partition_fast": &PartitionerFast{},
}
chunkers := map[string]WorkflowNode{
"none": nil,
"chunker_character": &ChunkerCharacter{},
"chunker_title": &ChunkerTitle{},
"chunker_page": &ChunkerPage{},
"chunker_similarity": &ChunkerSimilarity{},
}
enrichers := map[string]*Enricher{
"none": nil,
"enricher_image_openai": {Subtype: EnrichmentTypeImageOpenAI},
"enricher_table_openai": {Subtype: EnrichmentTypeTableOpenAI},
"enricher_table2html_openai": {Subtype: EnrichmentTypeTable2HTMLOpenAI},
"enricher_ner_openai": {Subtype: EnrichmentTypeNEROpenAI},
"enricher_image_anthropic": {Subtype: EnrichmentTypeImageAnthropic},
"enricher_table_anthropic": {Subtype: EnrichmentTypeTableAnthropic},
"enricher_ner_anthropic": {Subtype: EnrichmentTypeNERAnthropic},
"enricher_image_bedrock": {Subtype: EnrichmentTypeImageBedrock},
"enricher_table_bedrock": {Subtype: EnrichmentTypeTableBedrock},
}
embedders := map[string]WorkflowNode{
"none": nil,
"embedder": &Embedder{},
}
type testcase struct {
nodes WorkflowNodes
wantErr bool
}
tests := make(map[string]testcase, len(partitioners)*len(chunkers)*len(embedders)*len(enrichers)+4)
for partitionerName, partitioner := range partitioners {
for chunkerName, chunker := range chunkers {
for enricherName, enricher := range enrichers {
for embedderName, embedder := range embedders {
labels := []string{}
var tc testcase
tc.wantErr = partitioner == nil
if partitioner != nil {
labels = append(labels, partitionerName)
tc.nodes = append(tc.nodes, partitioner)
}
if enricher != nil {
labels = append(labels, enricherName)
tc.nodes = append(tc.nodes, enricher)
tc.wantErr = tc.wantErr || chunker == nil
}
if chunker != nil {
labels = append(labels, chunkerName)
tc.nodes = append(tc.nodes, chunker)
}
if embedder != nil {
labels = append(labels, embedderName)
tc.nodes = append(tc.nodes, embedder)
tc.wantErr = tc.wantErr || chunker == nil
}
name := strings.Join(labels, "-")
if name == "" {
name = "none"
}
tests[name] = tc
}
}
}
}
maps.Copy(tests, map[string]testcase{
"wrong_order": {
nodes: WorkflowNodes{&PartitionerAuto{}, &ChunkerCharacter{}, &Embedder{}, &Enricher{Subtype: EnrichmentTypeImageOpenAI}},
wantErr: true,
},
"double_image_enricher": {
nodes: WorkflowNodes{&PartitionerAuto{}, &Enricher{Subtype: EnrichmentTypeImageOpenAI}, &Enricher{Subtype: EnrichmentTypeImageAnthropic}, &ChunkerCharacter{}},
wantErr: true,
},
"double_table_enricher": {
nodes: WorkflowNodes{&PartitionerAuto{}, &Enricher{Subtype: EnrichmentTypeTableOpenAI}, &Enricher{Subtype: EnrichmentTypeTableBedrock}, &ChunkerCharacter{}},
wantErr: true,
},
"double_ner_enricher": {
nodes: WorkflowNodes{&PartitionerAuto{}, &Enricher{Subtype: EnrichmentTypeNEROpenAI}, &Enricher{Subtype: EnrichmentTypeNERAnthropic}, &ChunkerCharacter{}},
wantErr: true,
},
})
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
got := test.nodes.ValidateNodeOrder()
switch {
case !test.wantErr && got != nil:
t.Errorf("got\n%v\nwant nil", got)
case test.wantErr && got == nil:
t.Errorf("got nil, want error")
}
})
}
}