From c4ca82b7a85dbcd121eb29247665df75618a373f Mon Sep 17 00:00:00 2001 From: SimFG Date: Wed, 1 Nov 2023 15:32:25 +0800 Subject: [PATCH] Add the disable report config Signed-off-by: SimFG --- .github/workflows/unit_test_main.yaml | 8 ++++---- examples/data_manager/scalar_store.py | 6 +++--- gptcache/adapter/adapter.py | 2 +- gptcache/config.py | 2 ++ tests/unit_tests/manager/test_weaviate.py | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unit_test_main.yaml b/.github/workflows/unit_test_main.yaml index e3d27d03..fee3eb01 100644 --- a/.github/workflows/unit_test_main.yaml +++ b/.github/workflows/unit_test_main.yaml @@ -93,21 +93,21 @@ jobs: export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python3 -m pytest -k "not embedding and not processor" --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/ - - name: Embedding Unit Tests + - name: Processor Unit Tests timeout-minutes: 30 shell: bash run: | export IS_CI=true export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - python3 -m pytest --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/unit_tests/embedding/ + python3 -m pytest --cov=gptcache --cov-append --cov-report xml:coverage.xml ./tests/unit_tests/processor/ - - name: Processor Unit Tests + - name: Embedding Unit Tests timeout-minutes: 30 shell: bash run: | export IS_CI=true export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - python3 -m pytest --cov=gptcache --cov-append --cov-report xml:coverage.xml ./tests/unit_tests/processor/ + python3 -m pytest --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/unit_tests/embedding/ - name: Upload coverage to Codecov uses: codecov/codecov-action@v3.1.0 diff --git a/examples/data_manager/scalar_store.py b/examples/data_manager/scalar_store.py index 01a20fda..c07a7ee6 100644 --- a/examples/data_manager/scalar_store.py +++ b/examples/data_manager/scalar_store.py @@ -1,15 +1,15 @@ import os + import numpy as np -from gptcache.adapter import openai from gptcache import cache +from gptcache.adapter import openai from gptcache.manager import get_data_manager, CacheBase, VectorBase from gptcache.similarity_evaluation.distance import SearchDistanceEvaluation - d = 8 - +# Change the embdding function to your own def mock_embeddings(data, **kwargs): return np.random.random((d, )).astype('float32') diff --git a/gptcache/adapter/adapter.py b/gptcache/adapter/adapter.py index 2121bd70..aaa279ea 100644 --- a/gptcache/adapter/adapter.py +++ b/gptcache/adapter/adapter.py @@ -206,7 +206,7 @@ def post_process(): chat_cache.data_manager.add_session( cache_whole_data[2], session.name, pre_embedding_data ) - if cache_whole_data: + if cache_whole_data and not chat_cache.config.disable_report: # user_question / cache_question / cache_question_id / cache_answer / similarity / consume time/ time report_cache_data = cache_whole_data[3] report_search_data = cache_whole_data[2] diff --git a/gptcache/config.py b/gptcache/config.py index aad2ef18..2c8fd2ad 100644 --- a/gptcache/config.py +++ b/gptcache/config.py @@ -46,6 +46,7 @@ def __init__( context_len: Optional[int] = None, skip_list: List[str] = None, data_check: bool = False, + disable_report: bool = False, ): if similarity_threshold < 0 or similarity_threshold > 1: raise CacheError( @@ -63,3 +64,4 @@ def __init__( skip_list = ["system", "assistant"] self.skip_list = skip_list self.data_check = data_check + self.disable_report = disable_report diff --git a/tests/unit_tests/manager/test_weaviate.py b/tests/unit_tests/manager/test_weaviate.py index 416f2eda..8b0754f6 100644 --- a/tests/unit_tests/manager/test_weaviate.py +++ b/tests/unit_tests/manager/test_weaviate.py @@ -26,7 +26,6 @@ def test_normal(self): db.mul_add([VectorData(id=size, data=data[0])]) ret = db.search(data[0]) self.assertIn(ret[0][1], [0, size]) - self.assertIn(ret[1][1], [0, size]) db.delete([0, 1, 2, 3, 4, 5, size]) ret = db.search(data[0]) self.assertNotIn(ret[0][1], [0, size])