lwazi 1.6.6 → 1.6.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lwazi",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "Lwazi is an AI assistant for Laravel. Install with one command to add an AI assistant to your Laravel app.",
5
5
  "main": "bin/lwazi.js",
6
6
  "bin": {
@@ -55,8 +55,7 @@ class ChatController extends Controller
55
55
  $ragService = app(RagService::class);
56
56
  $routes = $ragService->getRouteIndex();
57
57
 
58
- $routeList = array_map(fn($r) => $r['uri'], array_slice($routes, 0, 30));
59
- $prompt = "Extract 3-5 key topic words from this question. Return ONLY valid JSON like: {\"terms\": [\"word1\", \"word2\"]}\n\nQuestion: {$message}";
58
+ $prompt = "What is the single most important word (noun) this user is asking about? Just return the word, nothing else. Question: {$message}";
60
59
 
61
60
  $terms = [];
62
61
  $llmError = null;
@@ -69,7 +68,7 @@ class ChatController extends Controller
69
68
  $response = \Illuminate\Support\Facades\Http::timeout(30)->post($ollamaUrl . '/api/chat', [
70
69
  'model' => $model,
71
70
  'messages' => [
72
- ['role' => 'system', 'content' => 'Return only valid JSON.'],
71
+ ['role' => 'system', 'content' => 'Return only one word.'],
73
72
  ['role' => 'user', 'content' => $prompt],
74
73
  ],
75
74
  'stream' => false,
@@ -78,15 +77,26 @@ class ChatController extends Controller
78
77
  $content = $response->json('message.content', '');
79
78
  $llmRaw = $content;
80
79
 
81
- $json = null;
82
- $start = strpos($content, '{');
83
- $end = strrpos($content, '}');
84
- if ($start !== false && $end !== false && $end > $start) {
85
- $json = json_decode(substr($content, $start, $end - $start + 1), true);
86
- }
87
- $terms = $json['terms'] ?? [];
88
- if (empty($terms) && is_array($json) && isset($json[0])) {
89
- $terms = $json;
80
+ $topic = trim($content);
81
+
82
+ if ($topic) {
83
+ $prompt2 = "List 5 synonyms for: {$topic}. Return ONLY JSON array like: [\"word1\",\"word2\"]";
84
+ $response2 = \Illuminate\Support\Facades\Http::timeout(30)->post($ollamaUrl . '/api/chat', [
85
+ 'model' => $model,
86
+ 'messages' => [
87
+ ['role' => 'system', 'content' => 'Return only valid JSON.'],
88
+ ['role' => 'user', 'content' => $prompt2],
89
+ ],
90
+ 'stream' => false,
91
+ ]);
92
+ $content2 = $response2->json('message.content', '');
93
+ $start = strpos($content2, '[');
94
+ $end = strrpos($content2, ']');
95
+ if ($start !== false && $end !== false && $end > $start) {
96
+ $json = json_decode(substr($content2, $start, $end - $start + 1), true);
97
+ }
98
+ $terms = is_array($json) ? array_values($json) : [];
99
+ $terms[] = strtolower($topic);
90
100
  }
91
101
  } catch (\Exception $e) {
92
102
  $llmError = $e->getMessage();
@@ -38,9 +38,10 @@ class LwaziService
38
38
  {
39
39
  error_log('Lwazi chat: ' . $message);
40
40
 
41
- if ($this->agent->isReady()) {
42
- return $this->agent->reply($message, $this->currentContextId);
43
- }
41
+ // Temporarily disable agent
42
+ // if ($this->agent->isReady()) {
43
+ // return $this->agent->reply($message, $this->currentContextId);
44
+ // }
44
45
 
45
46
  $this->conversationHistory[] = ['role' => 'user', 'content' => $message];
46
47