artefactual.preprocessing.BatchRequestOutput#

class artefactual.preprocessing.BatchRequestOutput(**data)[source]#

Bases: ResponseModel

One line of an OpenAI Batch output file.

The Batch API returns JSONL – one of these per line – and any OpenAI-compatible server writes the same shape. The completion is always nested under response.body.

custom_id is the only id that identifies the request: id is assigned by the provider, as is response.request_id, and so is the completion’s own id. It is the key every stage joins on.

A failed line carries no usable completion, and completion reports that by returning None. LogProbParser refuses such a line: it emits one row per line, and a dropped row would shift every later response against its label.

Methods

construct

copy

Returns a copy of the model.

dict

from_orm

json

model_construct

Creates a new instance of the Model class with validated data.

model_copy

!!! abstract "Usage Documentation"

model_dump

!!! abstract "Usage Documentation"

model_dump_json

!!! abstract "Usage Documentation"

model_json_schema

Generates a JSON schema for a model class.

model_parametrized_name

Compute the class name for parametrizations of generic classes.

model_post_init

Override this method to perform additional initialization after __init__ and model_construct.

model_rebuild

Try to rebuild the pydantic-core schema for the model.

model_validate

Validate a pydantic model instance.

model_validate_json

!!! abstract "Usage Documentation"

model_validate_strings

Validate the given object with string data against the Pydantic model.

parse_file

parse_obj

parse_raw

payload

The completion this line carries, validated as the format it is.

schema

schema_json

update_forward_refs

validate

property completion: Any | None#

The completion payload this line carries, or None if it carries none.

None covers every way a line can fail, which failure names: a non-HTTP error, an HTTP status outside 2xx – where the body is an error object rather than a completion – and a missing envelope or body.

custom_id: str#
error: Any#
property failure: str | None#

Why this line carries no completion, phrased for an error message.

None when it carries one. The error repr is truncated because it is provider text of no fixed length, and this ends up inside exception messages.

id: str | None#
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'from_attributes': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

payload(kind=<class 'artefactual.preprocessing.response_models.LogprobsMixin'>)[source]#

The completion this line carries, validated as the format it is.

kind narrows the formats accepted: the default is every registered one, a format accepts its own only.

Raises for a line that carries none: dropping a failed line would shift every later response against its label. Filter the failed lines out before parsing, which is where their failure can still be reported against a custom_id.

The body goes through the same formats as a bare completion, so a batch of Responses-API calls parses like any other.

Raises:
  • ValueError – If the line failed, naming its custom_id and failure.

  • TypeError – If the body is neither a chat completion nor a Responses payload.

Return type:

ChatCompletion | ResponsesPayload

response: BatchResponseData | None#