Skip to content

Commit cb5e8a8

Browse files
Create pytest actions for the package and the apps (camel-ai#92)
1 parent a3dbb5e commit cb5e8a8

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

.github/workflows/pytest_apps.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Pytest Gradio Apps
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
pytest_apps:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python 3.8
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.8"
26+
- uses: actions/cache@v3
27+
id: cache
28+
with:
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install flake8 pytest
37+
pip install gradio
38+
pip install -e .
39+
- name: Test with pytest
40+
env:
41+
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
42+
run: |
43+
pytest apps/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Pytest Camel package
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
pytest_package:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python 3.8
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.8"
26+
- uses: actions/cache@v3
27+
id: cache
28+
with:
29+
path: ~/.cache/pip
30+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install flake8 pytest
37+
pip install -e .
38+
- name: Test with pytest
39+
env:
40+
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
41+
run: |
42+
pytest test/

apps/data_explorer/data_explorer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def parse_arguments():
2222
help='Default dataset name selected from ZIPs')
2323
parser.add_argument('--share', type=bool, default=False,
2424
help='Expose the web UI to Gradio')
25+
parser.add_argument(
26+
'--server-name', type=str, default="0.0.0.0",
27+
help='localhost for local, 0.0.0.0 (default) for public')
2528
parser.add_argument('--server-port', type=int, default=8080,
2629
help='Port ot run the web page on')
2730
parser.add_argument('--inbrowser', type=bool, default=False,
@@ -323,7 +326,7 @@ def main():
323326

324327
blocks.queue(args.concurrency_count) \
325328
.launch(share=args.share, inbrowser=args.inbrowser,
326-
server_name="0.0.0.0", server_port=args.server_port)
329+
server_name=args.server_name, server_port=args.server_port)
327330

328331
print("Exiting.")
329332

apps/data_explorer/downloader.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import urllib.request
3+
4+
from huggingface_hub import hf_hub_download
5+
from huggingface_hub.utils._errors import RepositoryNotFoundError
6+
7+
REPO_ROOT = os.path.realpath(
8+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
9+
10+
11+
def download_data():
12+
13+
print("Downloading...")
14+
15+
data_dir = os.path.join(REPO_ROOT, "datasets/")
16+
17+
os.makedirs(data_dir, exist_ok=True)
18+
19+
try:
20+
hf_hub_download(repo_id="camel-ai/ai_society", repo_type="dataset",
21+
filename="ai_society_chat.zip", local_dir=data_dir,
22+
local_dir_use_symlinks=False)
23+
24+
hf_hub_download(repo_id="camel-ai/code", repo_type="dataset",
25+
filename="code_chat.zip", local_dir=data_dir,
26+
local_dir_use_symlinks=False)
27+
except RepositoryNotFoundError:
28+
for name in ("ai_society_chat.zip", "code_chat.zip"):
29+
data_url = ("https://storage.googleapis.com/"
30+
f"camel-bucket/datasets/private/{name}")
31+
file_path = os.path.join(data_dir, os.path.split(data_url)[1])
32+
urllib.request.urlretrieve(data_url, file_path)
33+
34+
data_url = ("https://storage.googleapis.com/"
35+
"camel-bucket/datasets/private/misalignment.zip")
36+
file_path = os.path.join(data_dir, os.path.split(data_url)[1])
37+
urllib.request.urlretrieve(data_url, file_path)
38+
39+
print("Download done")
40+
41+
42+
if __name__ == "__main__":
43+
download_data()

0 commit comments

Comments
 (0)