artefactual.preprocessing.openai_parser#
Functions
|
Detects if the output follows the signature of the new OpenAI Responses API. |
|
Processes top log probabilities from OpenAI Chat Completion (classic 'choices' format). |
|
Parses the response from the 'client.responses.create' API to extract the top log probabilities. |
Retrieves the log probabilities of the sampled tokens from a response following the OpenAI Chat Completion format. |
|
|
Retrieves the log probabilities of the sampled tokens from a response following the OpenAI Responses API format. |
- 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:
- 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 top log probabilities from OpenAI Chat Completion (classic ‘choices’ format).
- 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 the top log probabilities.
Structure expected: response.output -> [item] -> item.content -> [part] -> part.logprobs
- 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.
- artefactual.preprocessing.openai_parser.sampled_tokens_logprobs_chat_completion_api(response)[source]#
Retrieves the log probabilities of the sampled tokens from a response following the OpenAI Chat Completion format.
Iterates over all choices and returns a list of 1D arrays (one per choice), consistent with the vLLM counterpart.
- Return type:
list[ndarray[tuple[int,...],dtype[TypeVar(_ScalarType_co, bound=generic, covariant=True)]]]
- Args:
response (Any): The response object from the OpenAI Chat Completion API.
- Returns:
- list[NDArray]: A list of 1D numpy arrays, each containing the log probabilities
of the sampled tokens for one choice.
- artefactual.preprocessing.openai_parser.sampled_tokens_logprobs_responses_api(response)[source]#
Retrieves the log probabilities of the sampled tokens from a response following the OpenAI Responses API format.
Iterates over all output items and returns a list of 1D arrays (one per output item), consistent with the vLLM counterpart.
- Return type:
list[ndarray[tuple[int,...],dtype[TypeVar(_ScalarType_co, bound=generic, covariant=True)]]]
- Args:
response (Any): The response object from the OpenAI Responses API.
- Returns:
- list[NDArray]: A list of 1D numpy arrays, each containing the log probabilities
of the sampled tokens for one output item.