-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Task processing] Fix preferred providers #47177
Merged
julien-nc
merged 2 commits into
master
from
fix/noid/preferred-taskprocessing-providers
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
apps/testing/lib/TaskProcessing/FakeContextWriteProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Testing\TaskProcessing; | ||
|
||
use OCA\Testing\AppInfo\Application; | ||
use OCP\TaskProcessing\EShapeType; | ||
use OCP\TaskProcessing\ISynchronousProvider; | ||
use OCP\TaskProcessing\ShapeDescriptor; | ||
use OCP\TaskProcessing\ShapeEnumValue; | ||
use OCP\TaskProcessing\TaskTypes\ContextWrite; | ||
use RuntimeException; | ||
|
||
class FakeContextWriteProvider implements ISynchronousProvider { | ||
|
||
public function __construct() { | ||
} | ||
|
||
public function getId(): string { | ||
return Application::APP_ID . '-contextwrite'; | ||
} | ||
|
||
public function getName(): string { | ||
return 'Fake context write task processing provider'; | ||
} | ||
|
||
public function getTaskTypeId(): string { | ||
return ContextWrite::ID; | ||
} | ||
|
||
public function getExpectedRuntime(): int { | ||
return 1; | ||
} | ||
|
||
public function getInputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function getInputShapeDefaults(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalInputShape(): array { | ||
return [ | ||
'max_tokens' => new ShapeDescriptor( | ||
'Maximum output words', | ||
'The maximum number of words/tokens that can be generated in the completion.', | ||
EShapeType::Number | ||
), | ||
'model' => new ShapeDescriptor( | ||
'Model', | ||
'The model used to generate the completion', | ||
EShapeType::Enum | ||
), | ||
]; | ||
} | ||
|
||
public function getOptionalInputShapeEnumValues(): array { | ||
return [ | ||
'model' => [ | ||
new ShapeEnumValue('Model 1', 'model_1'), | ||
new ShapeEnumValue('Model 2', 'model_2'), | ||
new ShapeEnumValue('Model 3', 'model_3'), | ||
], | ||
]; | ||
} | ||
|
||
public function getOptionalInputShapeDefaults(): array { | ||
return [ | ||
'max_tokens' => 4321, | ||
'model' => 'model_2', | ||
]; | ||
} | ||
|
||
public function getOutputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalOutputShape(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalOutputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function process(?string $userId, array $input, callable $reportProgress): array { | ||
if ( | ||
!isset($input['style_input']) || !is_string($input['style_input']) | ||
|| !isset($input['source_input']) || !is_string($input['source_input']) | ||
) { | ||
throw new RuntimeException('Invalid inputs'); | ||
} | ||
$writingStyle = $input['style_input']; | ||
$sourceMaterial = $input['source_input']; | ||
|
||
if (isset($input['model']) && is_string($input['model'])) { | ||
$model = $input['model']; | ||
} else { | ||
$model = 'unknown model'; | ||
} | ||
|
||
$maxTokens = null; | ||
if (isset($input['max_tokens']) && is_int($input['max_tokens'])) { | ||
$maxTokens = $input['max_tokens']; | ||
} | ||
|
||
$fakeResult = 'This is a fake result: ' | ||
. "\n\n- Style input: " . $writingStyle | ||
. "\n- Source input: " . $sourceMaterial | ||
. "\n- Model: " . $model | ||
. "\n- Maximum number of words: " . $maxTokens; | ||
Check notice Code scanning / Psalm PossiblyNullOperand Note test
Cannot concatenate with a possibly null int|null
|
||
|
||
return ['output' => $fakeResult]; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
apps/testing/lib/TaskProcessing/FakeTextToImageProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Testing\TaskProcessing; | ||
|
||
use OCA\Testing\AppInfo\Application; | ||
use OCP\TaskProcessing\EShapeType; | ||
use OCP\TaskProcessing\ISynchronousProvider; | ||
use OCP\TaskProcessing\ShapeDescriptor; | ||
use OCP\TaskProcessing\TaskTypes\TextToImage; | ||
use RuntimeException; | ||
|
||
class FakeTextToImageProvider implements ISynchronousProvider { | ||
|
||
public function __construct() { | ||
} | ||
|
||
public function getId(): string { | ||
return Application::APP_ID . '-text2image'; | ||
} | ||
|
||
public function getName(): string { | ||
return 'Fake text2image task processing provider'; | ||
} | ||
|
||
public function getTaskTypeId(): string { | ||
return TextToImage::ID; | ||
} | ||
|
||
public function getExpectedRuntime(): int { | ||
return 1; | ||
} | ||
|
||
public function getInputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function getInputShapeDefaults(): array { | ||
return [ | ||
'numberOfImages' => 1, | ||
]; | ||
} | ||
|
||
public function getOptionalInputShape(): array { | ||
return [ | ||
'size' => new ShapeDescriptor( | ||
'Size', | ||
'Optional. The size of the generated images. Must be in 256x256 format.', | ||
EShapeType::Text | ||
), | ||
]; | ||
} | ||
|
||
public function getOptionalInputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalInputShapeDefaults(): array { | ||
return []; | ||
} | ||
|
||
public function getOutputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalOutputShape(): array { | ||
return []; | ||
} | ||
|
||
public function getOptionalOutputShapeEnumValues(): array { | ||
return []; | ||
} | ||
|
||
public function process(?string $userId, array $input, callable $reportProgress): array { | ||
if (!isset($input['input']) || !is_string($input['input'])) { | ||
throw new RuntimeException('Invalid prompt'); | ||
} | ||
$prompt = $input['input']; | ||
|
||
$nbImages = 1; | ||
if (isset($input['numberOfImages']) && is_int($input['numberOfImages'])) { | ||
$nbImages = $input['numberOfImages']; | ||
} | ||
|
||
$fakeContent = file_get_contents(__DIR__ . '/../../img/logo.png'); | ||
|
||
$output = ['images' => []]; | ||
foreach (range(1, $nbImages) as $i) { | ||
$output['images'][] = $fakeContent; | ||
} | ||
/** @var array<string, list<numeric|string>|numeric|string> $output */ | ||
return $output; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Psalm
DeprecatedMethod Note test