|
| 1 | +import faker from '@faker-js/faker'; |
1 | 2 | import { getTestCompiler } from '@vulcan-sql/test-utility'; |
2 | 3 | import * as dotenv from 'dotenv'; |
3 | 4 | import * as path from 'path'; |
@@ -32,53 +33,6 @@ const data = [ |
32 | 33 | }, |
33 | 34 | ]; |
34 | 35 |
|
35 | | -it.each([ |
36 | | - { question: 'what repository has most stars?', expected: 'vulcan-sql' }, |
37 | | - { question: 'what repository has lowest stars?', expected: 'hell-word' }, |
38 | | - { |
39 | | - question: 'How many stars does the vulcan-sql repository have?', |
40 | | - expected: '1000', |
41 | | - }, |
42 | | - { |
43 | | - question: 'How many stars does the accio repository have?', |
44 | | - expected: '500', |
45 | | - }, |
46 | | - { |
47 | | - question: 'How many repositories related to data-lake topic?', |
48 | | - expected: 'vulcan-sql, accio', |
49 | | - }, |
50 | | -])( |
51 | | - 'Should get correct expected $answer when asking $question', |
52 | | - async ({ question, expected }) => { |
53 | | - // Arrange |
54 | | - |
55 | | - const token = process.env['HF_ACCESS_TOKEN']; |
56 | | - const { compileAndLoad, execute, getExecutedQueries, getCreatedBinding } = |
57 | | - await getTestCompiler({ |
58 | | - extensions: { huggingface: path.join(__dirname, '..', 'src') }, |
59 | | - huggingface: { |
60 | | - accessToken: token, |
61 | | - }, |
62 | | - }); |
63 | | - |
64 | | - const sql = `{% set data = ${JSON.stringify( |
65 | | - data |
66 | | - )} %}SELECT {{ data | huggingface_table_question_answering(query="${question}") }}`; |
67 | | - |
68 | | - // Act |
69 | | - await compileAndLoad(sql); |
70 | | - await execute({}); |
71 | | - |
72 | | - // Assert |
73 | | - const queries = await getExecutedQueries(); |
74 | | - const bindings = await getCreatedBinding(); |
75 | | - |
76 | | - expect(queries[0]).toBe('SELECT $1'); |
77 | | - expect(bindings[0].get('$1')).toEqual(expected); |
78 | | - }, |
79 | | - 50 * 1000 |
80 | | -); |
81 | | - |
82 | 36 | it( |
83 | 37 | 'Should throw error when not pass the "query" argument', |
84 | 38 | async () => { |
@@ -152,27 +106,121 @@ it('Should throw error when input value not be array of object', async () => { |
152 | 106 | }); |
153 | 107 |
|
154 | 108 | it( |
155 | | - 'Should throw error when provided model cause the Hugging Face tableQuestionAnswering task failed', |
| 109 | + 'Should throw error when not provide access token', |
156 | 110 | async () => { |
157 | | - const token = process.env['HF_ACCESS_TOKEN']; |
158 | 111 | const { compileAndLoad, execute } = await getTestCompiler({ |
159 | 112 | extensions: { huggingface: path.join(__dirname, '..', 'src') }, |
160 | 113 | huggingface: { |
161 | | - accessToken: token, |
| 114 | + accessToken: '', |
162 | 115 | }, |
163 | 116 | }); |
164 | 117 |
|
165 | 118 | const sql = `{% set data = ${JSON.stringify( |
166 | 119 | data |
167 | | - )} %}SELECT {{ data | huggingface_table_question_answering(query="what repository has most stars?", model="neulab/omnitab-large-1024shot-finetuned-wtq-1024shot") }}`; |
| 120 | + )} %}SELECT {{ data | huggingface_table_question_answering("${faker.internet.password()}") }}`; |
168 | 121 |
|
169 | 122 | // Act |
170 | 123 | await compileAndLoad(sql); |
171 | 124 |
|
172 | 125 | // Assert |
173 | | - await expect(execute({})).rejects.toThrow( |
174 | | - "Error when sending data to Hugging Face for executing TableQuestionAnswering tasks, details: Invalid inference output: Expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}. Use the 'request' method with the same parameters to do a custom call with no type checking." |
175 | | - ); |
| 126 | + await expect(execute({})).rejects.toThrow('please given access token'); |
| 127 | + }, |
| 128 | + 50 * 1000 |
| 129 | +); |
| 130 | + |
| 131 | +it( |
| 132 | + 'Should throw error when not set hugging face options', |
| 133 | + async () => { |
| 134 | + const { compileAndLoad, execute } = await getTestCompiler({ |
| 135 | + extensions: { huggingface: path.join(__dirname, '..', 'src') }, |
| 136 | + }); |
| 137 | + |
| 138 | + const sql = `{% set data = ${JSON.stringify( |
| 139 | + data |
| 140 | + )} %}SELECT {{ data | huggingface_table_question_answering("${faker.internet.password()}") }}`; |
| 141 | + |
| 142 | + // Act |
| 143 | + await compileAndLoad(sql); |
| 144 | + |
| 145 | + // Assert |
| 146 | + await expect(execute({})).rejects.toThrow('please given access token'); |
| 147 | + }, |
| 148 | + 50 * 1000 |
| 149 | +); |
| 150 | + |
| 151 | +it( |
| 152 | + 'Should get correct expected value when provided "neulab/omnitab-large-1024shot-finetuned-wtq-1024shot" model and wait it for model', |
| 153 | + async () => { |
| 154 | + const token = process.env['HF_ACCESS_TOKEN']; |
| 155 | + const { compileAndLoad, execute, getExecutedQueries, getCreatedBinding } = |
| 156 | + await getTestCompiler({ |
| 157 | + extensions: { huggingface: path.join(__dirname, '..', 'src') }, |
| 158 | + huggingface: { |
| 159 | + accessToken: token, |
| 160 | + }, |
| 161 | + }); |
| 162 | + |
| 163 | + const sql = `{% set data = ${JSON.stringify( |
| 164 | + data |
| 165 | + )} %}SELECT {{ data | huggingface_table_question_answering(query="what repository has most stars?", model="neulab/omnitab-large-1024shot-finetuned-wtq-1024shot", wait_for_model=true) }}`; |
| 166 | + |
| 167 | + // Act |
| 168 | + await compileAndLoad(sql); |
| 169 | + await execute({}); |
| 170 | + |
| 171 | + // Assert |
| 172 | + const queries = await getExecutedQueries(); |
| 173 | + const bindings = await getCreatedBinding(); |
| 174 | + |
| 175 | + expect(queries[0]).toBe('SELECT $1'); |
| 176 | + expect(bindings[0].get('$1')).toEqual('vulcan-sql'); |
| 177 | + }, |
| 178 | + 50 * 1000 |
| 179 | +); |
| 180 | + |
| 181 | +it.each([ |
| 182 | + { question: 'what repository has most stars?', expected: 'vulcan-sql' }, |
| 183 | + { question: 'what repository has lowest stars?', expected: 'hell-word' }, |
| 184 | + { |
| 185 | + question: 'How many stars does the vulcan-sql repository have?', |
| 186 | + expected: '1000', |
| 187 | + }, |
| 188 | + { |
| 189 | + question: 'How many stars does the accio repository have?', |
| 190 | + expected: '500', |
| 191 | + }, |
| 192 | + { |
| 193 | + question: 'How many repositories related to data-lake topic?', |
| 194 | + expected: 'vulcan-sql, accio', |
| 195 | + }, |
| 196 | +])( |
| 197 | + 'Should get correct expected $answer when asking $question', |
| 198 | + async ({ question, expected }) => { |
| 199 | + // Arrange |
| 200 | + |
| 201 | + const token = process.env['HF_ACCESS_TOKEN']; |
| 202 | + const { compileAndLoad, execute, getExecutedQueries, getCreatedBinding } = |
| 203 | + await getTestCompiler({ |
| 204 | + extensions: { huggingface: path.join(__dirname, '..', 'src') }, |
| 205 | + huggingface: { |
| 206 | + accessToken: token, |
| 207 | + }, |
| 208 | + }); |
| 209 | + |
| 210 | + const sql = `{% set data = ${JSON.stringify( |
| 211 | + data |
| 212 | + )} %}SELECT {{ data | huggingface_table_question_answering(query="${question}", wait_for_model=true) }}`; |
| 213 | + |
| 214 | + // Act |
| 215 | + await compileAndLoad(sql); |
| 216 | + await execute({}); |
| 217 | + |
| 218 | + // Assert |
| 219 | + const queries = await getExecutedQueries(); |
| 220 | + const bindings = await getCreatedBinding(); |
| 221 | + |
| 222 | + expect(queries[0]).toBe('SELECT $1'); |
| 223 | + expect(bindings[0].get('$1')).toEqual(expected); |
176 | 224 | }, |
177 | 225 | 50 * 1000 |
178 | 226 | ); |
0 commit comments