Skip to content

Commit

Permalink
[promptflow] Bump SQLAlchemy to 2.x (microsoft#1254)
Browse files Browse the repository at this point in the history
# Description

Bump `SQLAlchemy` to 2.x.

Previously, we have limitation <2.0.0 because another dependency
`dataset` has strict rule on that. However, we don't have code path
requiring `dataset` any more (related feature is deprecated). So in this
PR, remove related code (`LocalCacheStorage`), and `dataset` in
`setup.py`, then bump `SQLAlchemy` version to allow 2.x.

Verification workflows:

SQLAlchemy 2.x:
<https://github.com/microsoft/promptflow/actions/runs/6978087648/job/18988891341?pr=1254#step:10:502>

- Executor
- UT: <https://github.com/microsoft/promptflow/actions/runs/6978087648>
- E2E: <https://github.com/microsoft/promptflow/actions/runs/6978087652>
- SDK/CLI:
<https://github.com/microsoft/promptflow/actions/runs/6978087670>

# All Promptflow Contribution checklist:
- [x] **The pull request does not introduce [breaking changes].**
- [x] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [x] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [x] Title of the pull request is clear and informative.
- [x] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [x] Pull request includes test coverage for the included changes.
  • Loading branch information
zhengfeiwang authored Nov 24, 2023
1 parent 81b6e99 commit 9781c60
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 228 deletions.
1 change: 1 addition & 0 deletions src/promptflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Add env variable 'PF_NO_INTERACTIVE_LOGIN' to disable interactive login if using azureml connection provider in promptflow sdk.
- Improved CLI invoke time.
- Bump `pydash` upper bound to 8.0.0.
- Bump `SQLAlchemy` upper bound to 3.0.0.

## 1.0.0 (2023.11.09)

Expand Down
8 changes: 0 additions & 8 deletions src/promptflow/promptflow/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,4 @@
from promptflow.batch._batch_inputs_processor import apply_inputs_mapping
from promptflow.executor._errors import InputNotFound
from promptflow.executor._tool_invoker import DefaultToolInvoker
from promptflow.storage._cache_storage import LocalCacheStorage
from promptflow.storage._run_storage import DefaultRunStorage
from promptflow.storage._sqlite_client import (
INDEX,
PRIMARY_KEY,
DuplicatedPrimaryKeyException,
NotFoundException,
SqliteClient,
)
51 changes: 1 addition & 50 deletions src/promptflow/promptflow/storage/_cache_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

from dataclasses import asdict, dataclass, field
from dataclasses import dataclass
from datetime import datetime

from promptflow.contracts.run_info import RunInfo
from promptflow.storage._sqlite_client import INDEX, PRIMARY_KEY, SqliteClient


@dataclass
Expand All @@ -19,57 +18,9 @@ class CacheRecord:
end_time: datetime


@dataclass
class LocalCacheRecord:
"""To store in local db."""

run_id: str = field(metadata={PRIMARY_KEY: True})
hash_id: str = field(metadata={INDEX: True})
flow_run_id: str
flow_id: str
cache_string: str
end_time: datetime


class AbstractCacheStorage:
def get_cache_record_list(hash_id: str) -> CacheRecord:
pass

def persist_cache_result(run_info: RunInfo):
pass


class LocalCacheStorage(AbstractCacheStorage):
@classmethod
def create_tables(cls, db_folder_path: str, db_name: str, test_mode: bool = False):
"""Create db tables if not exists. If table exists, check if columns are consistent with associated class.
Note that this method involves disk io, it is not safe to be invoked concurrently.
"""
# Create table for local cache record.
SqliteClient.create_table_if_not_exists(db_folder_path, db_name, LocalCacheRecord, test_mode)

def __init__(self, db_folder_path: str, db_name: str, test_mode: bool = False):
"""Create table clients and create db tables if not exists.
This method should be invoked after create_tables.
After invoking create_tables, this method is safe to be invoked concurrently; otherwise it is not.
"""
self._sqlite_client = SqliteClient(
db_folder_path, db_name, LocalCacheRecord, in_memory=test_mode
) # If test mode, create sqlite db in memory.

def get_cache_record_list(self, hash_id: str) -> CacheRecord:
local_cache_list = self._sqlite_client.get_by_field(hash_id=hash_id)
return [CacheRecord(**asdict(c)) for c in local_cache_list]

def persist_cache_result(self, run_info: RunInfo, hash_id: str, cache_string: str, flow_id: str):
cache_record = LocalCacheRecord(
run_id=run_info.run_id,
hash_id=hash_id,
flow_run_id=run_info.flow_run_id,
flow_id=flow_id,
cache_string=cache_string,
end_time=run_info.end_time,
)
self._sqlite_client.insert(cache_record)
168 changes: 0 additions & 168 deletions src/promptflow/promptflow/storage/_sqlite_client.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/promptflow/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"openai>=0.27.8,<0.28.0", # promptflow.core.api_injector
"flask>=2.2.3,<3.0.0", # Serving endpoint requirements
"flask-restx>=1.2.0,<1.3.0", # Serving endpoint requirements
"dataset>=1.6.0,<2.0.0", # promptflow.storage
"sqlalchemy>=1.4.48,<2.0.0", # sqlite requirements
"sqlalchemy>=1.4.48,<3.0.0", # sqlite requirements
# note that pandas 1.5.3 is the only version to test in ci before promptflow 0.1.0b7 is released
# and pandas 2.x.x will be the only version to test in ci after that.
"pandas>=1.5.3,<3.0.0", # load data requirements
Expand Down

0 comments on commit 9781c60

Please sign in to comment.