dn-scribe commited on
Commit
c72ec26
·
unverified ·
1 Parent(s): 9226d72

get_prompts_by_dataset

Browse files
docs/dataset_tables.json CHANGED
The diff for this file is too large to render. See raw diff
 
scribe_python_client/client.py CHANGED
@@ -1268,7 +1268,7 @@ class ScribeClient:
1268
 
1269
  self.get_dataset_data(dataset_links)
1270
 
1271
- #Load data from the CSV file (generated by get_dataset_data)
1272
  records = []
1273
  try:
1274
  with open("dataset_metadata.csv", mode="r", encoding="utf-8") as f:
@@ -1279,7 +1279,7 @@ class ScribeClient:
1279
  logging.error(f"Failed to load dataset_metadata.csv: {e}")
1280
  return {}
1281
 
1282
- #Group column data by table name
1283
  table_dict = {}
1284
  for row in records:
1285
  table_name = row.get("table_name")
@@ -1296,6 +1296,33 @@ class ScribeClient:
1296
  "description": row.get("column_description", "")
1297
  })
1298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1299
  return table_dict
1300
 
1301
 
@@ -1371,4 +1398,41 @@ class ScribeClient:
1371
  f.write(markdown_output)
1372
 
1373
  logging.info("Saved table metadata Markdown to dataset_tables.md")
1374
- return markdown_output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1268
 
1269
  self.get_dataset_data(dataset_links)
1270
 
1271
+ # Load data from the CSV file (generated by get_dataset_data)
1272
  records = []
1273
  try:
1274
  with open("dataset_metadata.csv", mode="r", encoding="utf-8") as f:
 
1279
  logging.error(f"Failed to load dataset_metadata.csv: {e}")
1280
  return {}
1281
 
1282
+ # Group column data by table name
1283
  table_dict = {}
1284
  for row in records:
1285
  table_name = row.get("table_name")
 
1296
  "description": row.get("column_description", "")
1297
  })
1298
 
1299
+ # Add markdown for each table
1300
+ for table_name, cols in table_dict.items():
1301
+ md_parts = []
1302
+ md_parts.append(f"## `{table_name}` Columns\n\n")
1303
+ md_parts.append("| Column Name | Label | Type | Description | Like-compliant |\n")
1304
+ md_parts.append("|-------------|-------|------|-------------|----------------|\n")
1305
+ for col in cols:
1306
+ column_name = col["column_name"]
1307
+ label = col["label"]
1308
+ col_type = col["type"].upper()
1309
+ description = col["description"]
1310
+ expr = row.get("expression", "") or ""
1311
+ if col_type == "STRING" and (" in (" in expr.lower() or " in(" in expr.lower()):
1312
+ like_compliant = False
1313
+ else:
1314
+ like_compliant = True
1315
+ md_parts.append(
1316
+ f"| `{column_name}` | {label} | {col_type} | {description} | {str(like_compliant)} |\n"
1317
+ )
1318
+ md_parts.append("\n")
1319
+ md_str = "".join(md_parts)
1320
+ # Add markdown string to the dict for this table
1321
+ # If table_dict[table_name] is a list, convert to dict with 'columns' and 'md'
1322
+ table_dict[table_name] = {
1323
+ "columns": cols,
1324
+ "md": md_str
1325
+ }
1326
  return table_dict
1327
 
1328
 
 
1398
  f.write(markdown_output)
1399
 
1400
  logging.info("Saved table metadata Markdown to dataset_tables.md")
1401
+ return markdown_output
1402
+
1403
+ def get_dataset_prompt(self, dataset, pretable_tex_file="", posttable_text_file=""):
1404
+ """
1405
+ Returns a prompt string for the given dataset, optionally wrapped with pre/post text from files.
1406
+ - dataset: table name to fetch from docs/dataset_tables.json
1407
+ - pretable_tex_file: filename to prepend (optional)
1408
+ - posttable_text_file: filename to append (optional)
1409
+ """
1410
+ import os
1411
+ import json
1412
+ # Load table data from docs/dataset_tables.json
1413
+ table_json_path = os.path.join("docs", "dataset_tables.json")
1414
+ if not os.path.exists(table_json_path):
1415
+ raise FileNotFoundError(f"dataset_tables.json not found at {table_json_path}")
1416
+ with open(table_json_path, "r", encoding="utf-8") as f:
1417
+ tables = json.load(f)
1418
+ if dataset not in tables:
1419
+ raise ValueError(f"Dataset '{dataset}' not found in dataset_tables.json")
1420
+ table_md = tables[dataset].get("md")
1421
+ if not table_md:
1422
+ raise ValueError(f"No markdown found for dataset '{dataset}' in dataset_tables.json")
1423
+ # Read pre/post text if provided
1424
+ pre_text = ""
1425
+ post_text = ""
1426
+ if pretable_tex_file:
1427
+ if not os.path.exists(pretable_tex_file):
1428
+ raise FileNotFoundError(f"Pre-table file '{pretable_tex_file}' not found.")
1429
+ with open(pretable_tex_file, "r", encoding="utf-8") as f:
1430
+ pre_text = f.read()
1431
+ if posttable_text_file:
1432
+ if not os.path.exists(posttable_text_file):
1433
+ raise FileNotFoundError(f"Post-table file '{posttable_text_file}' not found.")
1434
+ with open(posttable_text_file, "r", encoding="utf-8") as f:
1435
+ post_text = f.read()
1436
+ # Build prompt
1437
+ prompt = f"{pre_text}{table_md}{post_text}"
1438
+ return prompt