diff --git a/llama_stack/providers/utils/inference/inference_store.py b/llama_stack/providers/utils/inference/inference_store.py index 50f5af117..8d5958eee 100644 --- a/llama_stack/providers/utils/inference/inference_store.py +++ b/llama_stack/providers/utils/inference/inference_store.py @@ -56,7 +56,7 @@ class InferenceStore: logger.debug("Write queue disabled for SQLite (WAL mode handles concurrency)") await self.sql_store.create_table( - "chat_completions", + self.reference.table_name, { "id": ColumnDefinition(type=ColumnType.STRING, primary_key=True), "created": ColumnType.INTEGER, @@ -161,7 +161,7 @@ class InferenceStore: try: await self.sql_store.insert( - table="chat_completions", + table=self.reference.table_name, data=record_data, ) except IntegrityError as e: @@ -173,7 +173,7 @@ class InferenceStore: error_message = str(e.orig) if e.orig else str(e) if self._is_unique_constraint_error(error_message): # Update the existing record instead - await self.sql_store.update(table="chat_completions", data=record_data, where={"id": data["id"]}) + await self.sql_store.update(table=self.reference.table_name, data=record_data, where={"id": data["id"]}) else: # Re-raise if it's not a unique constraint error raise @@ -217,7 +217,7 @@ class InferenceStore: where_conditions["model"] = model paginated_result = await self.sql_store.fetch_all( - table="chat_completions", + table=self.reference.table_name, where=where_conditions if where_conditions else None, order_by=[("created", order.value)], cursor=("id", after) if after else None, @@ -246,7 +246,7 @@ class InferenceStore: raise ValueError("Inference store is not initialized") row = await self.sql_store.fetch_one( - table="chat_completions", + table=self.reference.table_name, where={"id": completion_id}, ) diff --git a/tests/unit/utils/inference/test_inference_store.py b/tests/unit/utils/inference/test_inference_store.py index d2de1c759..02e8407b8 100644 --- a/tests/unit/utils/inference/test_inference_store.py +++ b/tests/unit/utils/inference/test_inference_store.py @@ -210,3 +210,32 @@ async def test_inference_store_pagination_no_limit(): assert result.data[0].id == "beta-second" # Most recent first assert result.data[1].id == "omega-first" assert result.has_more is False + + +async def test_inference_store_custom_table_name(): + """Test that the table_name from config is respected.""" + custom_table_name = "custom_inference_store" + reference = InferenceStoreReference(backend="sql_default", table_name=custom_table_name) + store = InferenceStore(reference, policy=[]) + await store.initialize() + + # Create and store a test chat completion + base_time = int(time.time()) + completion = create_test_chat_completion("custom-table-test", base_time) + input_messages = [OpenAIUserMessageParam(role="user", content="Test custom table")] + await store.store_chat_completion(completion, input_messages) + await store.flush() + + # Verify we can retrieve the completion + result = await store.get_chat_completion("custom-table-test") + assert result.id == "custom-table-test" + assert result.model == "test-model" + + # Verify listing works + list_result = await store.list_chat_completions() + assert len(list_result.data) == 1 + assert list_result.data[0].id == "custom-table-test" + + # Verify the error message uses the custom table name + with pytest.raises(ValueError, match=f"Record with id='non-existent' not found in table '{custom_table_name}'"): + await store.list_chat_completions(after="non-existent", limit=2)