| "RUF022", # unsorted-dunder-all | "RUF022", # unsorted-dunder-all | ||||
| "S506", # unsafe-yaml-load | "S506", # unsafe-yaml-load | ||||
| "SIM", # flake8-simplify rules | "SIM", # flake8-simplify rules | ||||
| "T201", # print-found | |||||
| "TRY400", # error-instead-of-exception | "TRY400", # error-instead-of-exception | ||||
| "TRY401", # verbose-log-message | "TRY401", # verbose-log-message | ||||
| "UP", # pyupgrade rules | "UP", # pyupgrade rules | ||||
| "configs/*" = [ | "configs/*" = [ | ||||
| "N802", # invalid-function-name | "N802", # invalid-function-name | ||||
| ] | ] | ||||
| "core/model_runtime/callbacks/base_callback.py" = [ | |||||
| "T201", | |||||
| ] | |||||
| "core/workflow/callbacks/workflow_logging_callback.py" = [ | |||||
| "T201", | |||||
| ] | |||||
| "libs/gmpy2_pkcs10aep_cipher.py" = [ | "libs/gmpy2_pkcs10aep_cipher.py" = [ | ||||
| "N803", # invalid-argument-name | "N803", # invalid-argument-name | ||||
| ] | ] | ||||
| "tests/*" = [ | "tests/*" = [ | ||||
| "F811", # redefined-while-unused | "F811", # redefined-while-unused | ||||
| "T201", # allow print in tests | |||||
| ] | ] | ||||
| [lint.pyflakes] | [lint.pyflakes] |
| try: | try: | ||||
| app = db.session.query(App).where(App.id == app_id).first() | app = db.session.query(App).where(App.id == app_id).first() | ||||
| if not app: | if not app: | ||||
| print(f"App {app_id} not found") | |||||
| logger.info("App %s not found", app_id) | |||||
| continue | continue | ||||
| tenant = app.tenant | tenant = app.tenant | ||||
| if tenant: | if tenant: | ||||
| accounts = tenant.get_accounts() | accounts = tenant.get_accounts() | ||||
| if not accounts: | if not accounts: | ||||
| print(f"Fix failed for app {app.id}") | |||||
| logger.info("Fix failed for app %s", app.id) | |||||
| continue | continue | ||||
| account = accounts[0] | account = accounts[0] | ||||
| print(f"Fixing missing site for app {app.id}") | |||||
| logger.info("Fixing missing site for app %s", app.id) | |||||
| app_was_created.send(app, account=account) | app_was_created.send(app, account=account) | ||||
| except Exception: | except Exception: | ||||
| failed_app_ids.append(app_id) | failed_app_ids.append(app_id) |
| if not login_status: | if not login_status: | ||||
| raise ValueError("Weave login failed") | raise ValueError("Weave login failed") | ||||
| else: | else: | ||||
| print("Weave login successful") | |||||
| logger.info("Weave login successful") | |||||
| return True | return True | ||||
| except Exception as e: | except Exception as e: | ||||
| logger.debug("Weave API check failed: %s", str(e)) | logger.debug("Weave API check failed: %s", str(e)) |
| try: | try: | ||||
| metadata = json.loads(metadata_str) | metadata = json.loads(metadata_str) | ||||
| except json.JSONDecodeError: | except json.JSONDecodeError: | ||||
| print(f"Invalid JSON metadata: {metadata_str}") | |||||
| logger.warning("Invalid JSON metadata: %s", metadata_str) | |||||
| metadata = {} | metadata = {} | ||||
| metadata["score"] = score | metadata["score"] = score | ||||
| docs.append(Document(page_content=_text, metadata=metadata)) | docs.append(Document(page_content=_text, metadata=metadata)) |
| import array | import array | ||||
| import json | import json | ||||
| import logging | |||||
| import re | import re | ||||
| import uuid | import uuid | ||||
| from typing import Any | from typing import Any | ||||
| from extensions.ext_redis import redis_client | from extensions.ext_redis import redis_client | ||||
| from models.dataset import Dataset | from models.dataset import Dataset | ||||
| logger = logging.getLogger(__name__) | |||||
| oracledb.defaults.fetch_lobs = False | oracledb.defaults.fetch_lobs = False | ||||
| value, | value, | ||||
| ) | ) | ||||
| conn.commit() | conn.commit() | ||||
| except Exception as e: | |||||
| print(e) | |||||
| except Exception: | |||||
| logger.exception("Failed to insert record %s into %s", value[0], self.table_name) | |||||
| conn.close() | conn.close() | ||||
| return pks | return pks | ||||
| import json | import json | ||||
| import logging | |||||
| import uuid | import uuid | ||||
| from typing import Any | from typing import Any | ||||
| from core.rag.models.document import Document | from core.rag.models.document import Document | ||||
| from extensions.ext_redis import redis_client | from extensions.ext_redis import redis_client | ||||
| logger = logging.getLogger(__name__) | |||||
| Base = declarative_base() # type: Any | Base = declarative_base() # type: Any | ||||
| delete_condition = chunks_table.c.id.in_(ids) | delete_condition = chunks_table.c.id.in_(ids) | ||||
| conn.execute(chunks_table.delete().where(delete_condition)) | conn.execute(chunks_table.delete().where(delete_condition)) | ||||
| return True | return True | ||||
| except Exception as e: | |||||
| print("Delete operation failed:", str(e)) | |||||
| except Exception: | |||||
| logger.exception("Delete operation failed for collection %s", self._collection_name) | |||||
| return False | return False | ||||
| def delete_by_metadata_field(self, key: str, value: str): | def delete_by_metadata_field(self, key: str, value: str): |
| delete_condition = table.c.id.in_(ids) | delete_condition = table.c.id.in_(ids) | ||||
| conn.execute(table.delete().where(delete_condition)) | conn.execute(table.delete().where(delete_condition)) | ||||
| return True | return True | ||||
| except Exception as e: | |||||
| print("Delete operation failed:", str(e)) | |||||
| except Exception: | |||||
| logger.exception("Delete operation failed for collection %s", self._collection_name) | |||||
| return False | return False | ||||
| def get_ids_by_metadata_field(self, key: str, value: str): | def get_ids_by_metadata_field(self, key: str, value: str): |
| record_id = str(i.id) | record_id = str(i.id) | ||||
| provider_name = str(i.provider_name) | provider_name = str(i.provider_name) | ||||
| retrieval_model = i.retrieval_model | retrieval_model = i.retrieval_model | ||||
| print(type(retrieval_model)) | |||||
| logger.debug( | |||||
| "Processing dataset %s with retrieval model of type %s", | |||||
| record_id, | |||||
| type(retrieval_model), | |||||
| ) | |||||
| if record_id in failed_ids: | if record_id in failed_ids: | ||||
| continue | continue |