Skip to content

Commit

Permalink
replace usage of enum with string and update gh workflows
Browse files Browse the repository at this point in the history
gh workflows now check run the check on php 8.0 in addition to
8.1 and 8.2.
Also, --no-cache option for psalm

Signed-off-by: Anupam Kumar <[email protected]>
  • Loading branch information
kyteinsky committed Feb 29, 2024
1 parent f47932b commit 358b69e
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

strategy:
matrix:
php-versions: [ "8.1", "8.2" ]
php-versions: [ "8.0", "8.1", "8.2" ]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

strategy:
matrix:
php-versions: [ "8.1", "8.2" ]
php-versions: [ "8.0", "8.1", "8.2" ]

name: php-lint

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
databases: ['sqlite']
server-versions: ['master']

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
server-versions: [ 'dev-master', 'stable28' ]
fail-fast: false

name: Nextcloud
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^8.1 || ^8.2"
"php": "^8.0 || ^8.1 || ^8.2"
},
"require-dev": {
"nextcloud/coding-standard": "^1.1",
Expand All @@ -32,7 +32,7 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --threads=1",
"psalm": "psalm.phar --threads=1 --no-cache",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
Expand All @@ -43,7 +43,7 @@
"optimize-autoloader": true,
"classmap-authoritative": true,
"platform": {
"php": "8.1"
"php": "8.0"
}
},
"autoload": {
Expand Down
194 changes: 101 additions & 93 deletions composer.lock

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions lib/Command/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)',
);
}

Expand All @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions lib/Service/LangRopeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string> $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,
Expand Down
8 changes: 3 additions & 5 deletions lib/TextProcessing/ScopedContextChatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'],
);

Expand Down
4 changes: 2 additions & 2 deletions stubs/appapi-public-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace OCA\AppAPI {
class PublicFunctions {
public function __construct(
private readonly \OCA\AppAPI\Service\ExAppService $exAppService,
private readonly \OCA\AppAPI\Service\AppAPIService $service,
private \OCA\AppAPI\Service\ExAppService $exAppService,
private \OCA\AppAPI\Service\AppAPIService $service,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require_once __DIR__ . '/../../../tests/bootstrap.php';
require_once __DIR__ . '/../vendor/autoload.php';

use \OCA\ContextChat\AppInfo\Application;
use \OCP\App\IAppManager;
use \OCP\Server;
use OCA\ContextChat\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\Server;

Server::get(IAppManager::class)->loadApp(Application::APP_ID);
OC_Hook::clear();

0 comments on commit 358b69e

Please sign in to comment.