Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Create pytest actions for the package and the apps (#92)

Dmitrii Khizbullincb5e8a8c102b
diff --git a/.github/workflows/pytest_apps.yml b/.github/workflows/pytest_apps.yml
new file mode 100644
index 000000000..8839ace1a
--- /dev/null
+++ b/.github/workflows/pytest_apps.yml
@@ -0,0 +1,43 @@
+# This workflow will install Python dependencies, run tests and lint with a single version of Python
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
+
+name: Pytest Gradio Apps
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+permissions:
+ contents: read
+
+jobs:
+ pytest_apps:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python 3.8
+ uses: actions/setup-python@v3
+ with:
+ python-version: "3.8"
+ - uses: actions/cache@v3
+ id: cache
+ with:
+ path: ~/.cache/pip
+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
+ restore-keys: |
+ ${{ runner.os }}-pip-
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install flake8 pytest
+ pip install gradio
+ pip install -e .
+ - name: Test with pytest
+ env:
+ OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
+ run: |
+ pytest apps/
diff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.yml
new file mode 100644
index 000000000..8a41856aa
--- /dev/null
+++ b/.github/workflows/pytest_package.yml
@@ -0,0 +1,42 @@
+# This workflow will install Python dependencies, run tests and lint with a single version of Python
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
+
+name: Pytest Camel package
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+permissions:
+ contents: read
+
+jobs:
+ pytest_package:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python 3.8
+ uses: actions/setup-python@v3
+ with:
+ python-version: "3.8"
+ - uses: actions/cache@v3
+ id: cache
+ with:
+ path: ~/.cache/pip
+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
+ restore-keys: |
+ ${{ runner.os }}-pip-
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install flake8 pytest
+ pip install -e .
+ - name: Test with pytest
+ env:
+ OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
+ run: |
+ pytest test/
diff --git a/apps/data_explorer/data_explorer.py b/apps/data_explorer/data_explorer.py
index 069ef6d9d..bcc6f7ef5 100644
--- a/apps/data_explorer/data_explorer.py
+++ b/apps/data_explorer/data_explorer.py
@@ -22,6 +22,9 @@ def parse_arguments():
help='Default dataset name selected from ZIPs')
parser.add_argument('--share', type=bool, default=False,
help='Expose the web UI to Gradio')
+ parser.add_argument(
+ '--server-name', type=str, default="0.0.0.0",
+ help='localhost for local, 0.0.0.0 (default) for public')
parser.add_argument('--server-port', type=int, default=8080,
help='Port ot run the web page on')
parser.add_argument('--inbrowser', type=bool, default=False,
@@ -323,7 +326,7 @@ def main():
blocks.queue(args.concurrency_count) \
.launch(share=args.share, inbrowser=args.inbrowser,
- server_name="0.0.0.0", server_port=args.server_port)
+ server_name=args.server_name, server_port=args.server_port)
print("Exiting.")
diff --git a/apps/data_explorer/downloader.py b/apps/data_explorer/downloader.py
new file mode 100644
index 000000000..f155d85ce
--- /dev/null
+++ b/apps/data_explorer/downloader.py
@@ -0,0 +1,43 @@
+import os
+import urllib.request
+
+from huggingface_hub import hf_hub_download
+from huggingface_hub.utils._errors import RepositoryNotFoundError
+
+REPO_ROOT = os.path.realpath(
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
+
+
+def download_data():
+
+ print("Downloading...")
+
+ data_dir = os.path.join(REPO_ROOT, "datasets/")
+
+ os.makedirs(data_dir, exist_ok=True)
+
+ try:
+ hf_hub_download(repo_id="camel-ai/ai_society", repo_type="dataset",
+ filename="ai_society_chat.zip", local_dir=data_dir,
+ local_dir_use_symlinks=False)
+
+ hf_hub_download(repo_id="camel-ai/code", repo_type="dataset",
+ filename="code_chat.zip", local_dir=data_dir,
+ local_dir_use_symlinks=False)
+ except RepositoryNotFoundError:
+ for name in ("ai_society_chat.zip", "code_chat.zip"):
+ data_url = ("https://storage.googleapis.com/"
+ f"camel-bucket/datasets/private/{name}")
+ file_path = os.path.join(data_dir, os.path.split(data_url)[1])
+ urllib.request.urlretrieve(data_url, file_path)
+
+ data_url = ("https://storage.googleapis.com/"
+ "camel-bucket/datasets/private/misalignment.zip")
+ file_path = os.path.join(data_dir, os.path.split(data_url)[1])
+ urllib.request.urlretrieve(data_url, file_path)
+
+ print("Download done")
+
+
+if __name__ == "__main__":
+ download_data()