Metadata-Version: 2.4
Name: zed-zeta-bindings
Version: 1.3.1
License-File: LICENSE-GPL
Summary: Python bindings for zeta_prompt
License: GPL-3.0-or-later
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# zed-zeta-bindings

Python bindings for Zed's Zeta prompt formatting and model output parsing code.

## Installation

```sh
pip install zed-zeta-bindings
```

## Usage

```python
import zeta_bindings as zeta

prompt_format = "Zeta2"  # Or "Zeta2.1".
prompt_input = zeta.ZetaPromptInput.from_dict(request_body)
prompt = zeta.format_prompt(prompt_input, prompt_format)
stop_tokens = zeta.stop_tokens(prompt_format) or None

raw_output = await engine.predict({"prompt": prompt, "stop": stop_tokens})
parsed_output = zeta.parse_output(raw_output, prompt_format, prompt_input)

response = {
    "output": parsed_output.new_editable_region,
    "editable_range": {
        "start": parsed_output.range_in_excerpt[0],
        "end": parsed_output.range_in_excerpt[1],
    },
}
```

`prompt_format` should be `Zeta2` or `Zeta2.1`. `format_prompt` returns `None` when the prompt input exceeds the token budget for the selected format.

For more detailed type information, see `crates/zeta_prompt` in the Zed repository: https://github.com/zed-industries/zed/tree/main/crates/zeta_prompt.

## License

`zed-zeta-bindings` is licensed under GPL-3.0-or-later

## API

### `ZetaPromptInput.from_dict(data)`

Builds the typed prompt input from a request dictionary. The required fields are:

- `cursor_path`
- `cursor_excerpt`
- `cursor_offset_in_excerpt`
- `excerpt_ranges`

Optional fields include `excerpt_start_row`, `events`, `related_files`, `active_buffer_diagnostics`, and `syntax_ranges`.

### `format_prompt(prompt_input, format_str)`

Formats a `ZetaPromptInput` into the prompt string sent to the model. `format_str` should be `Zeta2` or `Zeta2.1`.

Returns `None` if the input does not fit within the selected format's token budget.

### `stop_tokens(format_str)`

Returns the stop tokens for the selected prompt format. `format_str` should be `Zeta2` or `Zeta2.1`.

### `parse_output(model_output, format_str, prompt_input)`

Parses a raw model completion into a `ParsedOutput`. `format_str` should be `Zeta2` or `Zeta2.1`.

`ParsedOutput` contains:

- `new_editable_region`: the replacement text for the editable region.
- `range_in_excerpt`: the `[start, end]` byte range of the editable region in `cursor_excerpt`.
- `cursor_offset_in_new_editable_region`: the cursor offset in the replacement text, when present.

