@@ -3,7 +3,7 @@ import path from 'path'
33import { readJSONFile } from '../utils.ts'
44import { run_chat_pipeline } from '../../termdb.chat2.ts'
55import serverconfig from '../../../src/serverconfig.js'
6- import type { DEType , SummaryType , FilterTerm , CategoricalFilterTerm , NumericFilterTerm } from '#types'
6+ import type { DEType , SummaryType , MatrixType , FilterTerm , CategoricalFilterTerm , NumericFilterTerm } from '#types'
77
88const testing = true // This causes raw LLM output to be sent by the agent
99const llm = serverconfig . llm
@@ -50,6 +50,8 @@ export async function test_chatbot_by_dataset(ds: any) {
5050 //console.log("DE request did not match. LLM response :" + JSON.stringify(test_result.response) + " Actual response: " + JSON.stringify(test_data.answer))
5151 validate_DE_output ( test_result . response , test_data . answer )
5252 }
53+ } else if ( test_result . action == 'matrix' ) {
54+ validate_matrix_output ( test_result . response , test_data . answer )
5355 }
5456 }
5557}
@@ -112,6 +114,56 @@ function validate_DE_output(output_DE_object: DEType, expected_DE_output: DEType
112114 return validate_DE_groups
113115}
114116
117+ function validate_matrix_output ( output : MatrixType , expected : MatrixType ) : boolean {
118+ const outputTerms = output . terms || [ ]
119+ const expectedTerms = expected . terms || [ ]
120+ if ( outputTerms . length != expectedTerms . length || ! outputTerms . every ( ( t , i ) => t == expectedTerms [ i ] ) ) {
121+ console . log (
122+ 'Matrix terms did not match. LLM response: ' +
123+ JSON . stringify ( outputTerms ) +
124+ ' Expected: ' +
125+ JSON . stringify ( expectedTerms )
126+ )
127+ return false
128+ }
129+
130+ const outputGenes = output . geneNames || [ ]
131+ const expectedGenes = expected . geneNames || [ ]
132+ if ( outputGenes . length != expectedGenes . length || ! outputGenes . every ( ( g , i ) => g == expectedGenes [ i ] ) ) {
133+ console . log (
134+ 'Matrix geneNames did not match. LLM response: ' +
135+ JSON . stringify ( outputGenes ) +
136+ ' Expected: ' +
137+ JSON . stringify ( expectedGenes )
138+ )
139+ return false
140+ }
141+
142+ if ( ! output . simpleFilter && ! expected . simpleFilter ) {
143+ return true
144+ }
145+ if ( ! output . simpleFilter || ! expected . simpleFilter ) {
146+ console . log (
147+ 'Matrix simpleFilter mismatch. LLM response: ' +
148+ JSON . stringify ( output . simpleFilter ) +
149+ ' Expected: ' +
150+ JSON . stringify ( expected . simpleFilter )
151+ )
152+ return false
153+ }
154+
155+ const filter_valid = validate_filter ( output . simpleFilter , expected . simpleFilter )
156+ if ( ! filter_valid ) {
157+ console . log (
158+ 'Matrix simpleFilter did not match. LLM response: ' +
159+ JSON . stringify ( output . simpleFilter ) +
160+ ' Expected: ' +
161+ JSON . stringify ( expected . simpleFilter )
162+ )
163+ }
164+ return filter_valid
165+ }
166+
115167function validate_filter ( output_filter : FilterTerm [ ] , expected_filter : FilterTerm [ ] ) : boolean {
116168 if ( output_filter . length != expected_filter . length ) {
117169 return false
0 commit comments