lwazi 1.8.2 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Services/LwaziService.php +36 -14
package/package.json
CHANGED
|
@@ -93,10 +93,20 @@ class LwaziService
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
$
|
|
97
|
-
|
|
98
|
-
$
|
|
99
|
-
|
|
96
|
+
if ($intent === 'content') {
|
|
97
|
+
$contentResponse = $this->searchContent($message);
|
|
98
|
+
if ($contentResponse) {
|
|
99
|
+
$this->conversationHistory[] = ['role' => 'assistant', 'content' => $contentResponse];
|
|
100
|
+
return $contentResponse;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ($intent === 'data') {
|
|
105
|
+
$dataResponse = $this->fetchRelevantData($message);
|
|
106
|
+
if ($dataResponse) {
|
|
107
|
+
$this->conversationHistory[] = ['role' => 'assistant', 'content' => $dataResponse];
|
|
108
|
+
return $dataResponse;
|
|
109
|
+
}
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
$prompt = $this->buildPrompt();
|
|
@@ -315,23 +325,35 @@ class LwaziService
|
|
|
315
325
|
protected function findBestRouteWithTerms(array $routes, array $terms): ?string
|
|
316
326
|
{
|
|
317
327
|
$scored = [];
|
|
328
|
+
$termSet = array_filter(array_map('strtolower', array_map('trim', $terms)), fn($t) => strlen($t) >= 3);
|
|
329
|
+
|
|
330
|
+
if (empty($termSet)) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
|
|
318
334
|
foreach ($routes as $r) {
|
|
319
335
|
$uri = strtolower($r['uri'] ?? '');
|
|
320
|
-
if ($uri === '') continue;
|
|
336
|
+
if ($uri === '' || $uri === '/') continue;
|
|
321
337
|
|
|
338
|
+
$uriClean = preg_replace('/[^a-z0-9]/', '', $uri);
|
|
339
|
+
|
|
340
|
+
$hasExactMatch = false;
|
|
322
341
|
$score = 0;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
342
|
+
|
|
343
|
+
foreach ($termSet as $term) {
|
|
344
|
+
$termClean = preg_replace('/[^a-z0-9]/', '', $term);
|
|
345
|
+
|
|
346
|
+
if (strlen($termClean) < 3) continue;
|
|
347
|
+
|
|
348
|
+
if ($uri === '/' . $term || $uri === $term || str_contains($uri, '/' . $term . '/')) {
|
|
349
|
+
$hasExactMatch = true;
|
|
350
|
+
$score += 50;
|
|
351
|
+
} elseif (!empty($termClean) && str_contains($uriClean, $termClean)) {
|
|
352
|
+
$score += 5;
|
|
331
353
|
}
|
|
332
354
|
}
|
|
333
355
|
|
|
334
|
-
if ($score > 0) {
|
|
356
|
+
if ($hasExactMatch && $score > 0) {
|
|
335
357
|
$scored[] = ['uri' => $r['uri'], 'score' => $score];
|
|
336
358
|
}
|
|
337
359
|
}
|