Skip to content

Commit 1152ba9

Browse files
SimsonWjameszyao
authored andcommitted
ci: add workflow
1 parent 5865524 commit 1152ba9

File tree

15 files changed

+212
-83
lines changed

15 files changed

+212
-83
lines changed

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHAT_COMPLETION_MODEL_ID=TpHmCB8s
2+
3+
TASKINGAI_HOST=https://api.test199.com
4+
5+
TEXT_EMBEDDING_MODEL_ID=TpEZlEOK
6+
7+
TASKINGAI_API_KEY=taxy8i3OCfeJfh0eXW0h00cF2QT7nWyy

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Publish Package
2+
3+
on:
4+
push:
5+
tags: ["v*.*.*"]
6+
paths-ignore:
7+
- '**.md'
8+
- '**.svg'
9+
- '**.jpg'
10+
- '**.png'
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
environment: test
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v3
22+
23+
- name: Set short SHA
24+
run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV
25+
26+
- name: Check for git tag version
27+
id: get_tag
28+
run: |
29+
TAG=$(git describe --tags --exact-match 2> /dev/null || echo "")
30+
if [[ -n "$TAG" ]]; then
31+
echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV
32+
fi
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v2
36+
with:
37+
python-version: 3.x
38+
39+
- name: Install Dependencies
40+
run: pip install -r requirements.txt
41+
42+
- name: Run Version Verification
43+
run: |
44+
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!')"
45+
46+
47+
- name: Install Twine
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install twine
51+
52+
- name: Run Tests
53+
env:
54+
CLIENT_TEST_ENV: ${{ secrets.CLIENT_TEST_ENV }}
55+
run: |
56+
echo "$CLIENT_TEST_ENV" > .env
57+
bash ./test/run_test.sh
58+
59+
- name: Build Package
60+
run: python setup.py sdist bdist_wheel
61+
62+
- name: Publish Package
63+
run: twine upload dist/*
64+
env:
65+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
66+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
67+
68+
- name: Create Release
69+
uses: actions/create-release@v1
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
tag_name: ${{ env.IMAGE_TAG }}
74+
release_name: Release ${{ env.IMAGE_TAG }}
75+
body: |
76+
This is the release for version ${{ env.IMAGE_TAG }}.
77+
draft: false
78+
prerelease: false

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Run test
2+
3+
on:
4+
pull_request:
5+
branches: [ "master" ]
6+
paths-ignore:
7+
- '**.md'
8+
- '**.svg'
9+
- '**.jpg'
10+
- '**.png'
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
environment: test
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v3
22+
23+
- name: Set short SHA
24+
run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV
25+
26+
- name: Check for git tag version
27+
id: get_tag
28+
run: |
29+
TAG=$(git describe --tags --exact-match 2> /dev/null || echo "")
30+
if [[ -n "$TAG" ]]; then
31+
echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV
32+
fi
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v2
36+
with:
37+
python-version: 3.x
38+
39+
- name: Install Dependencies
40+
run: |
41+
pip install -r requirements.txt
42+
pip install -r test_requirements.txt
43+
44+
- name: Run Tests
45+
env:
46+
CLIENT_TEST_ENV: ${{ secrets.CLIENT_TEST_ENV }}
47+
run: |
48+
echo "$CLIENT_TEST_ENV" > .env
49+
bash ./test/run_test.sh

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ setuptools>=21.0.0
55
httpx>=0.23.0
66
pydantic>=2.5.0
77

8+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
url="https://www.tasking.ai",
2525
keywords=["TaskingAI", "LLM", "AI"],
2626
install_requires=REQUIRES,
27-
packages=find_packages(exclude=["test", "test.*"]),
27+
packages=find_packages(exclude=["test", "test.*", "examples", "examples.*"]),
2828
include_package_data=True,
2929
long_description=long_description,
3030
long_description_content_type="text/markdown",

taskingai/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__title__ = "taskingai"
2-
__version__ = "0.1.3"
2+
__version__ = "0.2.0"

test/config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import os
2+
from dotenv import load_dotenv
3+
import taskingai
4+
5+
load_dotenv()
26

37

48
class Config:
@@ -11,6 +15,14 @@ class Config:
1115
if not chat_completion_model_id:
1216
raise ValueError("chat_completion_model_id is not defined")
1317

14-
sleep_time = 1
18+
taskingai_host = os.environ.get("TASKINGAI_HOST")
19+
if not taskingai_host:
20+
raise ValueError("taskingai_host is not defined")
1521

22+
taskingai_apikey = os.environ.get("TASKINGAI_API_KEY")
23+
if not taskingai_apikey:
24+
raise ValueError("taskingai_apikey is not defined")
1625

26+
taskingai.init(api_key=taskingai_apikey, host=taskingai_host)
27+
28+
sleep_time = 1

test/run_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export PYTHONPATH="${PYTHONPATH}:${parent_dir}"
44

55
echo "Starting tests..."
66

7-
pytest -q --tb=no
7+
pytest ./test/testcase/test_sync
8+
sleep 5
9+
pytest ./test/testcase/test_async
810

911
echo "Tests completed."
1012

test/testcase/test_async/test_async_assistant.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,18 @@ async def test_a_delete_assistant(self):
113113

114114
assistants = await a_list_assistants(limit=100)
115115
old_nums = len(assistants)
116-
for i, v in enumerate(assistants):
116+
for index, v in enumerate(assistants):
117117
assistant_id = v.assistant_id
118118

119119
# Delete an assistant.
120120

121121
await a_delete_assistant(assistant_id=str(assistant_id))
122122

123123
# List assistants.
124-
125-
new_assistants = await a_list_assistants()
126-
assistant_ids = [j.assistant_id for j in new_assistants]
127-
pytest.assume(assistant_id not in assistant_ids)
128-
new_nums = len(new_assistants)
129-
pytest.assume(new_nums == old_nums - 1 - i)
124+
if index == old_nums - 1:
125+
new_assistants = await a_list_assistants()
126+
new_nums = len(new_assistants)
127+
pytest.assume(new_nums == 0)
130128

131129

132130
@pytest.mark.test_async
@@ -210,12 +208,10 @@ async def test_a_delete_chat(self):
210208
await a_delete_chat(assistant_id=self.assistant_id, chat_id=str(chat_id))
211209

212210
# List chats.
213-
214-
new_chats = await a_list_chats(assistant_id=self.assistant_id)
215-
chat_ids = [i.chat_id for i in new_chats]
216-
pytest.assume(chat_id not in chat_ids)
217-
new_nums = len(new_chats)
218-
pytest.assume(new_nums == old_nums - 1 - index)
211+
if index == old_nums - 1:
212+
new_chats = await a_list_chats(assistant_id=self.assistant_id)
213+
new_nums = len(new_chats)
214+
pytest.assume(new_nums == 0)
219215

220216

221217
@pytest.mark.test_async

test/testcase/test_async/test_async_retrieval.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ async def test_a_update_collection(self):
106106
async def test_a_delete_collection(self):
107107
# List collections.
108108
old_res = await a_list_collections(order="desc", limit=100, after=None, before=None)
109-
109+
old_nums = len(old_res)
110110
for index, collection in enumerate(old_res):
111111
collection_id = collection.collection_id
112112
# Delete a collection.
113113
await a_delete_collection(collection_id=collection_id)
114-
115-
new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None)
116-
# List collections.
117-
collection_ids = [c.collection_id for c in new_collections]
118-
pytest.assume(collection_id not in collection_ids)
114+
if index == old_nums - 1:
115+
new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None)
116+
# List collections.
117+
new_nums = len(new_collections)
118+
pytest.assume(new_nums == 0)
119119

120120

121121
@pytest.mark.test_async
@@ -234,13 +234,13 @@ async def test_a_delete_record(self):
234234
await a_delete_record(collection_id=self.collection_id, record_id=record_id)
235235

236236
# List records.
237-
238-
new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None,
239-
before=None)
240-
record_ids = [record.record_id for record in new_records]
241-
pytest.assume(record_id not in record_ids)
242-
new_nums = len(new_records)
243-
pytest.assume(new_nums == old_nums - 1 - index)
237+
if index == old_nums - 1:
238+
new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None,
239+
before=None)
240+
record_ids = [record.record_id for record in new_records]
241+
pytest.assume(record_id not in record_ids)
242+
new_nums = len(new_records)
243+
pytest.assume(new_nums == 0)
244244

245245

246246
@pytest.mark.test_async
@@ -352,9 +352,7 @@ async def test_delete_chunk(self):
352352
delete_chunk(collection_id=self.collection_id, chunk_id=chunk_id)
353353

354354
# List chunks.
355-
356-
new_chunks = list_chunks(collection_id=self.collection_id)
357-
chunk_ids = [chunk.chunk_id for chunk in new_chunks]
358-
pytest.assume(chunk_id not in chunk_ids)
359-
new_nums = len(new_chunks)
360-
pytest.assume(new_nums == old_nums - 1 - index)
355+
if index == old_nums-1:
356+
new_chunks = list_chunks(collection_id=self.collection_id)
357+
new_nums = len(new_chunks)
358+
pytest.assume(new_nums == 0)

test/testcase/test_async/test_async_tool.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,7 @@ async def test_a_delete_action(self):
214214
# Delete an action.
215215

216216
await a_delete_action(action_id=action_id)
217-
218-
new_actions = await a_list_actions()
219-
action_ids = [action.action_id for action in new_actions]
220-
pytest.assume(action_id not in action_ids)
221-
new_nums = len(new_actions)
222-
pytest.assume(new_nums == old_nums - 1 - index)
223-
224-
225-
226-
217+
if index == old_nums - 1:
218+
new_actions = await a_list_actions()
219+
new_nums = len(new_actions)
220+
pytest.assume(new_nums == 0)

test/testcase/test_sync/test_sync_assistant.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ def test_delete_assistant(self):
111111
delete_assistant(assistant_id=str(assistant_id))
112112

113113
# List assistants.
114-
115-
new_assistants = list_assistants()
116-
assistant_ids = [j.assistant_id for j in new_assistants]
117-
pytest.assume(assistant_id not in assistant_ids)
118-
new_nums = len(new_assistants)
119-
pytest.assume(new_nums == old_nums - 1 - i)
114+
if i == old_nums-1:
115+
new_assistants = list_assistants()
116+
new_nums = len(new_assistants)
117+
pytest.assume(new_nums == 0)
120118

121119

122120
@pytest.mark.test_sync
@@ -195,12 +193,10 @@ def test_delete_chat(self, assistant_id):
195193
delete_chat(assistant_id=assistant_id, chat_id=str(chat_id))
196194

197195
# List chats.
198-
199-
new_chats = list_chats(assistant_id=assistant_id)
200-
chat_ids = [i.chat_id for i in new_chats]
201-
pytest.assume(chat_id not in chat_ids)
202-
new_nums = len(new_chats)
203-
pytest.assume(new_nums == old_nums - 1 - index)
196+
if index == old_nums-1:
197+
new_chats = list_chats(assistant_id=assistant_id)
198+
new_nums = len(new_chats)
199+
pytest.assume(new_nums == 0)
204200

205201

206202
@pytest.mark.test_sync

test/testcase/test_sync/test_sync_retrieval.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ def test_delete_collection(self):
109109
# Delete a collection.
110110

111111
delete_collection(collection_id=collection_id)
112+
if index == old_nums-1:
113+
new_collections = list_collections(order="desc", limit=100, after=None, before=None)
112114

113-
new_collections = list_collections(order="desc", limit=100, after=None, before=None)
115+
# List collections.
114116

115-
# List collections.
116-
117-
collection_ids = [collection.collection_id for collection in new_collections]
118-
pytest.assume(collection_id not in collection_ids)
119-
new_nums = len(new_collections)
120-
pytest.assume(new_nums == old_nums - 1 - index)
117+
new_nums = len(new_collections)
118+
pytest.assume(new_nums == 0)
121119

122120

123121
@pytest.mark.test_sync
@@ -229,13 +227,12 @@ def test_delete_record(self, collection_id):
229227
delete_record(collection_id=collection_id, record_id=record_id)
230228

231229
# List records.
230+
if index == old_nums-1:
231+
new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None,
232+
before=None)
232233

233-
new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None,
234-
before=None)
235-
record_ids = [record.record_id for record in new_records]
236-
pytest.assume(record_id not in record_ids)
237-
new_nums = len(new_records)
238-
pytest.assume(new_nums == old_nums - 1 - index)
234+
new_nums = len(new_records)
235+
pytest.assume(new_nums == 0)
239236

240237

241238
@pytest.mark.test_sync
@@ -340,9 +337,7 @@ def test_delete_chunk(self, collection_id):
340337
delete_chunk(collection_id=collection_id, chunk_id=chunk_id)
341338

342339
# List chunks.
343-
344-
new_chunks = list_chunks(collection_id=collection_id)
345-
chunk_ids = [chunk.chunk_id for chunk in new_chunks]
346-
pytest.assume(chunk_id not in chunk_ids)
347-
new_nums = len(new_chunks)
348-
pytest.assume(new_nums == old_nums - 1 - index)
340+
if index == old_nums-1:
341+
new_chunks = list_chunks(collection_id=collection_id)
342+
new_nums = len(new_chunks)
343+
pytest.assume(new_nums == 0)

0 commit comments

Comments
 (0)