From 33c1e716d84ed1443e1fd922fc19ecfec0915dd3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 09:16:27 -0700 Subject: [PATCH 1/5] chore(deps): bump jinja2 from 3.1.3 to 3.1.4 in /.kokoro (#62) Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.3 to 3.1.4. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/3.1.3...3.1.4) --- updated-dependencies: - dependency-name: jinja2 dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .kokoro/requirements.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.kokoro/requirements.txt b/.kokoro/requirements.txt index c2ce28d..1b2d154 100644 --- a/.kokoro/requirements.txt +++ b/.kokoro/requirements.txt @@ -273,10 +273,12 @@ jaraco-classes==3.3.1 \ jeepney==0.8.0 \ --hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \ --hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755 - # via secretstorage -jinja2==3.1.3 \ - --hash=sha256:7d6d50dd97d52cbc355597bd845fabfbac3f551e1f99619e39a35ce8c370b5fa \ - --hash=sha256:ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90 + # via + # keyring + # secretstorage +jinja2==3.1.4 \ + --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ + --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d # via gcp-releasetool keyring==24.3.1 \ --hash=sha256:c3327b6ffafc0e8befbdb597cacdb4928ffe5c1212f7645f186e6d9957a898db \ @@ -479,7 +481,9 @@ rsa==4.9 \ secretstorage==3.3.3 \ --hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \ --hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99 - # via -r requirements.in + # via + # -r requirements.in + # keyring six==1.16.0 \ --hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \ --hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 From 27c361c2551479f7def81cb182c7fe29534c07a7 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Thu, 9 May 2024 14:36:04 -0700 Subject: [PATCH 2/5] fix: Fix broken link in README.rst (#63) --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 77225bc..bcf4bef 100644 --- a/README.rst +++ b/README.rst @@ -85,7 +85,7 @@ Use a vector store to store embedded data and perform vector search. See the full `Vector Store`_ tutorial. -.. _`Vector Store`: https://github.com/googleapis/langchain-google-firestore-python/blob/main/docs/vector_store.ipynb +.. _`Vector Store`: https://github.com/googleapis/langchain-google-firestore-python/blob/main/docs/vectorstores.ipynb Document Loader Usage ~~~~~~~~~~~~~~~~~~~~~ From 9b10d7abb0d6009ca9997ce25a162d7a42065188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Fabricio=20Urbina=20Gonz=C3=A1lez?= Date: Tue, 14 May 2024 20:03:11 +0000 Subject: [PATCH 3/5] feat: Optional message encoding. (#65) * feat:optional message encoding. * feat: Optional message encoding. * fix: format file. * fix: type encoding for chat message. --- .../chat_message_history.py | 21 ++++++++++++++---- tests/test_chat_message_history.py | 22 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/langchain_google_firestore/chat_message_history.py b/src/langchain_google_firestore/chat_message_history.py index 79b5f3d..f0e2e18 100644 --- a/src/langchain_google_firestore/chat_message_history.py +++ b/src/langchain_google_firestore/chat_message_history.py @@ -37,6 +37,7 @@ def __init__( session_id: str, collection: str = DEFAULT_COLLECTION, client: Optional[Client] = None, + encode_message: bool = True, ) -> None: """Chat Message History for Google Cloud Firestore. @@ -45,7 +46,9 @@ def __init__( chat session. This is the document_path of a document. collection: The single `/`-delimited path to a Firestore collection. client: Client for interacting with the Google Cloud Firestore API. + encode_message: Encode the message when storing into Firestore. """ + self.encode_message = encode_message self.client = client_with_user_agent(USER_AGENT, client) self.session_id = session_id self.doc_ref = self.client.collection(collection).document(session_id) @@ -57,14 +60,19 @@ def _load_messages(self) -> None: if doc.exists: data_messages = doc.to_dict() if "messages" in data_messages: - self.messages = decode_messages(data_messages["messages"]) + self.messages = convert_messages_to_langchain( + self.encode_message, data_messages["messages"] + ) def add_message(self, message: BaseMessage) -> None: self.messages.append(message) self._upsert_messages() def _upsert_messages(self) -> None: - self.doc_ref.set({"messages": encode_messages(self.messages)}) + if self.encode_message: + self.doc_ref.set({"messages": encode_messages(self.messages)}) + else: + self.doc_ref.set({"messages": [m.json() for m in self.messages]}) def clear(self) -> None: self.messages = [] @@ -75,6 +83,11 @@ def encode_messages(messages: List[BaseMessage]) -> List[bytes]: return [str.encode(m.json()) for m in messages] -def decode_messages(messages: List[bytes]) -> List[BaseMessage]: - dict_messages = [json.loads(m.decode()) for m in messages] +def convert_messages_to_langchain( + is_encoded: bool, messages: List[bytes] +) -> List[BaseMessage]: + if is_encoded: + dict_messages = [json.loads(m.decode()) for m in messages] + else: + dict_messages = [json.loads(m) for m in messages] return messages_from_dict([{"type": m["type"], "data": m} for m in dict_messages]) diff --git a/tests/test_chat_message_history.py b/tests/test_chat_message_history.py index 941d082..503fd00 100644 --- a/tests/test_chat_message_history.py +++ b/tests/test_chat_message_history.py @@ -51,6 +51,28 @@ def test_firestore_history_workflow(test_case: TestCase) -> None: assert len(chat_history.messages) == 0 +def test_firestore_without_encoding_workflow(test_case: TestCase) -> None: + session_id = uuid.uuid4().hex + chat_history = FirestoreChatMessageHistory( + session_id=session_id, + collection="HistoryWorkflow", + encode_message=False, + ) + chat_history.add_user_message("User message") + + expected_messages = [ + HumanMessage(content="User message"), + ] + chat_history._load_messages() + + test_case.assertCountEqual(expected_messages, chat_history.messages) + + chat_history.clear() + chat_history._load_messages() + + assert len(chat_history.messages) == 0 + + def test_firestore_load_messages(test_case: TestCase) -> None: NUM_MESSAGES = 25 session_id = uuid.uuid4().hex From 2cdb70255687cc5d13fb45191aa568a294ff4d17 Mon Sep 17 00:00:00 2001 From: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> Date: Thu, 16 May 2024 12:36:37 -0400 Subject: [PATCH 4/5] ci: Add code coverage check (#66) * ci: Add code coverage check * increase cc to 90 * fix typo --- .coveragerc | 8 ++++++++ DEVELOPER.md | 14 +++++++++++++- integration.cloudbuild.yaml | 2 +- pyproject.toml | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..2c634d5 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,8 @@ +[run] +branch = true +omit = + */__init__.py + +[report] +show_missing = true +fail_under = 90 \ No newline at end of file diff --git a/DEVELOPER.md b/DEVELOPER.md index fefafde..b0d6517 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -53,7 +53,7 @@ substitutions: _VERSION: "3.8" ``` -Use `gcloud builds triggers import --source=trigger.yaml` create triggers via the command line +Use `gcloud builds triggers import --source=trigger.yaml` to create triggers via the command line #### Project Setup @@ -72,5 +72,17 @@ Use `gcloud builds triggers import --source=trigger.yaml` create triggers via th To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: `/gcbrun`. +#### Code Coverage +Please make sure your code is fully tested. The Cloud Build integration tests are run with the `pytest-cov` code coverage plugin. They fail for PRs with a code coverage less than the threshold specified in `.coveragerc`. If your file is inside the main module and should be ignored by code coverage check, add it to the `omit` section of `.coveragerc`. + +Check for code coverage report in any Cloud Build integration test log. +Here is a breakdown of the report: +- `Stmts`: lines of executable code (statements). +- `Miss`: number of lines not covered by tests. +- `Branch`: branches of executable code (e.g an if-else clause may count as 1 statement but 2 branches; test for both conditions to have both branches covered). +- `BrPart`: number of branches not covered by tests. +- `Cover`: average coverage of files. +- `Missing`: lines that are not covered by tests. + [triggers]: https://console.cloud.google.com/cloud-build/triggers?e=13802955&project=langchain-firestore-testing \ No newline at end of file diff --git a/integration.cloudbuild.yaml b/integration.cloudbuild.yaml index 33ece04..05ebcbd 100644 --- a/integration.cloudbuild.yaml +++ b/integration.cloudbuild.yaml @@ -26,7 +26,7 @@ steps: - id: Run integration tests name: python:${_VERSION} entrypoint: python - args: ["-m", "pytest"] + args: ["-m", "pytest", "--cov=langchain_google_firestore", "--cov-config=.coveragerc", "tests/"] substitutions: _VERSION: "3.8" diff --git a/pyproject.toml b/pyproject.toml index eda02eb..4ccf6d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,8 @@ test = [ "isort==5.13.2", "mypy==1.10.0", "pytest-asyncio==0.23.6", - "pytest==7.4.4" + "pytest==7.4.4", + "pytest-cov==5.0.0" ] [build-system] From 07c8e896edd2d5041d9c03f4ab5e1a402a2e723c Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 13:20:09 -0700 Subject: [PATCH 5/5] chore(main): release 0.3.0 (#64) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ src/langchain_google_firestore/version.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0010a6..9b950a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [0.3.0](https://github.com/googleapis/langchain-google-firestore-python/compare/v0.2.1...v0.3.0) (2024-05-16) + + +### Features + +* Optional message encoding. ([#65](https://github.com/googleapis/langchain-google-firestore-python/issues/65)) ([9b10d7a](https://github.com/googleapis/langchain-google-firestore-python/commit/9b10d7abb0d6009ca9997ce25a162d7a42065188)) + + +### Bug Fixes + +* Fix broken link in README.rst ([#63](https://github.com/googleapis/langchain-google-firestore-python/issues/63)) ([27c361c](https://github.com/googleapis/langchain-google-firestore-python/commit/27c361c2551479f7def81cb182c7fe29534c07a7)) + ## [0.2.1](https://github.com/googleapis/langchain-google-firestore-python/compare/v0.2.0...v0.2.1) (2024-05-01) diff --git a/src/langchain_google_firestore/version.py b/src/langchain_google_firestore/version.py index fffa9d9..2b5d97a 100644 --- a/src/langchain_google_firestore/version.py +++ b/src/langchain_google_firestore/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.2.1" +__version__ = "0.3.0"