artefactual.preprocessing.openai_parser#

Functions

is_openai_responses_api(outputs)

Detects if the output follows the signature of the new OpenAI Responses API.

process_openai_chat_completion(response, ...)

Processes log probabilities from OpenAI Chat Completion (classic 'choices' format).

process_openai_responses_api(response)

Parses the response from the 'client.responses.create' API to extract log probabilities.

artefactual.preprocessing.openai_parser.is_openai_responses_api(outputs)[source]#

Detects if the output follows the signature of the new OpenAI Responses API.

Return type:

bool

Args:

outputs (Any): The output object or dictionary to inspect.

Returns:

bool: True if the output matches the OpenAI Responses API signature, False otherwise.

artefactual.preprocessing.openai_parser.process_openai_chat_completion(response, iterations)[source]#

Processes log probabilities from OpenAI Chat Completion (classic ‘choices’ format).

Return type:

list[dict[int, list[float]]]

Args:

response (Any): The response object or dictionary from OpenAI API (ChatCompletion). iterations (int): The number of iterations (choices) to process.

Returns:

list[dict[int, list[float]]]: A list of dictionaries, where each dictionary maps token indices to lists of log probabilities for a sequence.

artefactual.preprocessing.openai_parser.process_openai_responses_api(response)[source]#

Parses the response from the ‘client.responses.create’ API to extract log probabilities.

Structure expected: response.output -> [item] -> item.content -> [part] -> part.logprobs

Return type:

list[dict[int, list[float]]]

Args:

response (Any): The response object from the OpenAI Responses API.

Returns:

list[dict[int, list[float]]]: A list of dictionaries, where each dictionary maps token indices to lists of log probabilities for a sequence.