88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\GigaChat\TaskProcessing;
|
|
|
|
use OCA\GigaChat\Service\GigaChatService;
|
|
|
|
use OCP\Files\File;
|
|
use OCP\Files\IAppData;
|
|
use OCP\TaskProcessing\ISynchronousProvider;
|
|
use OCP\TaskProcessing\TaskTypes\TextToTextChat;
|
|
use OCP\IL10N;
|
|
|
|
class GigachatProvider implements ISynchronousProvider {
|
|
|
|
public function __construct(
|
|
private GigaChatService $gigachat,
|
|
) {
|
|
}
|
|
|
|
public function getId(): string {
|
|
return 'gigachat_integration:summary';
|
|
}
|
|
|
|
public function getName(): string {
|
|
return 'GigaChat provider';
|
|
}
|
|
|
|
public function getTaskTypeId(): string {
|
|
return TextToTextChat::ID;
|
|
}
|
|
|
|
public function process(?string $userId, array $input, callable $reportProgress): array {
|
|
$result = [];
|
|
|
|
$history = [];
|
|
foreach ($input['history'] as $message) {
|
|
$message_data = json_decode($message, true);
|
|
$message_data['role'] = ($message_data['role'] == 'human') ? 'user' : $message_data['role'];
|
|
if (in_array($message_data['role'], $this->gigachat::ROLES)){
|
|
$history[] = $message_data;
|
|
}
|
|
}
|
|
try {
|
|
$result = ['output' => $this->gigachat->get_response($input['input'], $history)];
|
|
} catch (Exception $e) {
|
|
throw new \Exception('Error getting GigaChat service response');
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function getExpectedRuntime(): int {
|
|
return 60;
|
|
}
|
|
|
|
public function getInputShapeDefaults(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOptionalInputShape(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOptionalInputShapeDefaults(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOptionalOutputShape(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getInputShapeEnumValues(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOptionalInputShapeEnumValues(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOutputShapeEnumValues(): array {
|
|
return [];
|
|
}
|
|
|
|
public function getOptionalOutputShapeEnumValues(): array {
|
|
return [];
|
|
}
|
|
} |