Skip to content

Commit 9935034

Browse files
committed
LLM OCP API: Add @SInCE
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent b6a95e3 commit 9935034

6 files changed

Lines changed: 94 additions & 3 deletions

File tree

lib/public/LanguageModel/AbstractLanguageModelTask.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44

55
use OC\LanguageModel\Db\Task;
66

7+
/**
8+
* @since 28.0.0
9+
*/
710
abstract class AbstractLanguageModelTask implements ILanguageModelTask {
811
protected ?int $id;
912
protected ?string $output;
1013
protected int $status = ILanguageModelTask::STATUS_UNKNOWN;
1114

15+
/**
16+
* @param string $input
17+
* @param string $appId
18+
* @param string|null $userId
19+
* @since 28.0.0
20+
*/
1221
final public function __construct(
1322
protected string $input,
1423
protected string $appId,
@@ -20,76 +29,99 @@ final public function __construct(
2029
* @param ILanguageModelProvider $provider
2130
* @return string
2231
* @throws \RuntimeException
32+
* @since 28.0.0
2333
*/
2434
abstract public function visitProvider(ILanguageModelProvider $provider): string;
2535

36+
/**
37+
* @param ILanguageModelProvider $provider
38+
* @return bool
39+
* @since 28.0.0
40+
*/
2641
abstract public function canUseProvider(ILanguageModelProvider $provider): bool;
2742

43+
/**
44+
* @return string
45+
* @since 28.0.0
46+
*/
2847
abstract public function getType(): string;
2948

3049
/**
3150
* @return string|null
51+
* @since 28.0.0
3252
*/
3353
final public function getOutput(): ?string {
3454
return $this->output;
3555
}
3656

3757
/**
3858
* @param string|null $output
59+
* @since 28.0.0
3960
*/
4061
final public function setOutput(?string $output): void {
4162
$this->output = $output;
4263
}
4364

4465
/**
4566
* @return int
67+
* @since 28.0.0
4668
*/
4769
final public function getStatus(): int {
4870
return $this->status;
4971
}
5072

5173
/**
5274
* @param int $status
75+
* @since 28.0.0
5376
*/
5477
final public function setStatus(int $status): void {
5578
$this->status = $status;
5679
}
5780

5881
/**
5982
* @return int|null
83+
* @since 28.0.0
6084
*/
6185
final public function getId(): ?int {
6286
return $this->id;
6387
}
6488

6589
/**
6690
* @param int|null $id
91+
* @since 28.0.0
6792
*/
6893
final public function setId(?int $id): void {
6994
$this->id = $id;
7095
}
7196

7297
/**
7398
* @return string
99+
* @since 28.0.0
74100
*/
75101
final public function getInput(): string {
76102
return $this->input;
77103
}
78104

79105
/**
80106
* @return string
107+
* @since 28.0.0
81108
*/
82109
final public function getAppId(): string {
83110
return $this->appId;
84111
}
85112

86113
/**
87114
* @return string|null
115+
* @since 28.0.0
88116
*/
89117
final public function getUserId(): ?string {
90118
return $this->userId;
91119
}
92120

121+
/**
122+
* @return array
123+
* @since 28.0.0
124+
*/
93125
public function jsonSerialize() {
94126
return [
95127
'id' => $this->getId(),
@@ -103,6 +135,11 @@ public function jsonSerialize() {
103135
}
104136

105137

138+
/**
139+
* @param Task $taskEntity
140+
* @return ILanguageModelTask
141+
* @since 28.0.0
142+
*/
106143
final public static function fromTaskEntity(Task $taskEntity): ILanguageModelTask {
107144
$task = self::factory($taskEntity->getType(), $taskEntity->getInput(), $taskEntity->getuserId(), $taskEntity->getAppId());
108145
$task->setId($taskEntity->getId());
@@ -117,6 +154,7 @@ final public static function fromTaskEntity(Task $taskEntity): ILanguageModelTas
117154
* @param string $appId
118155
* @return ILanguageModelTask
119156
* @throws \InvalidArgumentException
157+
* @since 28.0.0
120158
*/
121159
final public static function factory(string $type, string $input, ?string $userId, string $appId): ILanguageModelTask {
122160
if (!in_array($type, self::TYPES)) {

lib/public/LanguageModel/Events/TaskFailedEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(ILanguageModelTask $task,
1515

1616
/**
1717
* @return string
18+
* @since 28.0.0
1819
*/
1920
public function getErrorMessage(): string {
2021
return $this->errorMessage;

lib/public/LanguageModel/FreePromptTask.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
use RuntimeException;
66

7+
/**
8+
* @since 28.0.0
9+
*/
710
final class FreePromptTask extends AbstractLanguageModelTask {
11+
/**
12+
* @since 28.0.0
13+
*/
814
public const TYPE = 'free_prompt';
915

1016
/**
11-
* @param ILanguageModelProvider $provider
12-
* @throws RuntimeException
13-
* @return string
17+
* @inheritDoc
1418
*/
1519
public function visitProvider(ILanguageModelProvider $provider): string {
1620
return $provider->prompt($this->getInput());

lib/public/LanguageModel/HeadlineTask.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
use RuntimeException;
66

7+
/**
8+
* @since 28.0.0
9+
*/
710
final class HeadlineTask extends AbstractLanguageModelTask {
11+
/**
12+
* @since 28.0.0
13+
*/
814
public const TYPE = 'headline';
915

1016
/**

lib/public/LanguageModel/ILanguageModelManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function scheduleTask(ILanguageModelTask $task) : void;
6868
* @return ILanguageModelTask
6969
* @throws RuntimeException If the query failed
7070
* @throws \ValueError If the task could not be found
71+
* @since 28.0.0
7172
*/
7273
public function getTask(int $id): ILanguageModelTask;
7374
}

lib/public/LanguageModel/ILanguageModelTask.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,113 @@
22

33
namespace OCP\LanguageModel;
44

5+
/**
6+
* @since 28.0.0
7+
*/
58
interface ILanguageModelTask extends \JsonSerializable {
9+
/**
10+
* @since 28.0.0
11+
*/
612
public const STATUS_FAILED = 4;
13+
/**
14+
* @since 28.0.0
15+
*/
716
public const STATUS_SUCCESSFUL = 3;
17+
/**
18+
* @since 28.0.0
19+
*/
820
public const STATUS_RUNNING = 2;
21+
/**
22+
* @since 28.0.0
23+
*/
924
public const STATUS_SCHEDULED = 1;
25+
/**
26+
* @since 28.0.0
27+
*/
1028
public const STATUS_UNKNOWN = 0;
1129

30+
/**
31+
* @since 28.0.0
32+
*/
1233
public const TYPES = [
1334
FreePromptTask::TYPE => FreePromptTask::class,
1435
SummaryTask::TYPE => SummaryTask::class,
1536
HeadlineTask::TYPE => HeadlineTask::class,
1637
TopicsTask::TYPE => TopicsTask::class,
1738
];
1839

40+
/**
41+
* @param ILanguageModelProvider $provider
42+
* @return string
43+
* @since 28.0.0
44+
*/
1945
public function visitProvider(ILanguageModelProvider $provider): string;
2046

47+
/**
48+
* @param ILanguageModelProvider $provider
49+
* @return bool
50+
* @since 28.0.0
51+
*/
2152
public function canUseProvider(ILanguageModelProvider $provider): bool;
2253

2354

2455
/**
2556
* @return string
57+
* @since 28.0.0
2658
*/
2759
public function getType(): string;
2860

2961
/**
3062
* @return int
63+
* @since 28.0.0
3164
*/
3265
public function getStatus(): int;
3366

3467
/**
3568
* @param int $status
69+
* @since 28.0.0
3670
*/
3771
public function setStatus(int $status): void;
3872

3973
/**
4074
* @param int|null $id
75+
* @since 28.0.0
4176
*/
4277
public function setId(?int $id): void;
4378

4479
/**
4580
* @return int|null
81+
* @since 28.0.0
4682
*/
4783
public function getId(): ?int;
4884

4985
/**
5086
* @return string
87+
* @since 28.0.0
5188
*/
5289
public function getInput(): string;
5390

5491
/**
5592
* @param string|null $output
93+
* @since 28.0.0
5694
*/
5795
public function setOutput(?string $output): void;
5896

5997
/**
6098
* @return null|string
99+
* @since 28.0.0
61100
*/
62101
public function getOutput(): ?string;
63102

64103
/**
65104
* @return string
105+
* @since 28.0.0
66106
*/
67107
public function getAppId(): string;
68108

69109
/**
70110
* @return string|null
111+
* @since 28.0.0
71112
*/
72113
public function getUserId(): ?string;
73114
}

0 commit comments

Comments
 (0)