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

Function getSuggestionForQuery

client/censusGPT/src/App.js:225–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

223 }
224
225 const getSuggestionForQuery = async () => {
226 currentSuggestionId = null
227 const options = {
228 method: 'POST',
229 headers: { 'content-type': 'application/json' },
230 body: JSON.stringify({
231 natural_language_query: query,
232 scope: props.version === 'San Francisco' ? 'SF' : 'USA',
233 generation_id: currentGenerationId,
234 session_id: sessionId,
235 }),
236 }
237
238 fetch(api_endpoint + '/api/get_suggestion', options)
239 .then((response) => response.json())
240 .then((response) => {
241 // Handle errors
242 if (!response || !response.suggested_query) {
243 capturePosthog('backend_error', response)
244 return
245 }
246
247 // Capture the response in posthog
248 capturePosthog('backend_response', {
249 origin: 'getSuggestionForQuery',
250 })
251 // Set the state for SQL and Status Code
252
253 if (response.generation_id)
254 currentSuggestionId = response.generation_id
255
256 setSuggestedQuery(response.suggested_query)
257 })
258 .catch((err) => {
259 logSentryError({ query }, err)
260 setIsLoading(false)
261 capturePosthog('backend_error', {
262 error: err,
263 })
264 console.error(err)
265 })
266 }
267
268 const executeSql = (sql) => {
269 setIsLoading(true)

Callers 1

fetchBackendFunction · 0.85

Calls 2

capturePosthogFunction · 0.90
logSentryErrorFunction · 0.90

Tested by

no test coverage detected