Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ProKil committed Oct 12, 2024
2 parents 12e74a6 + 88fc3a3 commit 8606b17
Show file tree
Hide file tree
Showing 69 changed files with 7,522 additions and 6,525 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bullseye

RUN pip install uv\
&& uv venv /workspaces/.venv\
&& export UV_PROJECT_ENVIRONMENT=/workspaces/.venv\
&& echo export UV_PROJECT_ENVIRONMENT=/workspaces/.venv >> /root/.bashrc
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile.llamacpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ghcr.io/ggerganov/llama.cpp:server

# Install curl and other necessary utilities
RUN apt-get update && \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/* && \
curl -L https://huggingface.co/unsloth/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q8_0.gguf --output Llama-3.2.gguf

CMD ["-m", "Llama-3.2.gguf", "--port", "8000"]
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Sotopia Place",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile

"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "uv sync --all-extras",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
31 changes: 31 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
devcontainer:
build:
context: .
dockerfile: Dockerfile
depends_on:
llamacpp:
condition: service_started
redis:
condition: service_healthy
volumes:
- ../..:/workspaces:cached
command: sleep infinity
network_mode: "host"

llamacpp:
build:
context: .
dockerfile: Dockerfile.llamacpp
container_name: llamacpp
network_mode: "host"

redis:
image: redis/redis-stack-server:latest
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
network_mode: "host"

networks:
sotopia:
external: false
16 changes: 6 additions & 10 deletions .github/workflows/tests.yml → .github/workflows/cli_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pytest
name: Pytest (Installation)

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -10,7 +10,7 @@ on:
- main
- release
- dev
pull_request_target:
pull_request:
branches:
- main
- release
Expand All @@ -34,18 +34,14 @@ jobs:
if: runner.os == 'ubuntu-latest'
uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: |
poetry install --with test -E chat
python -m pip install --upgrade pip
python -m pip install uv
uv sync --extra test --extra chat
- name: Test with pytest
env: # Or as an environment variable
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
REDIS_OM_URL: ${{ secrets.REDIS_OM_URL }}
TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }}
run: |
poetry run pytest --cov=. --cov-report=xml
uv run pytest tests/cli/test_install.py --cov=. --cov-report=xml
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4.0.1
with:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ jobs:
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3
poetry install --with test -E chat
python -m pip install --upgrade pip
python -m pip install uv
uv sync --extra test --extra chat
- name: Type-checking package with mypy
run: |
# Run this mypy instance against our main package.
poetry run pip install types-protobuf==4.24.0.4
poetry run mypy --install-types --non-interactive sotopia
poetry run mypy --install-types --non-interactive sotopia-chat
poetry run mypy --strict .
uv run mypy --strict .
12 changes: 5 additions & 7 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ jobs:
python-version: 3.11.2
- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3
- name: Get release version
run: echo "RELEASE_VERSION=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
python -m pip install --upgrade pip
python -m pip install uv
- name: Build and publish Python package
run: poetry publish --build
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: |
uv build
uv publish
1 change: 1 addition & 0 deletions .github/workflows/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uv run --extra test --extra chat pytest --ignore tests/cli --cov=. --cov-report=xml
35 changes: 35 additions & 0 deletions .github/workflows/tests_in_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Pytest in docker

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

on:
push:
branches:
- main
- release
- dev
pull_request:
branches:
- main
- release

jobs:
Pytest:
strategy:
max-parallel: 5

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Compose
run: docker compose -f .devcontainer/docker-compose.yml up -d
- name: Run tests
run: docker compose -f .devcontainer/docker-compose.yml run --rm -u root -v /home/runner/work/sotopia/sotopia:/workspaces/sotopia devcontainer /bin/sh -c "cd /workspaces/sotopia; ls; uv sync --extra test --extra chat; uv run pytest --ignore tests/cli --cov=. --cov-report=xml"
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=1000']
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.1 # Use the sha / tag you want to point at
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ See [documentation](https://docs.sotopia.world) for more details.
## Get started

### Install locally
We recommend using a virtual environment, e.g. with anaconda3: `conda create -n sotopia python=3.11; conda activate sotopia; curl -sSL https://install.python-poetry.org | python3`.
We recommend using a virtual environment, e.g. with anaconda3: `conda create -n sotopia python=3.11; conda activate sotopia;`.

Then:
`python -m pip install sotopia; sotopia install`
Expand Down
82 changes: 82 additions & 0 deletions docs/doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Welcome to the documentation for the Sotopia
import os
import openai
import rich
from tqdm import tqdm


def generate_api_docs(source_dir: str, output_dir: str) -> None:
# Create the output directory if it doesn't exist
os.makedirs(output_dir, exist_ok=True)

# Walk through the source directory
total_files = sum(
[
len(files)
for r, d, files in os.walk(source_dir)
if any(f.endswith(".py") and not f.startswith("__") for f in files)
]
)
with tqdm(total=total_files, desc="Generating API docs") as pbar:
for root, dirs, files in os.walk(source_dir):
for file in files:
if file.endswith(".py") and not file.startswith("__"):
file_path = os.path.join(root, file)

# Read the Python file
with open(file_path, "r") as f:
code = f.read()

# Write the documentation to a file
doc_content = generate_doc_for_node(code)
rich.print(f"doc_content: {doc_content}")
relative_path = os.path.relpath(root, source_dir)
output_path = os.path.join(
output_dir, relative_path, f"{file[:-3]}.md"
)
os.makedirs(os.path.dirname(output_path), exist_ok=True)

with open(output_path, "w") as f:
f.write(doc_content)
pbar.update(1)


def generate_doc_for_node(code: str) -> str:
prompt = f"""
Please provide a brief documentation for the following Python code:
```python
{code}
```
Include a short description, parameters (if any), and return value (if any) as well as usage examples. Try to prettify the markdown content as much as possible.
Please only return the markdown content and do not include any other text.
"""

response = openai.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You are a helpful assistant that generates Python documentation. You only return the markdown content and do not include any other text.",
},
{"role": "user", "content": prompt},
],
)

doc = response.choices[0].message.content
assert isinstance(doc, str)

return doc


if __name__ == "__main__":
openai.api_key = os.getenv("OPENAI_API_KEY")
if not openai.api_key:
raise ValueError("Please set the OPENAI_API_KEY environment variable")

source_dir = "sotopia/samplers"
output_dir = "docs/pages/python_API/samplers"
generate_api_docs(source_dir, output_dir)

print("API documentation generated successfully.")
8 changes: 5 additions & 3 deletions docs/pages/_meta.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"index": {
"title": "Introduction",
"type": "page",
"theme": {
"breadcrumb": true
}
},
"---": {
"type": "separator"
},
"concepts": {
"title": "Concepts",
"type": "page"
},
"python_API": {
"title": "Python API",
"type": "page"
},
"examples": {
"title": "Examples",
"type": "page"
Expand Down
17 changes: 17 additions & 0 deletions docs/pages/concepts/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"agents": {
"title": "Agents"
},
"environments": {
"title": "Environments"
},
"database": {
"title": "Database"
},
"generation": {
"title": "Generation Utilities"
},
"renderers": {
"title": "Renderers"
}
}
Loading

0 comments on commit 8606b17

Please sign in to comment.