Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^8.3|^8.4",
"php": "^8.3|^8.4|^8.5",
"guzzlehttp/guzzle": "^7.9"
},
"require-dev": {
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
typeDeclarations: true,
privatization: true,
earlyReturn: true,
strictBooleans: true,
)
->withPhpSets();
2 changes: 1 addition & 1 deletion src/Concerns/IsCompilable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
13 changes: 6 additions & 7 deletions src/Ingestion/Generation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
*/
public function update(
array|string|null $input = null,
Expand Down
25 changes: 12 additions & 13 deletions src/Ingestion/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
*/
public function update(
?string $name = null,
Expand All @@ -51,9 +50,9 @@ public function update(
/**
* Create a child span nested under this span.
*
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
*/
public function span(
string $name,
Expand All @@ -80,10 +79,10 @@ public function span(
/**
* Create a child generation nested under this span.
*
* @param array<string, mixed>|string $input
* @param array<string, mixed>|string $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string $input
* @param array<string, mixed>|string $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
*/
public function generation(
string $name,
Expand Down
27 changes: 13 additions & 14 deletions src/Ingestion/Trace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
* @param list<string>|null $tags
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
* @param list<string>|null $tags
*/
public function update(
?string $name = null,
Expand Down Expand Up @@ -54,9 +53,9 @@ public function update(
/**
* Create a child span on this trace.
*
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string|null $input
* @param array<string, mixed>|string|null $output
* @param array<string, mixed>|null $metadata
*/
public function span(
string $name,
Expand All @@ -82,10 +81,10 @@ public function span(
/**
* Create a child generation on this trace.
*
* @param array<string, mixed>|string $input
* @param array<string, mixed>|string $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
* @param array<string, mixed>|string $input
* @param array<string, mixed>|string $output
* @param array<string, mixed>|null $modelParameters
* @param array<string, mixed>|null $metadata
*/
public function generation(
string $name,
Expand Down
15 changes: 8 additions & 7 deletions src/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<int, array{role: string, content: string}>|null $fallback
* @param array<int, array{role: string, content: string}>|null $fallback
*
* @throws InvalidPromptTypeException
*/
Expand Down Expand Up @@ -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<int, array{role: string, content: string}>) $prompt
* @param array<int, string>|null $labels
* @param array<string, mixed>|null $config
* @param array<int, string>|null $tags
* @param ($type is PromptType::TEXT ? string : array<int, array{role: string, content: string}>) $prompt
* @param array<int, string>|null $labels
* @param array<string, mixed>|null $config
* @param array<int, string>|null $tags
* @return ($type is PromptType::TEXT ? TextPromptResponse : ChatPromptResponse)
*
* @throws JsonException
Expand Down Expand Up @@ -164,7 +165,7 @@ public function create(string $promptName, string|array $prompt, PromptType $typ
/**
* Update labels for a specific prompt version.
*
* @param array<int, string> $labels
* @param array<int, string> $labels
*
* @throws JsonException
*/
Expand Down
13 changes: 0 additions & 13 deletions src/Responses/FallbackPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@
{
use IsCompilable;

/**
* @param ($type is "text" ? string : array<int, array{role: string, content: string}>) $prompt
*/
public function __construct(
string|array $prompt,
string $type,
) {
parent::__construct(
prompt: $prompt,
type: $type,
);
}

/**
* Create a text fallback prompt
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/PromptListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/ScoreListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/IngestionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'],
);

Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/ScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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,
);

Expand All @@ -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,
);

Expand Down Expand Up @@ -154,8 +154,8 @@
page: 1,
limit: 10,
name: 'accuracy',
dataType: ScoreDataType::NUMERIC,
traceId: 'trace-123',
dataType: ScoreDataType::NUMERIC,
);

expect($history)->toHaveCount(1);
Expand Down Expand Up @@ -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',
Expand Down