(self, db=None, table_name=None, schema=None, library_name=None, account_name="llmware",
auto_correct_schema_errors=True,auto_correct_postpend="_d")
| 3201 | larger projects. """ |
| 3202 | |
| 3203 | def __init__(self, db=None, table_name=None, schema=None, library_name=None, account_name="llmware", |
| 3204 | auto_correct_schema_errors=True,auto_correct_postpend="_d"): |
| 3205 | |
| 3206 | # check for llmware path & create if not already set up, e.g., "first time use" |
| 3207 | if not os.path.exists(LLMWareConfig.get_llmware_path()): |
| 3208 | LLMWareConfig.setup_llmware_workspace() |
| 3209 | logger.info("CustomTable - Setting up LLMWare Workspace.") |
| 3210 | |
| 3211 | if not db: |
| 3212 | self.db = LLMWareConfig().get_active_db() |
| 3213 | else: |
| 3214 | if db in LLMWareConfig().get_supported_collection_db(): |
| 3215 | self.db = db |
| 3216 | |
| 3217 | self.reserved_tables = ["status", "library", "parser_events"] |
| 3218 | |
| 3219 | # this list will be improved over time to include common reserved col names |
| 3220 | self.reserved_col_names = ["table","text"] |
| 3221 | |
| 3222 | if table_name not in self.reserved_tables: |
| 3223 | self.table_name = table_name |
| 3224 | else: |
| 3225 | logger.warning( |
| 3226 | f"error: proposed custom table name - {table_name} - is a reserved table name and can not be used. " |
| 3227 | f"self.table_name is being set to None, and will need to be set to a different name before using.") |
| 3228 | |
| 3229 | self.table_name = None |
| 3230 | |
| 3231 | self.schema = schema |
| 3232 | self.library_name = library_name |
| 3233 | self.account_name = account_name |
| 3234 | self.db_connection = None |
| 3235 | |
| 3236 | # if schema column name is in reserved list, then will add the value of schema_postpend to end of string |
| 3237 | self.auto_correct_schema_errors = auto_correct_schema_errors |
| 3238 | self.postpend = auto_correct_postpend |
| 3239 | |
| 3240 | # attributes used when loading a custom csv or json/jsonl to populate a table |
| 3241 | self.rows = None |
| 3242 | self.col_numbers = [] |
| 3243 | self.col_names = [] |
| 3244 | self.column_map = {} |
| 3245 | self.sql_create_table = None |
| 3246 | |
| 3247 | # check if table_name already registered in LLMWareTableSchema |
| 3248 | if table_name in LLMWareTableSchema().get_custom_tables() and not self.schema: |
| 3249 | |
| 3250 | self.schema = LLMWareTableSchema().get_custom_schema()[table_name] |
| 3251 | |
| 3252 | # check if table already created in DB, and if not, create table |
| 3253 | if table_name and self.schema: |
| 3254 | |
| 3255 | if self.db != "mongo": |
| 3256 | self.build_table() |
| 3257 | |
| 3258 | # confirm that table name and schema are registered in LLMWareTableSchema for easy future access |
| 3259 | if self.table_name and self.schema: |
| 3260 | LLMWareTableSchema().register_custom_schema(self.table_name, self.schema, replace=False) |
nothing calls this directly
no test coverage detected