| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Base class for a text generation model for providers that implement OpenAI's API format. This abstract class is designed to work with any AI provider that offers an OpenAI-compatible API endpoint, including but not limited to Anthropic, Google, and other providers that have adopted OpenAI's API specification as a standard interface.
| File Size: | 557 lines (25 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
| generateTextResult(array $prompt) X-Ref |
| {@inheritDoc} |
| prepareGenerateTextParams(array $prompt) X-Ref |
| Prepares the given prompt and the model configuration into parameters for the API request. return: array<string, mixed> The parameters for the API request. param: list<Message> $prompt The prompt to generate text for. Either a single message or a list of messages |
| prepareMessagesParam(array $messages, ?string $systemInstruction = null) X-Ref |
| Prepares the messages parameter for the API request. return: list<array<string, mixed>> The prepared messages parameter. param: list<Message> $messages The messages to prepare. param: string|null $systemInstruction An optional system instruction to prepend to the messages. |
| getMessageRoleString(MessageRoleEnum $role) X-Ref |
| Returns the OpenAI API specific role string for the given message role. return: string The role for the API request. param: MessageRoleEnum $role The message role. |
| getMessagePartContentData(MessagePart $part) X-Ref |
| Returns the OpenAI API specific content data for a message part. return: ?array<string, mixed> The data for the message content part, or null if not applicable. param: MessagePart $part The message part to get the data for. |
| getMessagePartToolCallData(MessagePart $part) X-Ref |
| Returns the OpenAI API specific tool calls data for a message part. return: ?array<string, mixed> The data for the message tool call part, or null if not applicable. param: MessagePart $part The message part to get the data for. |
| validateOutputModalities(array $outputModalities) X-Ref |
| Validates that the given output modalities to ensure that at least one output modality is text. param: array<ModalityEnum> $outputModalities The output modalities to validate. |
| prepareOutputModalitiesParam(array $modalities) X-Ref |
| Prepares the output modalities parameter for the API request. return: list<string> The prepared modalities parameter. param: array<ModalityEnum> $modalities The modalities to prepare. |
| prepareToolsParam(array $functionDeclarations) X-Ref |
| Prepares the tools parameter for the API request. return: list<array<string, mixed>> The prepared tools parameter. param: list<FunctionDeclaration> $functionDeclarations The function declarations. |
| prepareResponseFormatParam(?array $outputSchema) X-Ref |
| Prepares the response format parameter for the API request. This is only called if the output MIME type is `application/json`. return: array<string, mixed> The prepared response format parameter. param: array<string, mixed>|null $outputSchema The output schema. |
| throwIfNotSuccessful(Response $response) X-Ref |
| Throws an exception if the response is not successful. param: Response $response The HTTP response to check. |
| parseResponseToGenerativeAiResult(Response $response) X-Ref |
| Parses the response from the API endpoint to a generative AI result. return: GenerativeAiResult The parsed generative AI result. param: Response $response The response from the API endpoint. |
| parseResponseChoiceToCandidate(array $choiceData, int $index) X-Ref |
| Parses a single choice from the API response into a Candidate object. return: Candidate The parsed candidate. param: ChoiceData $choiceData The choice data from the API response. param: int $index The index of the choice in the choices array. |
| parseResponseChoiceMessage(array $messageData, int $index) X-Ref |
| Parses the message from a choice in the API response. return: Message The parsed message. param: MessageData $messageData The message data from the API response. param: int $index The index of the choice in the choices array. |
| parseResponseChoiceMessageParts(array $messageData, int $index) X-Ref |
| Parses the message parts from a choice in the API response. return: MessagePart[] The parsed message parts. param: MessageData $messageData The message data from the API response. param: int $index The index of the choice in the choices array. |
| parseResponseChoiceMessageToolCallPart(array $toolCallData) X-Ref |
| Parses a tool call part from the API response. return: MessagePart|null The parsed message part for the tool call, or null if not applicable. param: ToolCallData $toolCallData The tool call data from the API response. |
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |