diff --git a/.env b/.env new file mode 100644 index 0000000..dcbcd97 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +CHAT_COMPLETION_MODEL_ID=TpHmCB8s + +TASKINGAI_HOST=https://api.test199.com + +TEXT_EMBEDDING_MODEL_ID=TpEZlEOK + +TASKINGAI_API_KEY=taxy8i3OCfeJfh0eXW0h00cF2QT7nWyy \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d5fe404 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,78 @@ +name: Publish Package + +on: + push: + tags: ["v*.*.*"] + paths-ignore: + - '**.md' + - '**.svg' + - '**.jpg' + - '**.png' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + environment: test + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set short SHA + run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV + + - name: Check for git tag version + id: get_tag + run: | + TAG=$(git describe --tags --exact-match 2> /dev/null || echo "") + if [[ -n "$TAG" ]]; then + echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV + fi + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install Dependencies + run: pip install -r requirements.txt + + - name: Run Version Verification + run: | + python -c "from config import CONFIG; import os; current_tag = os.getenv('IMAGE_TAG'); assert CONFIG.VERSION == current_tag, 'Version mismatch: Expected {} but got {}'.format(CONFIG.VERSION, current_tag); print('Version matched!')" + + + - name: Install Twine + run: | + python -m pip install --upgrade pip + pip install twine + + - name: Run Tests + env: + CLIENT_TEST_ENV: ${{ secrets.CLIENT_TEST_ENV }} + run: | + echo "$CLIENT_TEST_ENV" > .env + bash ./test/run_test.sh + + - name: Build Package + run: python setup.py sdist bdist_wheel + + - name: Publish Package + run: twine upload dist/* + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.IMAGE_TAG }} + release_name: Release ${{ env.IMAGE_TAG }} + body: | + This is the release for version ${{ env.IMAGE_TAG }}. + draft: false + prerelease: false \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3403490 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,49 @@ +name: Run test + +on: + pull_request: + branches: [ "master" ] + paths-ignore: + - '**.md' + - '**.svg' + - '**.jpg' + - '**.png' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + environment: test + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set short SHA + run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV + + - name: Check for git tag version + id: get_tag + run: | + TAG=$(git describe --tags --exact-match 2> /dev/null || echo "") + if [[ -n "$TAG" ]]; then + echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV + fi + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install Dependencies + run: | + pip install -r requirements.txt + pip install -r test_requirements.txt + + - name: Run Tests + env: + CLIENT_TEST_ENV: ${{ secrets.CLIENT_TEST_ENV }} + run: | + echo "$CLIENT_TEST_ENV" > .env + bash ./test/run_test.sh diff --git a/requirements.txt b/requirements.txt index 05ff7e9..314bff1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ setuptools>=21.0.0 httpx>=0.23.0 pydantic>=2.5.0 + diff --git a/setup.py b/setup.py index 8c47448..e7367d8 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ url="https://www.tasking.ai", keywords=["TaskingAI", "LLM", "AI"], install_requires=REQUIRES, - packages=find_packages(exclude=["test", "test.*"]), + packages=find_packages(exclude=["test", "test.*", "examples", "examples.*"]), include_package_data=True, long_description=long_description, long_description_content_type="text/markdown", diff --git a/taskingai/_version.py b/taskingai/_version.py index cf38cb1..2e42793 100644 --- a/taskingai/_version.py +++ b/taskingai/_version.py @@ -1,2 +1,2 @@ __title__ = "taskingai" -__version__ = "0.1.3" +__version__ = "0.2.0" diff --git a/test/config.py b/test/config.py index d09f5db..96b51ad 100644 --- a/test/config.py +++ b/test/config.py @@ -1,4 +1,8 @@ import os +from dotenv import load_dotenv +import taskingai + +load_dotenv() class Config: @@ -11,6 +15,14 @@ class Config: if not chat_completion_model_id: raise ValueError("chat_completion_model_id is not defined") - sleep_time = 1 + taskingai_host = os.environ.get("TASKINGAI_HOST") + if not taskingai_host: + raise ValueError("taskingai_host is not defined") + taskingai_apikey = os.environ.get("TASKINGAI_API_KEY") + if not taskingai_apikey: + raise ValueError("taskingai_apikey is not defined") + taskingai.init(api_key=taskingai_apikey, host=taskingai_host) + + sleep_time = 1 diff --git a/test/run_test.sh b/test/run_test.sh index 43f8608..0c1a3fc 100644 --- a/test/run_test.sh +++ b/test/run_test.sh @@ -4,7 +4,9 @@ export PYTHONPATH="${PYTHONPATH}:${parent_dir}" echo "Starting tests..." -pytest -q --tb=no +pytest ./test/testcase/test_sync +sleep 5 +pytest ./test/testcase/test_async echo "Tests completed." diff --git a/test/testcase/test_async/test_async_assistant.py b/test/testcase/test_async/test_async_assistant.py index bd42833..c28249d 100644 --- a/test/testcase/test_async/test_async_assistant.py +++ b/test/testcase/test_async/test_async_assistant.py @@ -113,7 +113,7 @@ async def test_a_delete_assistant(self): assistants = await a_list_assistants(limit=100) old_nums = len(assistants) - for i, v in enumerate(assistants): + for index, v in enumerate(assistants): assistant_id = v.assistant_id # Delete an assistant. @@ -121,12 +121,10 @@ async def test_a_delete_assistant(self): await a_delete_assistant(assistant_id=str(assistant_id)) # List assistants. - - new_assistants = await a_list_assistants() - assistant_ids = [j.assistant_id for j in new_assistants] - pytest.assume(assistant_id not in assistant_ids) - new_nums = len(new_assistants) - pytest.assume(new_nums == old_nums - 1 - i) + if index == old_nums - 1: + new_assistants = await a_list_assistants() + new_nums = len(new_assistants) + pytest.assume(new_nums == 0) @pytest.mark.test_async @@ -210,12 +208,10 @@ async def test_a_delete_chat(self): await a_delete_chat(assistant_id=self.assistant_id, chat_id=str(chat_id)) # List chats. - - new_chats = await a_list_chats(assistant_id=self.assistant_id) - chat_ids = [i.chat_id for i in new_chats] - pytest.assume(chat_id not in chat_ids) - new_nums = len(new_chats) - pytest.assume(new_nums == old_nums - 1 - index) + if index == old_nums - 1: + new_chats = await a_list_chats(assistant_id=self.assistant_id) + new_nums = len(new_chats) + pytest.assume(new_nums == 0) @pytest.mark.test_async diff --git a/test/testcase/test_async/test_async_retrieval.py b/test/testcase/test_async/test_async_retrieval.py index 6ab4dae..5dea9a2 100644 --- a/test/testcase/test_async/test_async_retrieval.py +++ b/test/testcase/test_async/test_async_retrieval.py @@ -106,16 +106,16 @@ async def test_a_update_collection(self): async def test_a_delete_collection(self): # List collections. old_res = await a_list_collections(order="desc", limit=100, after=None, before=None) - + old_nums = len(old_res) for index, collection in enumerate(old_res): collection_id = collection.collection_id # Delete a collection. await a_delete_collection(collection_id=collection_id) - - new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None) - # List collections. - collection_ids = [c.collection_id for c in new_collections] - pytest.assume(collection_id not in collection_ids) + if index == old_nums - 1: + new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None) + # List collections. + new_nums = len(new_collections) + pytest.assume(new_nums == 0) @pytest.mark.test_async @@ -234,13 +234,13 @@ async def test_a_delete_record(self): await a_delete_record(collection_id=self.collection_id, record_id=record_id) # List records. - - new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None, - before=None) - record_ids = [record.record_id for record in new_records] - pytest.assume(record_id not in record_ids) - new_nums = len(new_records) - pytest.assume(new_nums == old_nums - 1 - index) + if index == old_nums - 1: + new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None, + before=None) + record_ids = [record.record_id for record in new_records] + pytest.assume(record_id not in record_ids) + new_nums = len(new_records) + pytest.assume(new_nums == 0) @pytest.mark.test_async @@ -352,9 +352,7 @@ async def test_delete_chunk(self): delete_chunk(collection_id=self.collection_id, chunk_id=chunk_id) # List chunks. - - new_chunks = list_chunks(collection_id=self.collection_id) - chunk_ids = [chunk.chunk_id for chunk in new_chunks] - pytest.assume(chunk_id not in chunk_ids) - new_nums = len(new_chunks) - pytest.assume(new_nums == old_nums - 1 - index) + if index == old_nums-1: + new_chunks = list_chunks(collection_id=self.collection_id) + new_nums = len(new_chunks) + pytest.assume(new_nums == 0) diff --git a/test/testcase/test_async/test_async_tool.py b/test/testcase/test_async/test_async_tool.py index 7428d97..8842e58 100644 --- a/test/testcase/test_async/test_async_tool.py +++ b/test/testcase/test_async/test_async_tool.py @@ -214,13 +214,7 @@ async def test_a_delete_action(self): # Delete an action. await a_delete_action(action_id=action_id) - - new_actions = await a_list_actions() - action_ids = [action.action_id for action in new_actions] - pytest.assume(action_id not in action_ids) - new_nums = len(new_actions) - pytest.assume(new_nums == old_nums - 1 - index) - - - - + if index == old_nums - 1: + new_actions = await a_list_actions() + new_nums = len(new_actions) + pytest.assume(new_nums == 0) diff --git a/test/testcase/test_sync/test_sync_assistant.py b/test/testcase/test_sync/test_sync_assistant.py index dde7382..4dc2dc4 100644 --- a/test/testcase/test_sync/test_sync_assistant.py +++ b/test/testcase/test_sync/test_sync_assistant.py @@ -111,12 +111,10 @@ def test_delete_assistant(self): delete_assistant(assistant_id=str(assistant_id)) # List assistants. - - new_assistants = list_assistants() - assistant_ids = [j.assistant_id for j in new_assistants] - pytest.assume(assistant_id not in assistant_ids) - new_nums = len(new_assistants) - pytest.assume(new_nums == old_nums - 1 - i) + if i == old_nums-1: + new_assistants = list_assistants() + new_nums = len(new_assistants) + pytest.assume(new_nums == 0) @pytest.mark.test_sync @@ -195,12 +193,10 @@ def test_delete_chat(self, assistant_id): delete_chat(assistant_id=assistant_id, chat_id=str(chat_id)) # List chats. - - new_chats = list_chats(assistant_id=assistant_id) - chat_ids = [i.chat_id for i in new_chats] - pytest.assume(chat_id not in chat_ids) - new_nums = len(new_chats) - pytest.assume(new_nums == old_nums - 1 - index) + if index == old_nums-1: + new_chats = list_chats(assistant_id=assistant_id) + new_nums = len(new_chats) + pytest.assume(new_nums == 0) @pytest.mark.test_sync diff --git a/test/testcase/test_sync/test_sync_retrieval.py b/test/testcase/test_sync/test_sync_retrieval.py index d2e4b81..ec50689 100644 --- a/test/testcase/test_sync/test_sync_retrieval.py +++ b/test/testcase/test_sync/test_sync_retrieval.py @@ -109,15 +109,13 @@ def test_delete_collection(self): # Delete a collection. delete_collection(collection_id=collection_id) + if index == old_nums-1: + new_collections = list_collections(order="desc", limit=100, after=None, before=None) - new_collections = list_collections(order="desc", limit=100, after=None, before=None) + # List collections. - # List collections. - - collection_ids = [collection.collection_id for collection in new_collections] - pytest.assume(collection_id not in collection_ids) - new_nums = len(new_collections) - pytest.assume(new_nums == old_nums - 1 - index) + new_nums = len(new_collections) + pytest.assume(new_nums == 0) @pytest.mark.test_sync @@ -229,13 +227,12 @@ def test_delete_record(self, collection_id): delete_record(collection_id=collection_id, record_id=record_id) # List records. + if index == old_nums-1: + new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None, + before=None) - new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None, - before=None) - record_ids = [record.record_id for record in new_records] - pytest.assume(record_id not in record_ids) - new_nums = len(new_records) - pytest.assume(new_nums == old_nums - 1 - index) + new_nums = len(new_records) + pytest.assume(new_nums == 0) @pytest.mark.test_sync @@ -340,9 +337,7 @@ def test_delete_chunk(self, collection_id): delete_chunk(collection_id=collection_id, chunk_id=chunk_id) # List chunks. - - new_chunks = list_chunks(collection_id=collection_id) - chunk_ids = [chunk.chunk_id for chunk in new_chunks] - pytest.assume(chunk_id not in chunk_ids) - new_nums = len(new_chunks) - pytest.assume(new_nums == old_nums - 1 - index) + if index == old_nums-1: + new_chunks = list_chunks(collection_id=collection_id) + new_nums = len(new_chunks) + pytest.assume(new_nums == 0) diff --git a/test/testcase/test_sync/test_sync_tool.py b/test/testcase/test_sync/test_sync_tool.py index 936b34a..0d0ad44 100644 --- a/test/testcase/test_sync/test_sync_tool.py +++ b/test/testcase/test_sync/test_sync_tool.py @@ -207,8 +207,8 @@ def test_delete_action(self): # Delete an action. delete_action(action_id=action_id) - new_actions = list_actions(limit=100) - action_ids = [action.action_id for action in new_actions] - pytest.assume(action_id not in action_ids) - new_nums = len(new_actions) - pytest.assume(new_nums == old_nums - 1 - index) + + if index == old_nums-1: + new_actions = list_actions(limit=100) + new_nums = len(new_actions) + pytest.assume(new_nums == 0) diff --git a/test-requirements.txt b/test_requirements.txt similarity index 88% rename from test-requirements.txt rename to test_requirements.txt index 1dbb6ee..33c955e 100644 --- a/test-requirements.txt +++ b/test_requirements.txt @@ -14,4 +14,5 @@ asyncio==3.4.3 pytest-tornasync>=0.6.0 pytest-trio==0.8.0 pytest-twisted==1.14.0 -Twisted==24.3.0 \ No newline at end of file +Twisted==24.3.0 +python-dotenv==1.0.0 \ No newline at end of file