Skip to content

Commit

Permalink
Migration from Poetry to uv (#218)
Browse files Browse the repository at this point in the history
* minimal demo example of running custom model

* devcontainer setup and example

* remove default_bad_process_model to allow using custom model entirely

* improve the demo to show parallel execution

* CI: update tests trigger from pull request target to pull request

* fix mypy errors

* adding stubs to pyproject.toml

* poetry lock

* install all extras in the devcontainer start script

* add dev containers instruction

* migration to uv

* update mypy

* Update index.mdx

* update uv venv path in the devcontainer and contributor's guide
  • Loading branch information
ProKil authored Oct 8, 2024
1 parent 71d6199 commit ed626ec
Show file tree
Hide file tree
Showing 13 changed files with 4,823 additions and 7,060 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pipx install poetry; poetry install --all-extras; ollama pull llama3.2:1b"
"postCreateCommand":
"pip install uv; uv venv /workspaces/.venv; export UV_PROJECT_ENVIRONMENT=/workspaces/.venv; echo export UV_PROJECT_ENVIRONMENT=/workspaces/.venv >> /root/.bashrc; uv sync --all-extras; ollama pull llama3.2:1b",

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

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"remoteUser": "root"
}
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
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ 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 --cov=. --cov-report=xml
- name: Upload coverage report to Codecov
uses: codecov/[email protected]
with:
Expand Down
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
6 changes: 5 additions & 1 deletion docs/pages/contribution/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ Please refer to [Dev Containers](https://containers.dev/supporting#editors) to s

#### Without Dev Containers

You can also set up the development environment without Dev Containers. Please manually install Redis, and if you want to use a local model, you can use Ollama, Llama.cpp, vLLM or many others which support OpenAI compatible endpoints.
You can also set up the development environment without Dev Containers. There are three things you will need to set up manually:

- Python and uv: Please start from an environment supporting Python 3.10+ and install uv using `pip install uv; uv sync --all-extra`.
- Redis: Please refer to introduction page for the set up of Redis.
- Local LLM (optional): If you don't have access to model endpoints (e.g. OpenAI, Anthropic or others), you can use a local model. You can use Ollama, Llama.cpp, vLLM or many others which support OpenAI compatible endpoints.


### 5. Write Code and Commit It
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/examples/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Callout } from 'nextra/components'
# Example Scripts For Using The Library

<Callout type="info" emoji="ℹ️">
Before running examples, please install extra dependencies with `pip install sotopia[examples]` or `poetry install -E examples` if you are using poetry.
Before running examples, please install extra dependencies with `pip install sotopia[examples]` or `uv run --extra examples <the example script>` if you are using uv.
</Callout>

```python
Expand Down
7 changes: 3 additions & 4 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export REDIS_OM_URL="redis://localhost:6379"
```bash
pip install sotopia[examples, chat]
```
if you are using poetry, you can install the package with:
if you are developing Sotopia using uv, you can sync your dependency with
```bash
poetry install -E examples -E chat
uv sync --extra examples --extra chat
```
</AccordionContent>
</AccordionItem>
Expand All @@ -123,8 +123,7 @@ export REDIS_OM_URL="redis://localhost:6379"
#### Clone the repo and install the package
```bash
git clone [email protected]:sotopia-lab/sotopia.git;
curl -sSL https://install.python-poetry.org | python3;
poetry install # or pip install -e .
pip install -e .
```

#### Set up Redis stack
Expand Down
2 changes: 1 addition & 1 deletion examples/generation_api/custom_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Example: Generate (2~7) random numbers using Llama3.2 model served by ollama
# To run this example, you can either
# 1. Use the sotopia devcontainer and run the following command in the terminal:
# poetry run python examples/generation_api/custom_model.py
# uv run python examples/generation_api/custom_model.py
# This example can also serve a sanity check for your devcontainer setup.
# OR 2. after installing sotopia, install ollama, and then:
# ollama pull llama3.2:1b; python examples/generation_api/custom_model.py
Expand Down
Loading

0 comments on commit ed626ec

Please sign in to comment.