ninegrid2 6.546.0 → 6.549.0

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.
@@ -124,6 +124,11 @@ class aiContainer extends HTMLElement
124
124
  }
125
125
  };
126
126
 
127
+ #extractJsonSnippet = (text) => {
128
+ const match = text.match(/```json([\s\S]*?)```/);
129
+ return match ? match[1].trim() : text;
130
+ };
131
+
127
132
 
128
133
  #generateQdrantFilter = async () => {
129
134
 
@@ -168,9 +173,49 @@ class aiContainer extends HTMLElement
168
173
  new HumanMessage(prompt),
169
174
  ]);
170
175
 
171
- console.log(response);
176
+ //console.log(response);
177
+
178
+ /**
179
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
180
+ if (elSettings) {
181
+ switch (elSettings.server) {
182
+ case "ollama":
183
+ this.#model = new Ollama({
184
+ model: elSettings.model,
185
+ host: elSettings.ollamaUrl,
186
+ });
187
+ break;
188
+ }
189
+ } */
190
+
191
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
192
+ if (!elSettings) throw new Error("nx-ai-settings missing !!!");
193
+
194
+ console.log(response);
172
195
 
173
- let filterString = response.content.trim();
196
+ let filterString;
197
+ switch (elSettings.server) {
198
+ case "openai":
199
+ filterString = this.#extractJsonSnippet(response.content.trim());
200
+ break;
201
+ case "gemini":
202
+ filterString = this.#extractJsonSnippet(response.content.trim());
203
+ break;
204
+ case "ollama":
205
+ filterString = this.#extractJsonSnippet(response);
206
+ break;
207
+ default:
208
+ break;
209
+ }
210
+
211
+ console.log(filterString);
212
+
213
+ return JSON.parse(filterString);
214
+
215
+
216
+
217
+
218
+ //let filterString = response.content.trim();
174
219
  if (filterString.startsWith("```json")) {
175
220
  filterString = filterString.replace("```json", "");
176
221
  const idx = filterString.indexOf("```");
@@ -360,7 +405,6 @@ class aiContainer extends HTMLElement
360
405
 
361
406
  const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
362
407
 
363
-
364
408
  elAiChat.add("me", question);
365
409
  elAiChat.add("ing", question);
366
410
 
@@ -54325,6 +54325,11 @@ class aiContainer extends HTMLElement
54325
54325
  }
54326
54326
  };
54327
54327
 
54328
+ #extractJsonSnippet = (text) => {
54329
+ const match = text.match(/```json([\s\S]*?)```/);
54330
+ return match ? match[1].trim() : text;
54331
+ };
54332
+
54328
54333
 
54329
54334
  #generateQdrantFilter = async () => {
54330
54335
 
@@ -54369,25 +54374,42 @@ class aiContainer extends HTMLElement
54369
54374
  new messages.HumanMessage(prompt),
54370
54375
  ]);
54371
54376
 
54372
- console.log(response);
54377
+ //console.log(response);
54373
54378
 
54374
- let filterString = response.content.trim();
54375
- if (filterString.startsWith("```json")) {
54376
- filterString = filterString.replace("```json", "");
54377
- const idx = filterString.indexOf("```");
54378
- if (idx > 0) {
54379
- filterString = filterString.substring(0, idx);
54380
- //console.log(filterString.substring(idx+3));
54379
+ /**
54380
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
54381
+ if (elSettings) {
54382
+ switch (elSettings.server) {
54383
+ case "ollama":
54384
+ this.#model = new Ollama({
54385
+ model: elSettings.model,
54386
+ host: elSettings.ollamaUrl,
54387
+ });
54388
+ break;
54381
54389
  }
54382
- }
54383
- //filterString = filterString.replaceAll('"value"', '"text"')
54384
- console.log("Generated Filter String:", filterString);
54390
+ } */
54391
+
54392
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
54393
+ if (!elSettings) throw new Error("nx-ai-settings missing !!!");
54394
+
54395
+ console.log(response);
54396
+
54397
+ let filterString;
54398
+ switch (elSettings.server) {
54399
+ case "openai":
54400
+ filterString = this.#extractJsonSnippet(response.content.trim());
54401
+ break;
54402
+ case "gemini":
54403
+ filterString = this.#extractJsonSnippet(response.content.trim());
54404
+ break;
54405
+ case "ollama":
54406
+ filterString = this.#extractJsonSnippet(response);
54407
+ break;
54408
+ }
54385
54409
 
54386
- // Gemini가 JSON 모드나 Structured Output을 지원하지 않는 경우, 직접 파싱 시도
54387
- // 안정적인 JSON 파싱을 위해 'JSON Mode' 또는 Function Calling 사용을 강력히 권장
54388
- // LangChain의 SelfQueryRetriever를 사용하면 이 부분을 자동화할 수 있습니다.
54389
- //try {
54390
- return JSON.parse(filterString);
54410
+ console.log(filterString);
54411
+
54412
+ return JSON.parse(filterString);
54391
54413
  //} catch (parseError) {
54392
54414
  // console.error("Failed to parse filter string as JSON:", parseError);
54393
54415
  // console.error("String that failed to parse:", filterString);
@@ -54536,7 +54558,6 @@ class aiContainer extends HTMLElement
54536
54558
 
54537
54559
  const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
54538
54560
 
54539
-
54540
54561
  elAiChat.add("me", question);
54541
54562
  elAiChat.add("ing", question);
54542
54563
 
@@ -54323,6 +54323,11 @@ class aiContainer extends HTMLElement
54323
54323
  }
54324
54324
  };
54325
54325
 
54326
+ #extractJsonSnippet = (text) => {
54327
+ const match = text.match(/```json([\s\S]*?)```/);
54328
+ return match ? match[1].trim() : text;
54329
+ };
54330
+
54326
54331
 
54327
54332
  #generateQdrantFilter = async () => {
54328
54333
 
@@ -54367,25 +54372,42 @@ class aiContainer extends HTMLElement
54367
54372
  new HumanMessage(prompt),
54368
54373
  ]);
54369
54374
 
54370
- console.log(response);
54375
+ //console.log(response);
54371
54376
 
54372
- let filterString = response.content.trim();
54373
- if (filterString.startsWith("```json")) {
54374
- filterString = filterString.replace("```json", "");
54375
- const idx = filterString.indexOf("```");
54376
- if (idx > 0) {
54377
- filterString = filterString.substring(0, idx);
54378
- //console.log(filterString.substring(idx+3));
54377
+ /**
54378
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
54379
+ if (elSettings) {
54380
+ switch (elSettings.server) {
54381
+ case "ollama":
54382
+ this.#model = new Ollama({
54383
+ model: elSettings.model,
54384
+ host: elSettings.ollamaUrl,
54385
+ });
54386
+ break;
54379
54387
  }
54380
- }
54381
- //filterString = filterString.replaceAll('"value"', '"text"')
54382
- console.log("Generated Filter String:", filterString);
54388
+ } */
54389
+
54390
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
54391
+ if (!elSettings) throw new Error("nx-ai-settings missing !!!");
54392
+
54393
+ console.log(response);
54394
+
54395
+ let filterString;
54396
+ switch (elSettings.server) {
54397
+ case "openai":
54398
+ filterString = this.#extractJsonSnippet(response.content.trim());
54399
+ break;
54400
+ case "gemini":
54401
+ filterString = this.#extractJsonSnippet(response.content.trim());
54402
+ break;
54403
+ case "ollama":
54404
+ filterString = this.#extractJsonSnippet(response);
54405
+ break;
54406
+ }
54383
54407
 
54384
- // Gemini가 JSON 모드나 Structured Output을 지원하지 않는 경우, 직접 파싱 시도
54385
- // 안정적인 JSON 파싱을 위해 'JSON Mode' 또는 Function Calling 사용을 강력히 권장
54386
- // LangChain의 SelfQueryRetriever를 사용하면 이 부분을 자동화할 수 있습니다.
54387
- //try {
54388
- return JSON.parse(filterString);
54408
+ console.log(filterString);
54409
+
54410
+ return JSON.parse(filterString);
54389
54411
  //} catch (parseError) {
54390
54412
  // console.error("Failed to parse filter string as JSON:", parseError);
54391
54413
  // console.error("String that failed to parse:", filterString);
@@ -54534,7 +54556,6 @@ class aiContainer extends HTMLElement
54534
54556
 
54535
54557
  const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
54536
54558
 
54537
-
54538
54559
  elAiChat.add("me", question);
54539
54560
  elAiChat.add("ing", question);
54540
54561
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ninegrid2",
3
3
  "type": "module",
4
- "version": "6.546.0",
4
+ "version": "6.549.0",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
7
7
  "import": "./dist/index.js",
@@ -124,6 +124,11 @@ class aiContainer extends HTMLElement
124
124
  }
125
125
  };
126
126
 
127
+ #extractJsonSnippet = (text) => {
128
+ const match = text.match(/```json([\s\S]*?)```/);
129
+ return match ? match[1].trim() : text;
130
+ };
131
+
127
132
 
128
133
  #generateQdrantFilter = async () => {
129
134
 
@@ -168,9 +173,49 @@ class aiContainer extends HTMLElement
168
173
  new HumanMessage(prompt),
169
174
  ]);
170
175
 
171
- console.log(response);
176
+ //console.log(response);
177
+
178
+ /**
179
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
180
+ if (elSettings) {
181
+ switch (elSettings.server) {
182
+ case "ollama":
183
+ this.#model = new Ollama({
184
+ model: elSettings.model,
185
+ host: elSettings.ollamaUrl,
186
+ });
187
+ break;
188
+ }
189
+ } */
190
+
191
+ const elSettings = this.shadowRoot.querySelector("nx-ai-settings");
192
+ if (!elSettings) throw new Error("nx-ai-settings missing !!!");
193
+
194
+ console.log(response);
172
195
 
173
- let filterString = response.content.trim();
196
+ let filterString;
197
+ switch (elSettings.server) {
198
+ case "openai":
199
+ filterString = this.#extractJsonSnippet(response.content.trim());
200
+ break;
201
+ case "gemini":
202
+ filterString = this.#extractJsonSnippet(response.content.trim());
203
+ break;
204
+ case "ollama":
205
+ filterString = this.#extractJsonSnippet(response);
206
+ break;
207
+ default:
208
+ break;
209
+ }
210
+
211
+ console.log(filterString);
212
+
213
+ return JSON.parse(filterString);
214
+
215
+
216
+
217
+
218
+ //let filterString = response.content.trim();
174
219
  if (filterString.startsWith("```json")) {
175
220
  filterString = filterString.replace("```json", "");
176
221
  const idx = filterString.indexOf("```");
@@ -360,7 +405,6 @@ class aiContainer extends HTMLElement
360
405
 
361
406
  const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
362
407
 
363
-
364
408
  elAiChat.add("me", question);
365
409
  elAiChat.add("ing", question);
366
410