Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
prepare text processing and speech-to-text files
  • Loading branch information
andrey18106 committed Aug 24, 2023
commit 55df81d2979d161d2c7c9326d8ed450b913ab5f6
6 changes: 6 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@
// Talk bots
['name' => 'talkBot#registerExAppTalkBot', 'url' => '/api/v1/talk_bot', 'verb' => 'POST'],
//['name' => 'talkBot#unregisterExAppTalkBot', 'url' => '/api/v1/talk_bot/{id}', 'verb' => 'DELETE'],

// SpeechToText
['name' => 'speechToText#registerProvider', 'url' => '/api/v1/speech_to_text', 'verb' => 'POST'],

// TextProcessing
['name' => 'textProcessing#registerProvider', 'url' => '/api/v1/text_processing', 'verb' => 'POST'],
],
];
5 changes: 5 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use OCA\AppEcosystemV2\Profiler\AEDataCollector;
use OCA\AppEcosystemV2\PublicCapabilities;

use OCA\AppEcosystemV2\SpeechToText\SpeechToTextProvider;
use OCA\AppEcosystemV2\TextProcessing\TextProcessingProvider;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
Expand Down Expand Up @@ -47,6 +49,9 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class);
$context->registerNotifierService(ExAppNotifier::class);
$context->registerNotifierService(ExAppAdminNotifier::class);

$context->registerTextProcessingProvider(TextProcessingProvider::class);
$context->registerSpeechToTextProvider(SpeechToTextProvider::class);
}

public function boot(IBootContext $context): void {
Expand Down
34 changes: 34 additions & 0 deletions lib/Controller/SpeechToTextController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\Controller;

use OCA\AppEcosystemV2\AppInfo\Application;
use OCA\AppEcosystemV2\Service\AppEcosystemV2Service;
use OCA\AppEcosystemV2\Service\SpeechToTextService;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;

class SpeechToTextController extends OCSController {
protected $request;
private AppEcosystemV2Service $service;
private SpeechToTextService $speechToTextService;

public function __construct(
IRequest $request,
AppEcosystemV2Service $service,
SpeechToTextService $speechToTextService,
) {
parent::__construct(Application::APP_ID, $request);

$this->request = $request;
$this->service = $service;
$this->speechToTextService = $speechToTextService;
}

public function registerProvider(): Response {
return new DataResponse();
}
}
30 changes: 30 additions & 0 deletions lib/Controller/TextProcessingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\Controller;

use OCA\AppEcosystemV2\AppInfo\Application;
use OCA\AppEcosystemV2\Service\AppEcosystemV2Service;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;

class TextProcessingController extends OCSController {
protected $request;
private AppEcosystemV2Service $service;

public function __construct(
IRequest $request,
AppEcosystemV2Service $service,
) {
parent::__construct(Application::APP_ID, $request);

$this->request = $request;
$this->service = $service;
}

public function registerProvider(): Response {
return new DataResponse();
}
}
27 changes: 27 additions & 0 deletions lib/Migration/Version1000Date202305221555.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,33 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addUniqueIndex(['appid', 'scope_group'], 'ex_apps_scopes__idx');
}

if (!$schema->hasTable('ex_apps_text_processing')) {
$table = $schema->createTable('ex_apps_text_processing');

$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('appid', Types::STRING, [
'notnull' => true,
'length' => 32,
]);
}
// TODO: Add required field for both TextProcessingProvider and SpeechToText

if (!$schema->hasTable('ex_apps_speech_to_text')) {
$table = $schema->createTable('ex_apps_speech_to_text');

$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('appid', Types::STRING, [
'notnull' => true,
'length' => 32,
]);
}

return $schema;
}
}
13 changes: 13 additions & 0 deletions lib/Service/SpeechToTextService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\Service;

class SpeechToTextService {
public function __construct(

) {

}
}
13 changes: 13 additions & 0 deletions lib/Service/TextProcessingService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\Service;

class TextProcessingService {
public function __construct(

) {

}
}
33 changes: 33 additions & 0 deletions lib/SpeechToText/SpeechToTextProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\SpeechToText;

use OCA\AppEcosystemV2\Service\AppEcosystemV2Service;
use OCP\Files\File;
use OCP\IL10N;
use OCP\SpeechToText\ISpeechToTextProvider;

class SpeechToTextProvider implements ISpeechToTextProvider {

private IL10N $l10n;
private AppEcosystemV2Service $service;

public function __construct(
IL10N $l10n,
AppEcosystemV2Service $service,
) {
$this->l10n = $l10n;
$this->service = $service;
}

public function getName(): string {
return $this->l10n->t('AppEcosystemV2 speech-to-text provider');
}

public function transcribeFile(File $file): string {
// TODO: Pass request to ExApp with file params

}
}
39 changes: 39 additions & 0 deletions lib/TextProcessing/ExAppTaskType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\TextProcessing;

use OCA\AppEcosystemV2\Db\ExFilesActionsMenu;
use OCA\AppEcosystemV2\Service\ExFilesActionsMenuService;
use OCA\AppEcosystemV2\Service\TextProcessingService;
use OCP\IL10N;
use OCP\TextProcessing\ITaskType;

class ExAppTaskType implements ITaskType {
private IL10N $l10n;
private ExFilesActionsMenuService $exFilesActionsMenuService;
private TextProcessingService $textProcessingService;

public function __construct(
IL10N $l10n,
ExFilesActionsMenuService $exFilesActionsMenuService,
TextProcessingService $textProcessingService,
) {
$this->l10n = $l10n;
$this->textProcessingService = $textProcessingService;
$this->exFilesActionsMenuService = $exFilesActionsMenuService;
}

public function getName(): string {
return $this->l10n->t('AppEcosystemV2 ExApp task');
}

public function getDescription(): string {
$fileActions = $this->exFilesActionsMenuService->getRegisteredFileActions();
$availableExAppProviders = join(', ', array_unique(array_map(function (ExFilesActionsMenu $fileActionMenu) {
return $fileActionMenu->getAppid();
}, $fileActions)));
return $this->l10n->t(sprintf('Prompt to registered ExApp TextProcessing provider. Registered ExApps TextProcessing providers: %s. Prompt mast start with [appid]: Your prompt text', $availableExAppProviders));
}
}
30 changes: 30 additions & 0 deletions lib/TextProcessing/TextProcessingProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace OCA\AppEcosystemV2\TextProcessing;

use OCP\IL10N;
use OCP\TextProcessing\IProvider;

class TextProcessingProvider implements IProvider {
private IL10N $l10n;

public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}

public function getName(): string {
return $this->l10n->t('AppEcosystemV2 text processing provider');
}

public function getTaskType(): string {
return ExAppTaskType::class;
}

public function process(string $prompt): string {
// TODO: Pass prompt to registered ExApp

return '';
}
}