Backup #560
| ID | 560 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/UseCases/Chat/ChatResponse.php |
| Version | 2 |
| Typ |
modified |
| Größe | 2.9 KB |
| Hash | 2d051684e1e4cd3249440c24512edbd5a6551a64222d3824abbea568cc11f87c |
| Datum | 2025-12-23 03:34:59 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
namespace UseCases\Chat;
/**
* ChatResponse - DTO for chat message results
*
* Contains the AI response and all associated metadata.
*/
final class ChatResponse
{
public function __construct(
private string $answer,
private array $sources = [],
private ?int $tokensInput = null,
private ?int $tokensOutput = null,
private ?float $durationSeconds = null,
private ?string $error = null,
private ?array $qualityValidation = null,
) {
}
public function getQualityValidation(): ?array
{
return $this->qualityValidation;
}
public function withQualityValidation(array $validation): self
{
return new self(
answer: $this->answer,
sources: $this->sources,
tokensInput: $this->tokensInput,
tokensOutput: $this->tokensOutput,
durationSeconds: $this->durationSeconds,
error: $this->error,
qualityValidation: $validation,
);
}
public function getAnswer(): string
{
return $this->answer;
}
public function getSources(): array
{
return $this->sources;
}
public function getTokensInput(): ?int
{
return $this->tokensInput;
}
public function getTokensOutput(): ?int
{
return $this->tokensOutput;
}
public function getDurationSeconds(): ?float
{
return $this->durationSeconds;
}
public function getError(): ?string
{
return $this->error;
}
public function hasError(): bool
{
return $this->error !== null;
}
/**
* Create from AI service response array
*/
public static function fromServiceResponse(array $result, ?float $duration = null): self
{
if (isset($result['error'])) {
return new self(
answer: '',
error: $result['error'],
);
}
return new self(
answer: $result['answer'] ?? '',
sources: $result['sources'] ?? [],
tokensInput: $result['usage']['input_tokens'] ?? null,
tokensOutput: $result['usage']['output_tokens'] ?? null,
durationSeconds: $duration,
);
}
/**
* Create error response
*/
public static function error(string $message): self
{
return new self(
answer: '',
error: $message,
);
}
/**
* Convert to array for view rendering
*/
public function toArray(): array
{
return [
'answer' => $this->answer,
'sources' => $this->sources,
'usage' => [
'input_tokens' => $this->tokensInput,
'output_tokens' => $this->tokensOutput,
],
'duration_seconds' => $this->durationSeconds,
'error' => $this->error,
];
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 732 |
3 |
modified |
2.9 KB |
2025-12-23 07:57 |
| 560 |
2 |
modified |
2.9 KB |
2025-12-23 03:34 |
| 559 |
1 |
modified |
2.3 KB |
2025-12-23 03:34 |
← Zurück zur Übersicht