diff --git a/.github/workflows/lint-php-cs.yml b/.github/workflows/lint-php-cs.yml index f708ba0..ff97df2 100644 --- a/.github/workflows/lint-php-cs.yml +++ b/.github/workflows/lint-php-cs.yml @@ -45,7 +45,7 @@ jobs: strategy: matrix: - php-versions: [ "8.1", "8.2" ] + php-versions: [ "8.0", "8.1", "8.2", "8.3" ] steps: - name: Checkout diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml index b039b9a..6fcda6c 100644 --- a/.github/workflows/lint-php.yml +++ b/.github/workflows/lint-php.yml @@ -47,7 +47,7 @@ jobs: strategy: matrix: - php-versions: [ "8.1", "8.2" ] + php-versions: [ "8.0", "8.1", "8.2", "8.3" ] name: php-lint diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index b1dd380..a3d9145 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -33,7 +33,7 @@ jobs: # do not stop on another job's failure fail-fast: false matrix: - php-versions: [ "8.1", "8.2" ] + php-versions: [ "8.0", "8.1", "8.2", "8.3" ] databases: ['sqlite'] server-versions: ['master'] diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 7bf9fda..244bbf1 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -30,8 +30,8 @@ jobs: strategy: matrix: - php-versions: [ '8.1', '8.2' ] - server-versions: [ 'dev-master', 'dev-stable28' ] + php-versions: [ "8.0", "8.1", "8.2", "8.3" ] + server-versions: [ 'dev-master', 'stable28' ] fail-fast: false name: Nextcloud diff --git a/lib/Command/Prompt.php b/lib/Command/Prompt.php index 1d5da0f..286777c 100644 --- a/lib/Command/Prompt.php +++ b/lib/Command/Prompt.php @@ -12,7 +12,6 @@ namespace OCA\ContextChat\Command; -use OCA\ContextChat\Service\ScopeType; use OCA\ContextChat\TextProcessing\ContextChatTaskType; use OCA\ContextChat\TextProcessing\ScopedContextChatTaskType; use OCP\TextProcessing\FreePromptTaskType; @@ -55,13 +54,13 @@ protected function configure() { 'context-sources', null, InputOption::VALUE_REQUIRED, - 'Context sources to use', + 'Context sources to use (as a comma-separated list without brackets)', ) ->addOption( 'context-providers', null, InputOption::VALUE_REQUIRED, - 'Context provider to use', + 'Context providers to use (as a comma-separated list without brackets)', ); } @@ -83,15 +82,19 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($noContext) { $task = new Task(FreePromptTaskType::class, $prompt, 'context_chat', $userId); } elseif (!empty($contextSources)) { + $contextSources = preg_replace('/\s*,+\s*/', ',', $contextSources); + $contextSourcesArray = array_filter(explode(',', $contextSources), fn ($source) => !empty($source)); $task = new Task(ScopedContextChatTaskType::class, json_encode([ - 'scopeType' => ScopeType::SOURCE, - 'scopeList' => explode(',', $contextSources), + 'scopeType' => 'source', + 'scopeList' => $contextSourcesArray, 'prompt' => $prompt, ]), 'context_chat', $userId); } elseif (!empty($contextProviders)) { + $contextProviders = preg_replace('/\s*,+\s*/', ',', $contextProviders); + $contextProvidersArray = array_filter(explode(',', $contextProviders), fn ($source) => !empty($source)); $task = new Task(ScopedContextChatTaskType::class, json_encode([ - 'scopeType' => ScopeType::PROVIDER, - 'scopeList' => explode(',', $contextProviders), + 'scopeType' => 'provider', + 'scopeList' => $contextProvidersArray, 'prompt' => $prompt, ]), 'context_chat', $userId); } else { diff --git a/lib/Service/LangRopeService.php b/lib/Service/LangRopeService.php index 1f57d1e..7040110 100644 --- a/lib/Service/LangRopeService.php +++ b/lib/Service/LangRopeService.php @@ -27,11 +27,6 @@ use Psr\Log\LoggerInterface; use RuntimeException; -enum ScopeType: string { - case PROVIDER = 'provider'; - case SOURCE = 'source'; -} - class LangRopeService { public function __construct( private LoggerInterface $logger, @@ -195,11 +190,11 @@ public function query(string $userId, string $prompt, bool $useContext = true): /** * @param string $userId * @param string $prompt - * @param ScopeType $scopeType + * @param string $scopeType * @param array $scopeList * @return array */ - public function scopedQuery(string $userId, string $prompt, ScopeType $scopeType, array $scopeList): array { + public function scopedQuery(string $userId, string $prompt, string $scopeType, array $scopeList): array { $params = [ 'query' => $prompt, 'userId' => $userId, diff --git a/lib/TextProcessing/ScopedContextChatProvider.php b/lib/TextProcessing/ScopedContextChatProvider.php index 60398ba..aeae6bd 100644 --- a/lib/TextProcessing/ScopedContextChatProvider.php +++ b/lib/TextProcessing/ScopedContextChatProvider.php @@ -4,7 +4,6 @@ namespace OCA\ContextChat\TextProcessing; use OCA\ContextChat\Service\LangRopeService; -use OCA\ContextChat\Service\ScopeType; use OCP\IL10N; use OCP\TextProcessing\IProvider; use OCP\TextProcessing\IProviderWithUserId; @@ -63,15 +62,14 @@ public function process(string $prompt): string { throw new \RuntimeException('Invalid JSON string, expected { "scopeType": string, "scopeList": list[string], "prompt": string }'); } - $scopeTypeEnum = ScopeType::tryFrom($parsedData['scopeType']); - if ($scopeTypeEnum === null) { - throw new \RuntimeException('Invalid scope type: ' . $parsedData['scopeType']); + if (!in_array($parsedData['scopeType'], ['source', 'provider'])) { + throw new \RuntimeException("Invalid scope type: {$parsedData['scopeType']}, should be 'source' or 'provider'"); } $response = $this->langRopeService->scopedQuery( $this->userId, $parsedData['prompt'], - $scopeTypeEnum, + $parsedData['scopeType'], $parsedData['scopeList'], );