Skip to content

Async HTTP support #646

@rhysemmerson

Description

@rhysemmerson

Prism can only make blocking HTTP requests. This makes it hard to do async workflows.

For example: running an input guardrail asynchronously with the main model request.

$guardrailRequest = Prism::structured()
    ->async()
    // ...
    ->asStructures();

$conversationRequest = Prism::text()
    ->async()
    // ...
    ->stream();

[$guardrailResult, $conversationResult] = Promise\all([
    $guardrailRequest,
    $conversationRequest,
]);

if ($guardrailResult->structured['failed']) {
   throw new GuardrailException(); 
}

foreach ($conversationResult as $chunk) {
    yield $chunk->text;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions