Skip to content

Commit 4e2df90

Browse files
committed
feat: add limit input to search task type
Signed-off-by: Julien Veyssier <[email protected]>
1 parent b63613f commit 4e2df90

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

lib/Service/LangRopeService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ public function query(string $userId, string $prompt, bool $useContext = true, ?
339339
* @param string $prompt
340340
* @param ?string $scopeType
341341
* @param ?array<string> $scopeList
342+
* @param int|null $limit
342343
* @return array
343-
* @throws RuntimeException
344344
*/
345-
public function docSearch(string $userId, string $prompt, ?string $scopeType = null, ?array $scopeList = null): array {
345+
public function docSearch(string $userId, string $prompt, ?string $scopeType = null, ?array $scopeList = null, ?int $limit = null): array {
346346
$params = [
347347
'query' => $prompt,
348348
'userId' => $userId,
@@ -351,6 +351,9 @@ public function docSearch(string $userId, string $prompt, ?string $scopeType = n
351351
$params['scopeType'] = $scopeType;
352352
$params['scopeList'] = $scopeList;
353353
}
354+
if ($limit !== null) {
355+
$params['ctxLimit'] = $limit;
356+
}
354357

355358
return $this->requestToExApp('/docSearch', 'POST', $params);
356359
}

lib/TaskProcessing/ContextChatSearchProvider.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function getInputShapeEnumValues(): array {
4848
}
4949

5050
public function getInputShapeDefaults(): array {
51-
return [];
51+
return [
52+
'limit' => 10,
53+
];
5254
}
5355

5456
public function getOptionalInputShape(): array {
@@ -89,6 +91,11 @@ public function process(?string $userId, array $input, callable $reportProgress)
8991
throw new \RuntimeException('Invalid input, expected "prompt" key with string value');
9092
}
9193

94+
if (!isset($input['limit']) || !is_numeric($input['limit'])) {
95+
throw new \RuntimeException('Invalid input, expected "limit" key with number value');
96+
}
97+
$limit = (int)$input['limit'];
98+
9299
if (
93100
!isset($input['scopeType']) || !is_string($input['scopeType'])
94101
|| !isset($input['scopeList']) || !is_array($input['scopeList'])
@@ -108,7 +115,13 @@ public function process(?string $userId, array $input, callable $reportProgress)
108115

109116
// unscoped query
110117
if ($input['scopeType'] === ScopeType::NONE) {
111-
$response = $this->langRopeService->docSearch($userId, $input['prompt']);
118+
$response = $this->langRopeService->docSearch(
119+
$userId,
120+
$input['prompt'],
121+
null,
122+
null,
123+
$limit,
124+
);
112125
if (isset($response['error'])) {
113126
throw new \RuntimeException('No result in ContextChat response. ' . $response['error']);
114127
}
@@ -139,6 +152,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
139152
$input['prompt'],
140153
$input['scopeType'],
141154
$processedScopes,
155+
$limit,
142156
);
143157

144158
return $this->processResponse($userId, $response);
@@ -154,7 +168,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
154168
*/
155169
private function processResponse(string $userId, array $response): array {
156170
if (isset($response['error'])) {
157-
throw new \RuntimeException('No result in ContextChat response: ' . $response['error']);
171+
throw new \RuntimeException('Error received in ContextChat document search request: ' . $response['error']);
158172
}
159173
if (!array_is_list($response)) {
160174
throw new \RuntimeException('Invalid response from ContextChat, expected a list: ' . json_encode($response));

lib/TaskProcessing/ContextChatSearchTaskType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function getInputShape(): array {
7373
$this->l->t('Required to nicely render the scope list in assistant'),
7474
EShapeType::Text,
7575
),
76+
'limit' => new ShapeDescriptor(
77+
$this->l->t('Max result number'),
78+
$this->l->t('Maximum number of results returned by Context Chat'),
79+
EShapeType::Number,
80+
),
7681
];
7782
}
7883

0 commit comments

Comments
 (0)