Initialize DuckDB table.
(self)
| 64 | return self._local.conn |
| 65 | |
| 66 | def _init_db(self): |
| 67 | """Initialize DuckDB table.""" |
| 68 | try: |
| 69 | conn = self._get_conn() |
| 70 | conn.execute(""" |
| 71 | CREATE TABLE IF NOT EXISTS cache ( |
| 72 | task VARCHAR, |
| 73 | input_hash VARCHAR, |
| 74 | config_key VARCHAR, |
| 75 | params_json VARCHAR, |
| 76 | output VARCHAR, |
| 77 | duration DOUBLE, |
| 78 | timestamp DOUBLE, |
| 79 | PRIMARY KEY (task, input_hash, config_key, params_json) |
| 80 | ) |
| 81 | """) |
| 82 | count = conn.execute("SELECT COUNT(*) FROM cache").fetchone()[0] |
| 83 | if count > 0: |
| 84 | tasks = conn.execute("SELECT DISTINCT task FROM cache").fetchall() |
| 85 | tasks_str = ', '.join(t[0] for t in tasks) |
| 86 | print(f"Cache: {count} entries ({tasks_str})") |
| 87 | except Exception as e: |
| 88 | print(f"Warning: Could not initialize cache: {e}") |
| 89 | self.enabled = False |
| 90 | |
| 91 | def get(self, task: str, input_text: str, config_key: str, params: dict = None) -> Optional[Tuple[str, float]]: |
| 92 | """Get cached result. |