Skip to content

Commit

Permalink
Rename ->object to ->structured
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlive committed Dec 12, 2024
1 parent ffac3a5 commit 89a820c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions docs/core-concepts/structured-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $response = Prism::structured()
->generate();

// Access your structured data
$review = $response->object;
$review = $response->structured;
echo $review['title']; // "Inception"
echo $review['rating']; // "5 stars"
echo $review['summary']; // "A mind-bending..."
Expand Down Expand Up @@ -81,7 +81,7 @@ $response = Prism::structured()
->generate();

// Access the structured data as a PHP array
$data = $response->object;
$data = $response->structured;

// Get the raw response text if needed
echo $response->text;
Expand All @@ -100,11 +100,11 @@ $rawResponse = $response->response;
> [!TIP]
> Always validate the structured data before using it in your application:
```php
if ($response->object === null) {
if ($response->structured === null) {
// Handle parsing failure
}

if (!isset($response->object['required_field'])) {
if (!isset($response->structured['required_field'])) {
// Handle missing required data
}
```
Expand Down
4 changes: 2 additions & 2 deletions src/Structured/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Response
/**
* @param Collection<int, Step> $steps
* @param Collection<int, Message> $responseMessages
* @param array<mixed> $object
* @param array<mixed> $structured
* @param ToolCall[] $toolCalls
* @param ToolResult[] $toolResults
* @param array{id: string, model: string} $response
Expand All @@ -25,7 +25,7 @@ public function __construct(
public readonly Collection $steps,
public readonly Collection $responseMessages,
public readonly string $text,
public readonly ?array $object,
public readonly ?array $structured,
public readonly FinishReason $finishReason,
public readonly array $toolCalls,
public readonly array $toolResults,
Expand Down
2 changes: 1 addition & 1 deletion src/Structured/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function toResponse(): Response
steps: $this->steps,
responseMessages: $this->responseMessages,
text: $finalStep->text,
object: $finalStep->finishReason === FinishReason::Stop
structured: $finalStep->finishReason === FinishReason::Stop
? $this->decodeObject($finalStep->text)
: [],
finishReason: $finalStep->finishReason,
Expand Down
4 changes: 2 additions & 2 deletions tests/Generators/StructuredGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
->generate();

// Assert response
expect($response->object)->toBe(['forecast_summary' => '70° and sunny']);
expect($response->structured)->toBe(['forecast_summary' => '70° and sunny']);
expect($response->finishReason)->toBe(FinishReason::Stop);
expect($response->toolCalls)->toBeEmpty();
expect($response->toolResults)->toBeEmpty();
Expand Down Expand Up @@ -334,7 +334,7 @@
->generate();

// Assert Response
expect($response->object)->toBe(['forecast_summary' => 'The weather is 75 and sunny!']);
expect($response->structured)->toBe(['forecast_summary' => 'The weather is 75 and sunny!']);
expect($response->finishReason)->toBe(FinishReason::Stop);

// Assert steps
Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/Anthropic/StructuredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
->withPrompt('What time is the tigers game today and should I wear a coat?')
->generate();

expect($response->object)->toBeArray();
expect($response->object)->toBe([
expect($response->structured)->toBeArray();
expect($response->structured)->toBe([
'weather' => '90° and sunny',
'game_time' => '3pm',
'coat_required' => false,
Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/Ollama/StructuredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
->withPrompt('What time is the tigers game today and should I wear a coat?')
->generate();

expect($response->object)->toBeArray();
expect($response->object)->toBe([
expect($response->structured)->toBeArray();
expect($response->structured)->toBe([
'weather' => 'sunny, 90°',
'game_time' => '3pm',
'coat_required' => false,
Expand Down
8 changes: 4 additions & 4 deletions tests/Providers/OpenAI/StructuredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
->withPrompt('What time is the tigers game today and should I wear a coat?')
->generate();

expect($response->object)->toBeArray();
expect($response->object)->toBe([
expect($response->structured)->toBeArray();
expect($response->structured)->toBe([
'weather' => 'The weather will be 90° and sunny',
'game_time' => 'The Tigers game is at 3 pm in Detroit',
'coat_required' => false,
Expand Down Expand Up @@ -89,8 +89,8 @@
->withPrompt('What time is the tigers game today and should I wear a coat?')
->generate();

expect($response->object)->toBeArray();
expect($response->object)->toBe([
expect($response->structured)->toBeArray();
expect($response->structured)->toBe([
'weather' => 'The weather will be 90° and sunny',
'game_time' => 'The tigers game is at 3pm in Detroit',
'coat_required' => false,
Expand Down

0 comments on commit 89a820c

Please sign in to comment.