WordPress\AiClient\Providers\OpenAiCompatibleImplementation
AbstractOpenAiCompatibleTextGenerationModel::getMessagePartToolCallData
Returns the OpenAI API specific tool calls data for a message part.
Метод класса: AbstractOpenAiCompatibleTextGenerationModel{}
Хуков нет.
Возвращает
?Массив<Строку,. mixed> The data for the message tool call part, or null if not applicable.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->getMessagePartToolCallData( $part ): ?array;
- $part(MessagePart) (обязательный)
- The message part to get the data for.
Список изменений
| С версии 0.1.0 | Введена. |
Код AbstractOpenAiCompatibleTextGenerationModel::getMessagePartToolCallData() AbstractOpenAiCompatibleTextGenerationModel::getMessagePartToolCallData WP 7.0.4
protected function getMessagePartToolCallData(MessagePart $part): ?array
{
$type = $part->getType();
if ($type->isFunctionCall()) {
$functionCall = $part->getFunctionCall();
if (!$functionCall) {
// This should be impossible due to class internals, but still needs to be checked.
throw new RuntimeException('The function call typed message part must contain a function call.');
}
$args = $functionCall->getArgs();
/*
* Ensure null or empty arrays become empty objects for JSON encoding.
* While in theory the JSON schema could also dictate a type of
* 'array', in practice function arguments are typically of type
* 'object'. More importantly, the OpenAI API specification seems
* to expect that, and does not support passing arrays as the root
* value. The null check handles the case where FunctionCall normalizes
* empty arrays to null.
*/
if ($args === null || is_array($args) && count($args) === 0) {
$args = new \stdClass();
}
return ['type' => 'function', 'id' => $functionCall->getId(), 'function' => ['name' => $functionCall->getName(), 'arguments' => json_encode($args)]];
}
// All other types are handled in `getMessagePartContentData()`.
return null;
}