File size: 4,124 Bytes
6b4e5a8
 
 
 
 
 
 
 
fded8f2
 
 
6b4e5a8
 
 
 
 
 
 
fded8f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b4e5a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fded8f2
 
 
 
 
 
 
6b4e5a8
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""FastAPI application for the Spreadsheet Environment."""

from __future__ import annotations

import os
import sys
from pathlib import Path

from dotenv import load_dotenv
from fastapi.middleware.cors import CORSMiddleware

try:
    from openenv.core.env_server.http_server import create_app
except ImportError as e:
    raise ImportError(
        "openenv is required. Install with: uv sync"
    ) from e

load_dotenv(os.path.join(os.path.dirname(__file__), "..", ".env"))

import openenv.core.env_server.web_interface as _wi  # noqa: E402

_wi.DEFAULT_QUICK_START_MARKDOWN = """
### How to use this environment

**Spreadsheet** β€” exact workbook manipulation and reasoning over realistic spreadsheet tasks. Read sheets, understand structure, write values/formulas, and submit for automated evaluation.

Use the **Playground** on the right. Type a **Tool Name** and **Arguments Json**, then click **Step**.

---

#### 1. Start a session

1. Click **Reset**
2. `list_tools` β†’ `{}` β€” discover all 13 tools & their params
3. `list_scenarios` β†’ `{}` β€” see all 12 scenarios
4. `load_scenario` β†’ `{"scenario_id": "formula_repair_01"}`

#### 2. Explore the workbook

- `list_sheets` β†’ `{}` β€” sheet names, dimensions, visibility
- `read_range` β†’ `{"sheet": "Summary", "range": "A1:F10"}` β€” read cells
- `inspect_formula` β†’ `{"sheet": "Summary", "cell": "C5"}` β€” raw formula string
- `list_named_targets` β†’ `{}` β€” allowed output zones
- `get_session_info` β†’ `{}` β€” session metadata, step count
- `get_edit_history` β†’ `{}` β€” all edits so far

> **Note:** `read_range` uses **A1 notation** (e.g. `"B2:D10"`). Formulas are returned as strings.

#### 3. Edit cells

- `write_cell` β†’ `{"sheet": "Summary", "cell": "C5", "value": "=SUM(B2:B10)"}` β€” write one cell
- `write_range` β†’ `{"sheet": "Summary", "start_cell": "A1", "data": "[[1, 2], [3, 4]]"}` β€” write a block

> **Note:** `write_range` uses **start_cell** (not `cell`). The `data` arg is a JSON string of a 2D array.

> Values starting with `=` are treated as formulas. Numeric strings are auto-converted.

#### 4. Validate & submit

- `validate_partial` β†’ `{}` β€” check progress (pass/fail count, no answers revealed)
- `submit_workbook` β†’ `{}` β€” final evaluation (pass rate + per-check results)
- `reset_scenario` β†’ `{}` β€” restore workbook to original (scenario stays loaded)

> Use `validate_partial` before `submit_workbook` to gauge progress without ending the task.

---

#### Scenarios (12)

`formula_repair_01` Β· `formula_repair_02` Β· `cross_sheet_lookup_01` Β· `cross_sheet_lookup_02` Β· `conditional_aggregation_01` Β· `conditional_aggregation_02` Β· `ledger_reconciliation_01` Β· `ledger_reconciliation_02` Β· `messy_table_extraction_01` Β· `range_transformation_01` Β· `schedule_grid_fill_01` Β· `buggy_template_fix_01`

#### Connect from Python

```python
from spreadsheet import SpreadsheetAction, SpreadsheetEnv

env = SpreadsheetEnv(base_url="http://localhost:8000")
obs = env.reset()
obs = await env.step(SpreadsheetAction(
    tool_name="load_scenario",
    arguments_json='{"scenario_id": "formula_repair_01"}'
))
```

For more, see the [OpenEnv documentation](https://meta-pytorch.org/OpenEnv/).
"""

try:
    from spreadsheet.models import SpreadsheetAction, SpreadsheetObservation
    from spreadsheet.server.spreadsheet_environment import SpreadsheetEnvironment
except ImportError:
    sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
    from models import SpreadsheetAction, SpreadsheetObservation
    from server.spreadsheet_environment import SpreadsheetEnvironment

MAX_CONCURRENT_ENVS = int(os.getenv("MAX_CONCURRENT_ENVS", "8"))

app = create_app(
    SpreadsheetEnvironment,
    SpreadsheetAction,
    SpreadsheetObservation,
    env_name="spreadsheet",
    max_concurrent_envs=MAX_CONCURRENT_ENVS,
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)


def main(host: str = "0.0.0.0", port: int = 8000):
    import uvicorn
    uvicorn.run(app, host=host, port=port)


if __name__ == "__main__":
    main()