> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# decision

> Chọn giữa các phương án, hoặc chấm điểm các văn bản.

Tầng quyết định: một giao diện (`Decider`), với các bộ điều hợp cho DecisionLite, một bộ chấm bằng LLM, hoặc bất kỳ endpoint nào.

## `decision.base`

Giao diện mà chỉ mục phụ thuộc vào để đưa ra các quyết định nhỏ, và các kiểu xung quanh nó.

#### `Decider`

Các quyết định nhỏ trên văn bản tiếng Anh.

Khởi tạo bằng `Decider(*args, **kwargs)`.

| Phương thức | Làm gì |
| - | - |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | Một số trong \[0, 1] cho mỗi văn bản, càng cao nghĩa là càng trả lời `query` tốt hơn. |

#### `DecisionError`

Lần gọi thất bại (lỗi mô hình, hết thời gian chờ, câu trả lời sai) sau các lần thử lại của chính bộ điều hợp.

#### `Option`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `key` | `str` | required |
| `description` | `str` | required |
| `label` | `str \| None` | `None` |

#### `Pick`

Kết quả của `pick`.

| Trường | Kiểu | Mặc định |
| - | - | - |
| `key` | `str \| None` | required |
| `probabilities` | `dict[str, float]` | required |
| `confidence` | `float` | `0.0` |

| Phương thức | Làm gì |
| - | - |
| `(property)` | — |
| `ranked(self, n: int \| None = None) -> list[str]` | Các khóa phương án, tốt nhất trước, không có `OTHER`. |

#### `PickSpec`

Một câu hỏi `pick` không kèm văn bản của nó: các phương án, việc "không phương án nào" có được phép hay không, và các chỉ dẫn.

| Trường | Kiểu | Mặc định |
| - | - | - |
| `options` | `tuple[Option, ...]` | required |
| `allow_other` | `bool` | `True` |
| `instructions` | `str` | `''` |

#### `Preparable`

Tùy chọn: một bộ quyết định rẻ hơn khi nó biết các tập phương án của mình trước lần `pick` đầu tiên.

Khởi tạo bằng `Preparable(*args, **kwargs)`.

| Phương thức | Làm gì |
| - | - |
| `prepare(self, specs: Sequence[PickSpec]) -> None` | — |

#### `check_options`

```python theme={null}
check_options(options: Sequence[Option], allow_other: bool = True) -> None
```

Từ chối một tập phương án xấu.

## `decision.composite`

Dùng một bộ quyết định cho `pick` và một bộ khác cho `score`.

#### `CompositeDecider`

Khởi tạo bằng `CompositeDecider(picker: Decider, scorer: Decider)`.

| Phương thức | Làm gì |
| - | - |
| `prepare(self, specs: Sequence[PickSpec]) -> None` | — |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |

## `decision.decision_lite`

Một bộ quyết định dựa trên DecisionLite SDK (EmbeddingGemma qua MediaPipe Decision Maker).

#### `DecisionLiteDecider`

`Decider` trên một thể hiện DecisionLite SDK.

Khởi tạo bằng `DecisionLiteDecider(decision_model: str \| pathlib.Path, *, backend: str = 'cpu', workers: int = 1, auto_prepare: bool = True)`.

| Phương thức | Làm gì |
| - | - |
| `prepare(self, specs: Sequence[PickSpec], *, replace: bool = False) -> None` | Đăng ký các tập phương án với một lần nạp lại. |
| `close(self) -> None` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |

#### `build_config_text`

```python theme={null}
build_config_text(model_path: str, specs: Sequence[PickSpec], *, backend: str = 'cpu', workers: int = 1) -> str
```

Một cấu hình DecisionLite, dưới dạng văn bản YAML, với một quyết định lựa chọn cho mỗi spec và không có bộ dịch.

#### `spec_name`

```python theme={null}
spec_name(spec: PickSpec) -> str
```

Tên quyết định cho một spec.

## `decision.fake`

Một bộ quyết định theo kịch bản cho các bài kiểm thử: không mô hình, không mạng.

#### `FakeDecider`

Trả về các câu trả lời có sẵn theo thứ tự và ghi lại mọi yêu cầu.

Khởi tạo bằng `FakeDecider(picks: list[Pick \| Exception \| Callable[[str, Sequence[Option], bool], Pick]] \| None = None, scores: list[list[float] \| Exception \| Callable[[str, Sequence[str]], list[float]]] \| None = None, model: str = 'fake/decider')`.

| Phương thức | Làm gì |
| - | - |
| `choosing(cls, key: str \| None, options: Sequence[Option], *, allow_other: bool = True) -> Pick` | Một `Pick` chắc chắn cho `key` (None nghĩa là 'other'), với phần xác suất còn lại chia đều. |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |

## `decision.lexical`

Một bộ quyết định làm việc từ các từ trong văn bản, không mô hình và không mạng.

#### `LexicalDecider`

Khởi tạo bằng `LexicalDecider(embedder: Embedder \| None = None, *, temperature: float = 12.0, other_similarity: float = 0.3)`.

| Phương thức | Làm gì |
| - | - |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |

## `decision.llm_judge`

Một bộ quyết định nhờ một LLM chấm điểm các phương án, qua Protocol `LlmClient`.

#### `LlmJudgeDecider`

`Decider` trên bất kỳ `LlmClient` nào.

Khởi tạo bằng `LlmJudgeDecider(llm: LlmClient, *, max_texts: int = 40)`.

| Phương thức | Làm gì |
| - | - |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |

#### `pick_from_ratings`

```python theme={null}
pick_from_ratings(options: Sequence[Option], ratings: Sequence[int], allow_other: bool) -> Pick
```

Quy tắc cố định từ các điểm đánh giá thành một `Pick`.

## `decision.system_one`

Một bộ quyết định cho các endpoint quyết định kiểu System One: `POST /v1/systemone` (Cloudflare Clef, Kev, một bộ quyết định PPLX, hoặc bất kỳ mô hình nào mà SGLang phục vụ qua route đó).

#### `SystemOneDecider`

`Decider` trên một endpoint System One.

Khởi tạo bằng `SystemOneDecider(base_url: str, *, model: str = 'Cloudflare/clef-flash', timeout_s: float = 300.0, attempts: int = 3, backoff_s: float = 1.0, max_concurrency: int = 10, api_key_env: str \| None = None, score_instructions: str = 'Does the text directly answer the question?', transport: httpx.BaseTransport \| httpx.AsyncBaseTransport \| None = None, sleep: Callable[[float], None] = <built-in function sleep>, asleep: Callable[[float], typing.Any] = <function sleep at 0x102764b80>)`.

| Phương thức | Làm gì |
| - | - |
| `close(self) -> None` | — |
| `pick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `apick(self, text: str, options: Sequence[Option], *, allow_other: bool = True, instructions: str = '') -> Pick` | — |
| `score(self, query: str, texts: Sequence[str]) -> list[float]` | — |
| `ascore(self, query: str, texts: Sequence[str]) -> list[float]` | — |

#### `option_names`

```python theme={null}
option_names(options: Sequence[Option], allow_other: bool) -> tuple[list[str], str | None]
```

Các tên an toàn cho máy chủ của các phương án, và tên của phương án 'không phương án nào' (None khi không được đưa ra).

#### `parse_pick`

```python theme={null}
parse_pick(response: Any, back: dict[str, str | None]) -> Pick
```

#### `parse_score`

```python theme={null}
parse_score(response: Any) -> float
```

#### `pick_request`

```python theme={null}
pick_request(model: str, text: str, options: Sequence[Option], allow_other: bool, instructions: str) -> tuple[dict[str, typing.Any], dict[str, str | None]]
```

Phần thân yêu cầu, và ánh xạ từ tên phương án ngược về khóa (None là câu trả lời 'other').

#### `score_request`

```python theme={null}
score_request(model: str, query: str, text: str, instructions: str) -> dict[str, typing.Any]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.