diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index ceef196..d1016e6 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -10,7 +10,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.4] + php: [8.3, 8.4, 8.5] dependency-version: [prefer-lowest, prefer-stable] name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e582bdd..14664ad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, macos-latest, windows-latest] - php: [8.4] + php: [8.3, 8.4, 8.5] dependency-version: [prefer-lowest, prefer-stable] name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index 9651b02..6c2f945 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^8.3|^8.4", + "php": "^8.3|^8.4|^8.5", "guzzlehttp/guzzle": "^7.9" }, "require-dev": { @@ -54,7 +54,7 @@ "test:lint": "@php vendor/bin/pint --config https://raw.githubusercontent.com/DIJ-digital/pint-config/main/pint.json", "test:unit": "pest", "test:types": "phpstan", - "test:refactor": "rector --dry-run", + "test:refactor": "rector", "test": [ "@test:lint", "@test:type-coverage", diff --git a/rector.php b/rector.php index a3b3e14..17afb5a 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,5 @@ typeDeclarations: true, privatization: true, earlyReturn: true, - strictBooleans: true, ) ->withPhpSets(); diff --git a/src/Concerns/IsCompilable.php b/src/Concerns/IsCompilable.php index d32399a..f6b988c 100644 --- a/src/Concerns/IsCompilable.php +++ b/src/Concerns/IsCompilable.php @@ -38,7 +38,7 @@ private function compileString(string $prompt, array $data = []): string $values = array_values($data); return str_replace( - array_map(fn ($i): string => '{{' . $i . '}}', array_keys($data)), + array_map(fn (string $i): string => '{{' . $i . '}}', array_keys($data)), $values, $prompt ); diff --git a/src/Ingestion/Generation.php b/src/Ingestion/Generation.php index 13350cb..b3ed376 100644 --- a/src/Ingestion/Generation.php +++ b/src/Ingestion/Generation.php @@ -8,24 +8,23 @@ class Generation { - public string $id { - get => $this->generationId; - } + public readonly string $id; public function __construct( public readonly string $generationId, public readonly string $traceId, private readonly Ingestion $ingestion, ) { + $this->id = $this->generationId; } /** * Update this generation. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $modelParameters - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $modelParameters + * @param array|null $metadata */ public function update( array|string|null $input = null, diff --git a/src/Ingestion/Span.php b/src/Ingestion/Span.php index 65080e3..ae90364 100644 --- a/src/Ingestion/Span.php +++ b/src/Ingestion/Span.php @@ -8,23 +8,22 @@ class Span { - public string $id { - get => $this->spanId; - } + public readonly string $id; public function __construct( public readonly string $spanId, public readonly string $traceId, private readonly Ingestion $ingestion, ) { + $this->id = $this->spanId; } /** * Update this span. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata */ public function update( ?string $name = null, @@ -51,9 +50,9 @@ public function update( /** * Create a child span nested under this span. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata */ public function span( string $name, @@ -80,10 +79,10 @@ public function span( /** * Create a child generation nested under this span. * - * @param array|string $input - * @param array|string $output - * @param array|null $modelParameters - * @param array|null $metadata + * @param array|string $input + * @param array|string $output + * @param array|null $modelParameters + * @param array|null $metadata */ public function generation( string $name, diff --git a/src/Ingestion/Trace.php b/src/Ingestion/Trace.php index ae7535d..b8ef5f8 100644 --- a/src/Ingestion/Trace.php +++ b/src/Ingestion/Trace.php @@ -8,23 +8,22 @@ class Trace { - public string $id { - get => $this->traceId; - } + public readonly string $id; public function __construct( public readonly string $traceId, private readonly Ingestion $ingestion, ) { + $this->id = $this->traceId; } /** * Update this trace. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata - * @param list|null $tags + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata + * @param list|null $tags */ public function update( ?string $name = null, @@ -54,9 +53,9 @@ public function update( /** * Create a child span on this trace. * - * @param array|string|null $input - * @param array|string|null $output - * @param array|null $metadata + * @param array|string|null $input + * @param array|string|null $output + * @param array|null $metadata */ public function span( string $name, @@ -82,10 +81,10 @@ public function span( /** * Create a child generation on this trace. * - * @param array|string $input - * @param array|string $output - * @param array|null $modelParameters - * @param array|null $metadata + * @param array|string $input + * @param array|string $output + * @param array|null $modelParameters + * @param array|null $metadata */ public function generation( string $name, diff --git a/src/Prompt.php b/src/Prompt.php index 42c6e4b..3edee52 100644 --- a/src/Prompt.php +++ b/src/Prompt.php @@ -21,7 +21,8 @@ class Prompt public function __construct( private readonly TransporterInterface $transporter, private readonly string $defaultLabel, - ) {} + ) { + } /** * Retrieve a text prompt by name. Uses default label if no version or label provided. @@ -49,7 +50,7 @@ public function text(string $promptName, ?int $version = null, ?string $label = /** * Retrieve a chat prompt by name. Uses default label if no version or label provided. * - * @param array|null $fallback + * @param array|null $fallback * * @throws InvalidPromptTypeException */ @@ -96,10 +97,10 @@ public function list(?string $name = null, ?int $version = null, ?string $label /** * Create a new prompt. * - * @param ($type is PromptType::TEXT ? string : array) $prompt - * @param array|null $labels - * @param array|null $config - * @param array|null $tags + * @param ($type is PromptType::TEXT ? string : array) $prompt + * @param array|null $labels + * @param array|null $config + * @param array|null $tags * @return ($type is PromptType::TEXT ? TextPromptResponse : ChatPromptResponse) * * @throws JsonException @@ -164,7 +165,7 @@ public function create(string $promptName, string|array $prompt, PromptType $typ /** * Update labels for a specific prompt version. * - * @param array $labels + * @param array $labels * * @throws JsonException */ diff --git a/src/Responses/FallbackPrompt.php b/src/Responses/FallbackPrompt.php index acb3153..2d72e38 100644 --- a/src/Responses/FallbackPrompt.php +++ b/src/Responses/FallbackPrompt.php @@ -11,19 +11,6 @@ { use IsCompilable; - /** - * @param ($type is "text" ? string : array) $prompt - */ - public function __construct( - string|array $prompt, - string $type, - ) { - parent::__construct( - prompt: $prompt, - type: $type, - ); - } - /** * Create a text fallback prompt */ diff --git a/src/Responses/PromptListResponse.php b/src/Responses/PromptListResponse.php index afd1b00..dc4e983 100644 --- a/src/Responses/PromptListResponse.php +++ b/src/Responses/PromptListResponse.php @@ -30,7 +30,7 @@ public function __construct( public static function fromArray(array $data): self { return new self( - data: array_map(fn (array $data): PromptListItem => PromptListItem::fromArray($data), $data['data']), + data: array_map(PromptListItem::fromArray(...), $data['data']), meta: MetaData::fromArray($data['meta']), pagination: PaginationData::fromArray($data['pagination']), ); diff --git a/src/Responses/ScoreListResponse.php b/src/Responses/ScoreListResponse.php index dd3c1c5..58680dc 100644 --- a/src/Responses/ScoreListResponse.php +++ b/src/Responses/ScoreListResponse.php @@ -26,7 +26,7 @@ public function __construct( public static function fromArray(array $data): self { return new self( - data: array_map(fn (array $item): ScoreResponse => ScoreResponse::fromArray($item), $data['data']), + data: array_map(ScoreResponse::fromArray(...), $data['data']), meta: MetaData::fromArray($data['meta']), ); } diff --git a/tests/Feature/IngestionTest.php b/tests/Feature/IngestionTest.php index e61ca1a..61969d9 100644 --- a/tests/Feature/IngestionTest.php +++ b/tests/Feature/IngestionTest.php @@ -113,7 +113,7 @@ function getEventType(array $history, int $index = 0): string $ingestion = makeIngestion($history); // Act - $ingestion->trace(name: 'test-trace', userId: 'user-123', sessionId: 'sess-456'); + $ingestion->trace(name: 'test-trace', sessionId: 'sess-456', userId: 'user-123'); // Assert $body = getEventBody($history); @@ -166,7 +166,7 @@ function getEventType(array $history, int $index = 0): string // Act $trace = $ingestion->trace(name: 'my-trace', input: 'start'); - $result = $trace->update(output: 'final result', userId: 'user-456'); + $result = $trace->update(userId: 'user-456', output: 'final result'); // Assert expect($result)->toBe($trace) @@ -259,10 +259,10 @@ function getEventType(array $history, int $index = 0): string name: 'test-generation', input: ['messages' => [['role' => 'user', 'content' => 'Hi']]], output: 'Hello', - promptName: 'prompt-x', - promptVersion: 3, model: 'gpt-4o', modelParameters: ['temperature' => 0.2], + promptName: 'prompt-x', + promptVersion: 3, metadata: ['source' => 'test'], ); diff --git a/tests/Feature/ScoreTest.php b/tests/Feature/ScoreTest.php index aa9b510..da4ada0 100644 --- a/tests/Feature/ScoreTest.php +++ b/tests/Feature/ScoreTest.php @@ -29,9 +29,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'accuracy', value: 0.95, + traceId: 'trace-456', dataType: ScoreDataType::NUMERIC, ); @@ -59,9 +59,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'helpfulness', value: 'helpful', + traceId: 'trace-456', dataType: ScoreDataType::CATEGORICAL, ); @@ -86,9 +86,9 @@ $score = (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'is_correct', value: 1, + traceId: 'trace-456', dataType: ScoreDataType::BOOLEAN, ); @@ -154,8 +154,8 @@ page: 1, limit: 10, name: 'accuracy', - dataType: ScoreDataType::NUMERIC, traceId: 'trace-123', + dataType: ScoreDataType::NUMERIC, ); expect($history)->toHaveCount(1); @@ -217,9 +217,9 @@ (new Langfuse(new HttpTransporter($client))) ->score() ->create( - traceId: 'trace-456', name: 'accuracy', value: 0.95, + traceId: 'trace-456', dataType: ScoreDataType::NUMERIC, id: 'custom-score-id', observationId: 'obs-789',