Skip to content

Commit 040ed08

Browse files
authored
Added handling for when prompt_eval_count is not in the response (it is often not) so it does not error out (#2)
Added handling for when prompt_eval_count is not in the response (it is often not) so it does not error out
1 parent df6d306 commit 040ed08

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Client/Response/ChatResponse.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public static function fromArray(array $data): self
1414
createdAt: new DateTimeImmutable($data['created_at']),
1515
message: Message::fromArray($data['message']),
1616
done: $data['done'],
17-
totalDuration: $data['total_duration'],
18-
loadDuration: $data['load_duration'],
19-
promptEvalCount: $data['prompt_eval_count'],
20-
promptEvalDuration: $data['prompt_eval_duration'],
21-
evalCount: $data['eval_count'],
17+
totalDuration: $data['total_duration'] ?? null,
18+
loadDuration: $data['load_duration'] ?? null,
19+
promptEvalCount: $data['prompt_eval_count'] ?? null,
20+
promptEvalDuration: $data['prompt_eval_duration'] ?? null,
21+
evalCount: $data['eval_count'] ?? null,
2222
);
2323
}
2424

@@ -27,11 +27,11 @@ public function __construct(
2727
public readonly DateTimeImmutable $createdAt,
2828
public readonly Message $message,
2929
public readonly bool $done,
30-
public readonly int $totalDuration,
31-
public readonly int $loadDuration,
32-
public readonly int $promptEvalCount,
33-
public readonly int $promptEvalDuration,
34-
public readonly int $evalCount,
30+
public readonly ?int $totalDuration,
31+
public readonly ?int $loadDuration,
32+
public readonly ?int $promptEvalCount,
33+
public readonly ?int $promptEvalDuration,
34+
public readonly ?int $evalCount,
3535
) {
3636
}
3737
}

0 commit comments

Comments
 (0)