Skip to content

Commit

Permalink
feat: Added $outputDimensionality param to embedContent method
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatih Aydın committed Dec 29, 2024
1 parent 5053e41 commit 7ba35de
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/Resources/EmbeddingModalContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface EmbeddingModalContract
/**
* @param string|Blob|array<string|Blob>|Content $content
*/
public function embedContent(string|Blob|array|Content $content, ?TaskType $taskType = null, ?string $title = null): EmbedContentResponse;
public function embedContent(string|Blob|array|Content $content, ?TaskType $taskType = null, ?string $title = null, ?int $outputDimensionality = null): EmbedContentResponse;

/**
* Generates multiple embedding vectors from the input Content which consists of a batch of strings represented as EmbedContentRequest objects.
Expand Down
4 changes: 3 additions & 1 deletion src/Requests/GenerativeModel/EmbedContentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function __construct(
protected readonly string $model,
protected readonly string|Blob|array|Content $part,
protected readonly ?TaskType $taskType = null,
protected readonly ?string $title = null
protected readonly ?string $title = null,
protected readonly ?int $outputDimensionality = null
) {}

public function resolveEndpoint(): string
Expand All @@ -43,6 +44,7 @@ protected function defaultBody(): array
'content' => Content::parse(part: $this->part)->toArray(),
'taskType' => $this->taskType?->value,
'title' => $this->title,
'outputDimensionality' => $this->outputDimensionality,
];
}
}
3 changes: 2 additions & 1 deletion src/Resources/EmbeddingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
*
* @param string|Blob|array<string|Blob>|Content $content
*/
public function embedContent(string|Blob|array|Content $content, ?TaskType $taskType = null, ?string $title = null): EmbedContentResponse
public function embedContent(string|Blob|array|Content $content, ?TaskType $taskType = null, ?string $title = null, ?int $outputDimensionality = null): EmbedContentResponse
{
/** @var ResponseDTO<array{ embedding: array{ values: array<float> } }> $response */
$response = $this->transporter->request(
Expand All @@ -46,6 +46,7 @@ public function embedContent(string|Blob|array|Content $content, ?TaskType $task
part: $content,
taskType: $taskType,
title: $title,
outputDimensionality: $outputDimensionality
)
);

Expand Down
2 changes: 1 addition & 1 deletion src/Testing/Resources/EmbeddingModelTestResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function resource(): string
return EmbeddingModel::class;
}

public function embedContent(Blob|Content|array|string $content, ?TaskType $taskType = null, ?string $title = null): EmbedContentResponse
public function embedContent(Blob|Content|array|string $content, ?TaskType $taskType = null, ?string $title = null, ?int $outputDimensionality = null): EmbedContentResponse
{
return $this->record(method: __FUNCTION__, args: func_get_args(), model: $this->model);
}
Expand Down

0 comments on commit 7ba35de

Please sign in to comment.