Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
uv pip install ruff mypy
uv pip install -e ".[test]"
- name: Lint with ruff
run: |
ruff check .
- name: Type check with mypy
run: |
mypy sotopia_verifiable
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
uv pip install pytest pytest-cov
uv pip install -e ".[test]"
- name: Test with pytest
run: |
pytest --cov=sotopia_verifiable tests/
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [pydantic]
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# sotopia-verifiable
A collection of verifiable games in sotopia format
# Sotopia Verifiable

A collection of verifiable games in Sotopia format. This extension provides tools and utilities for creating and evaluating verifiable social interactions within the Sotopia platform.

## Installation

```bash
pip install sotopia-verifiable
```

## Usage

```python
import sotopia
from sotopia_verifiable import VerifiableGame

# Example code will be added here
```

## Features

- Verifiable game mechanics
- Integration with Sotopia platform
- Tools for evaluation and analysis

## Development

To set up the development environment:

```bash
# Clone the repository
git clone https://github.com/sotopia-lab/sotopia-verifiable.git
cd sotopia-verifiable

# Install dependencies
pip install -e ".[test]"

# Run tests
pytest
```

## License

MIT License
40 changes: 40 additions & 0 deletions examples/basic_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Basic example of using Sotopia Verifiable."""

from sotopia_verifiable import VerifiableGame

# Create a game configuration
game_config = {
"name": "Simple Verification Example",
"verification_rules": [
{"type": "score_threshold", "min_score": 0.7}
]
}

# Create a verifiable game
game = VerifiableGame(game_config)

# Add another verification rule
game.add_verification_rule({"type": "time_limit", "max_seconds": 300})

# Print the verification rules
print("Verification Rules:")
for i, rule in enumerate(game.get_verification_rules(), 1):
print(f"Rule {i}: {rule}")

# Simulate a game outcome
game_outcome = {
"score": 0.85,
"time_taken": 250
}

# Verify the outcome
result = game.verify(game_outcome)

# Print the verification result
print("\nVerification Result:")
print(f"Valid: {result.is_valid}")
print(f"Score: {result.score}")
print(f"Details: {result.details}")

# Note: The base implementation always returns valid=True
# Custom implementations would check against the actual rules
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[project]
name = "sotopia-verifiable"
version = "0.1.0"
description = "A verifiable extension for Sotopia platform."
authors = [
{ name = "Xuhui Zhou", email = "xuhuiz@cs.cmu.edu" }
]
requires-python = "==3.12.*"
license = { text = "MIT License" }
readme = "README.md"

dependencies = [
"sotopia>=0.1.4",
"pydantic>=2.5.0,<3.0.0",
"rich>=13.6.0,<15.0.0",
"absl-py>=2.0.0,<3.0.0"
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.optional-dependencies]
test = ["pytest", "pytest-cov", "pytest-asyncio"]

[tool.uv]
dev-dependencies = [
"pre-commit",
"types-setuptools",
"types-requests",
"ruff",
"mypy"
]

[tool.mypy]
mypy_path = "stubs"
strict = true
plugins = [
"pydantic.mypy"
]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"

[project.scripts]
sotopia-verifiable = "sotopia_verifiable.cli:app"
7 changes: 7 additions & 0 deletions sotopia_verifiable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Sotopia Verifiable - A collection of verifiable games in Sotopia format."""

__version__ = "0.1.0"

from sotopia_verifiable.core.verifiable_game import VerifiableGame

__all__ = ["VerifiableGame"]
5 changes: 5 additions & 0 deletions sotopia_verifiable/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""CLI tools for Sotopia Verifiable."""

from sotopia_verifiable.cli.app import app

__all__ = ["app"]
89 changes: 89 additions & 0 deletions sotopia_verifiable/cli/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Command-line interface for Sotopia Verifiable."""

import sys
from typing import List, Optional

from rich.console import Console

console = Console()


def app(argv: Optional[List[str]] = None) -> int:
"""Main entry point for the CLI.

Args:
argv: Command line arguments

Returns:
Exit code
"""
if argv is None:
argv = sys.argv[1:]

console.print("[bold green]Sotopia Verifiable[/bold green]")
console.print("A collection of verifiable games in Sotopia format")

if not argv:
console.print("\n[bold]Available commands:[/bold]")
console.print(" verify - Verify a game outcome")
console.print(" list - List available verification rules")
console.print("\nRun with --help for more information.")
return 0

command = argv[0]

if command == "verify":
return _handle_verify(argv[1:])
elif command == "list":
return _handle_list(argv[1:])
elif command in ["--help", "-h", "help"]:
_print_help()
return 0
else:
console.print(f"[bold red]Unknown command:[/bold red] {command}")
console.print("Run with --help for available commands.")
return 1


def _handle_verify(args: List[str]) -> int:
"""Handle the verify command.

Args:
args: Command arguments

Returns:
Exit code
"""
console.print("[bold]Verify command[/bold] (not implemented yet)")
return 0


def _handle_list(args: List[str]) -> int:
"""Handle the list command.

Args:
args: Command arguments

Returns:
Exit code
"""
console.print("[bold]List command[/bold] (not implemented yet)")
return 0


def _print_help() -> None:
"""Print help information."""
console.print("[bold]Sotopia Verifiable CLI[/bold]")
console.print("\n[bold]Usage:[/bold]")
console.print(" sotopia-verifiable [command] [options]")

console.print("\n[bold]Commands:[/bold]")
console.print(" verify - Verify a game outcome")
console.print(" list - List available verification rules")

console.print("\n[bold]Options:[/bold]")
console.print(" --help, -h - Show this help message")


if __name__ == "__main__":
sys.exit(app())
5 changes: 5 additions & 0 deletions sotopia_verifiable/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Core functionality for Sotopia Verifiable."""

from sotopia_verifiable.core.verifiable_game import VerifiableGame

__all__ = ["VerifiableGame"]
Loading
Loading