MCPcopy Index your code
hub / github.com/caesarHQ/textSQL / fetchBackend

Function fetchBackend

client/censusGPT/src/App.js:504–773  ·  view source on GitHub ↗
(natural_language_query)

Source from the content-addressed store, hash-verified

502 }
503
504 const fetchBackend = async (natural_language_query) => {
505 if (natural_language_query == null) {
506 return
507 }
508 // Don't send a request if the query is empty!
509 natural_language_query = natural_language_query.trim()
510 if (!natural_language_query.length) return
511
512 setTableNames()
513 setSqlExplanation()
514 setShowExplanationModal(false)
515
516 // clear previous layers
517 clearMapLayers()
518 clearAllButQuery()
519 const table_names = await getTables(natural_language_query)
520
521 if (!table_names) {
522 await getSuggestionForFailedQuery()
523 return
524 }
525
526 // Set the loading state
527 setIsLoading(true)
528
529 let requestBody = {
530 natural_language_query,
531 table_names,
532 scope: props.version === 'San Francisco' ? 'SF' : 'USA',
533 session_id: sessionId,
534 generation_id: currentGenerationId,
535 }
536
537 // Set the options for the fetch request
538 const options = {
539 method: 'POST',
540 headers: { 'content-type': 'application/json' },
541 body: JSON.stringify(requestBody),
542 }
543
544 let responseOuter = null
545 // Send the request
546 const startTime = new Date().getTime()
547 const apiCall = fetch(api_endpoint + '/api/text_to_sql', options)
548 const TIMEOUT_DURATION = 45000
549 const timeout = new Promise((_, reject) => {
550 setTimeout(() => {
551 reject(new Error('Server failed to respond in time'))
552 }, TIMEOUT_DURATION) // timeout after 45 seconds
553 })
554 Promise.race([apiCall, timeout])
555 .then((response) => response.json())
556 .then(async (response) => {
557 // Set the loading state to false
558 setIsLoading(false)
559
560 // Handle errors
561 if (!response) {

Callers 4

handleClickExampleFunction · 0.85
App.jsFile · 0.85
handleSearchClickFunction · 0.85
handleClickFunction · 0.85

Calls 10

capturePosthogFunction · 0.90
getCitiesFunction · 0.90
getZipcodesFunction · 0.90
logSentryErrorFunction · 0.90
clearMapLayersFunction · 0.85
clearAllButQueryFunction · 0.85
getTablesFunction · 0.85
getSuggestionForQueryFunction · 0.85

Tested by

no test coverage detected