(id, question, conversationHistory, currentQuery)
| 244 | } |
| 245 | |
| 246 | askAi(id, question, conversationHistory, currentQuery) { |
| 247 | return this.findById(id) |
| 248 | .then(async (dataRequest) => { |
| 249 | const connection = await db.Connection.findByPk(dataRequest.Connection.id); |
| 250 | const source = findSourceForConnection(connection); |
| 251 | let schema = connection?.schema; |
| 252 | if (!schema) { |
| 253 | if (source?.backend?.ai?.getSchema) { |
| 254 | assertSourceServerEnabled(source); |
| 255 | schema = await source.backend.ai.getSchema({ connection, dataRequest }); |
| 256 | } else if (source?.backend?.getSchema) { |
| 257 | assertSourceServerEnabled(source); |
| 258 | schema = await source.backend.getSchema({ connection, dataRequest }); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (!schema) { |
| 263 | return Promise.reject(new Error("No schema found. Please test your connection first.")); |
| 264 | } |
| 265 | |
| 266 | let aiResponse; |
| 267 | if (source?.backend?.ai?.generateQuery) { |
| 268 | assertSourceServerEnabled(source); |
| 269 | aiResponse = await source.backend.ai.generateQuery({ |
| 270 | schema, |
| 271 | question, |
| 272 | conversationHistory, |
| 273 | currentQuery, |
| 274 | connection, |
| 275 | dataRequest, |
| 276 | }); |
| 277 | } else { |
| 278 | aiResponse = await generateSqlQuery( |
| 279 | schema, question, conversationHistory, currentQuery |
| 280 | ); |
| 281 | } |
| 282 | |
| 283 | return aiResponse; |
| 284 | }) |
| 285 | .catch((error) => { |
| 286 | return Promise.reject(error); |
| 287 | }); |
| 288 | } |
| 289 | |
| 290 | createVariableBinding(id, data) { |
| 291 | const newVar = { |
no test coverage detected