MCPcopy Index your code
hub / github.com/dbcli/mycli / get_sample_data

Function get_sample_data

mycli/packages/special/llm.py:342–368  ·  view source on GitHub ↗
(
    cur: Cursor,
    dbname: str,
    prompt_field_truncate: int,
    prompt_section_truncate: int,
)

Source from the content-addressed store, hash-verified

340
341
342def get_sample_data(
343 cur: Cursor,
344 dbname: str,
345 prompt_field_truncate: int,
346 prompt_section_truncate: int,
347) -> dict[str, Any]:
348 if dbname in SAMPLE_DATA_CACHE:
349 return SAMPLE_DATA_CACHE[dbname]
350 click.echo("Preparing sample data to feed the LLM")
351 tables_query = "SHOW TABLES"
352 sample_row_query = "SELECT * FROM `{dbname}`.`{table}` LIMIT 1"
353 cur.execute(tables_query)
354 sample_data = {}
355 for (table_name,) in cur.fetchall():
356 try:
357 cur.execute(sample_row_query.format(dbname=dbname, table=table_name))
358 except Exception:
359 continue
360 cols = [desc[0] for desc in cur.description]
361 row = cur.fetchone()
362 if row is None:
363 continue
364 sample_data[table_name] = list(
365 zip(cols, truncate_list_elements(list(row), prompt_field_truncate, prompt_section_truncate), strict=False)
366 )
367 SAMPLE_DATA_CACHE[dbname] = sample_data
368 return sample_data
369
370
371def sql_using_llm(

Calls 5

truncate_list_elementsFunction · 0.85
echoMethod · 0.45
executeMethod · 0.45
fetchallMethod · 0.45
fetchoneMethod · 0.45