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 and 8.3 in addition to
8.1 and 8.2.

Signed-off-by: Anupam Kumar <[email protected]>
  • Loading branch information
kyteinsky committed Feb 28, 2024
1 parent f47932b commit 22e6fd6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 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", "8.3" ]

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", "8.3" ]

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", "8.3" ]
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", "8.3" ]
server-versions: [ 'dev-master', 'stable28' ]
fail-fast: false

name: Nextcloud
Expand Down
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

0 comments on commit 22e6fd6

Please sign in to comment.