ninegrid2 6.518.0 → 6.520.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.
@@ -5,6 +5,8 @@ import { ChatOpenAI } from '@langchain/openai';
5
5
  import { HumanMessage, SystemMessage } from '@langchain/core/messages';
6
6
  import { OllamaEmbeddings } from "@langchain/ollama";
7
7
  import { QdrantClient } from "@qdrant/js-client-rest";
8
+ import { StringOutputParser } from "@langchain/core/output_parsers"
9
+ import { PromptTemplate} from "@langchain/core/prompts"
8
10
 
9
11
  class aiContainer extends HTMLElement
10
12
  {
@@ -103,8 +105,16 @@ class aiContainer extends HTMLElement
103
105
  return colInfo;
104
106
  };
105
107
 
108
+ #getUniqueKey = () => {
109
+ if (this.#target.tagName === "NINE-GRID") {
110
+ return this.#target.dataset.unique;
111
+ }
112
+ };
113
+
106
114
 
107
- #generateQdrantFilter = async (userInput) => {
115
+ #generateQdrantFilter = async () => {
116
+
117
+ const userInput = this.shadowRoot.querySelector("textarea").value.trim();
108
118
 
109
119
  const systemMessage = "You are a helpful assistant.";
110
120
  // Qdrant 필터로 변환하기 위한 프롬프트 엔지니어링
@@ -138,6 +148,7 @@ class aiContainer extends HTMLElement
138
148
  Qdrant 필터 JSON:
139
149
  `;
140
150
 
151
+
141
152
  //try {
142
153
  const response = await this.#model.invoke([
143
154
  new SystemMessage(systemMessage),
@@ -218,20 +229,80 @@ class aiContainer extends HTMLElement
218
229
 
219
230
  #q1 = async () => {
220
231
  const filter = await this.#generateQdrantFilter();
221
- const d = await this.#searchWithQdrantFilter(filter);
222
- console.log(d);
232
+ return await this.#searchWithQdrantFilter(filter);
223
233
  };
224
234
 
225
235
  #q2 = async () => {
226
236
  const filter = await this.#generateQdrantFilter();
227
- const d = await this.#searchWithQdrantFilter(filter);
228
- console.log(d);
237
+ const searchResults = await this.#searchWithQdrantFilter(filter);
238
+
239
+ const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
240
+ const columnInfo = this.#getColumnInfo();
241
+ const uniqueKey = this.#getUniqueKey();
242
+
243
+ if (!searchResults || searchResults.length == 0) {
244
+ elAiChat.add("ai", "관련된 정보가 없습니다.");
245
+ }
246
+ else if (searchResults.length > 100) {
247
+ elAiChat.add("ai", `${searchResults.length}건의 정보를 찾았습니다.`, columnInfo, searchResults.map(item => item.payload), uniqueKey);
248
+ }
249
+ else {
250
+ let arr = searchResults.map(item => item.payload);
251
+ let contextText = `당신은 주어진 정보를 참고하여 답변하는 AI 입니다. 주어진 '정보'를 바탕으로 데이타를 분석해줘. 데이타는 "context" 항목에 있어. 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다. 이전에 너가 찾아준 데이타를 다시 보내는거니깐 첫 줄에는 "${arr.length}건을 찾았습니다." 라고 답변을 달아줘.\n\ncontext: `;
252
+
253
+ let contextText1 = `당신은 주어진 데이터를 분석하고 핵심 인사이트를 도출하는 전문 데이터 분석가입니다.
254
+
255
+ 아래에 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다.
256
+
257
+ 이 데이터를 철저히 분석하여 다음 질문에 대한 답변을 제공해주세요:
258
+ - 데이터의 주요 트렌드는 무엇인가요?
259
+ - 특이하거나 주목할 만한 패턴이 있나요?
260
+ - 가장 빈번하게 나타나는 항목(또는 값)은 무엇인가요?
261
+ - 데이터에서 발견할 수 있는 잠재적인 문제점이나 개선점은 무엇인가요?
262
+ - 각 데이터 레코드를 기반으로 한 간략한 요약 또는 분류가 가능할까요?
263
+
264
+ 분석 결과는 다음 형식으로 제공해주세요:
265
+ 1. **주요 트렌드**: 불릿 포인트 형식으로 요약
266
+ 2. **주목할 만한 패턴/이상치**: 구체적인 예시와 함께 설명
267
+ 3. **가장 빈번한 항목**: 항목명과 빈도수를 포함 (테이블 형식도 가능)
268
+ 4. **개선점/문제점**: 텍스트 설명
269
+ 5. **각 레코드에 대한 간략한 요약 또는 분류**: (선택 사항, 필요시)
270
+
271
+ context:\n`;
272
+
273
+ columnInfo.forEach(info => {
274
+ contextText += `${info.desc}\t`;
275
+ });
276
+ contextText += "\n";
277
+
278
+ for (const o of arr) {
279
+ columnInfo.forEach(info => {
280
+ contextText += `${o[info.name]}\t`;
281
+ });
282
+
283
+ contextText += "\n";
284
+ //contextText += `문서ID: ${o.doc_id}, 문서명: ${o.doc_nm}, 매출액: ${o.amt}, 수정자: ${o.update_user}, 수정일: ${o.update_dt}\n`;
285
+ }
286
+
287
+ //console.log(contextText);
288
+
289
+ const prompt = PromptTemplate.fromTemplate(
290
+ contextText
291
+ )
292
+
293
+ const chain = prompt
294
+ .pipe(this.#model)
295
+ .pipe(new StringOutputParser())
296
+
297
+ const result = await chain.invoke();
298
+
299
+ elAiChat.add("ai", result, columnInfo, arr, uniqueKey);
300
+ }
229
301
  };
230
302
 
231
303
  #q3 = async () => {
232
304
  const filter = await this.#generateQdrantFilter();
233
- const d = await this.#searchWithQdrantFilter(filter);
234
- console.log(d);
305
+ return await this.#searchWithQdrantFilter(filter);
235
306
  };
236
307
 
237
308
  #init = (info) => {
@@ -5,6 +5,8 @@ var googleGenai = require('@langchain/google-genai');
5
5
  var ollama = require('@langchain/ollama');
6
6
  var openai = require('@langchain/openai');
7
7
  var messages = require('@langchain/core/messages');
8
+ var output_parsers = require('@langchain/core/output_parsers');
9
+ var prompts = require('@langchain/core/prompts');
8
10
  var require$$0 = require('assert');
9
11
  var require$$4 = require('net');
10
12
  var require$$2 = require('http');
@@ -54197,8 +54199,16 @@ class aiContainer extends HTMLElement
54197
54199
  return colInfo;
54198
54200
  };
54199
54201
 
54202
+ #getUniqueKey = () => {
54203
+ if (this.#target.tagName === "NINE-GRID") {
54204
+ return this.#target.dataset.unique;
54205
+ }
54206
+ };
54207
+
54200
54208
 
54201
- #generateQdrantFilter = async (userInput) => {
54209
+ #generateQdrantFilter = async () => {
54210
+
54211
+ const userInput = this.shadowRoot.querySelector("textarea").value.trim();
54202
54212
 
54203
54213
  const systemMessage = "You are a helpful assistant.";
54204
54214
  // Qdrant 필터로 변환하기 위한 프롬프트 엔지니어링
@@ -54232,6 +54242,7 @@ class aiContainer extends HTMLElement
54232
54242
  Qdrant 필터 JSON:
54233
54243
  `;
54234
54244
 
54245
+
54235
54246
  //try {
54236
54247
  const response = await this.#model.invoke([
54237
54248
  new messages.SystemMessage(systemMessage),
@@ -54308,20 +54319,60 @@ class aiContainer extends HTMLElement
54308
54319
 
54309
54320
  #q1 = async () => {
54310
54321
  const filter = await this.#generateQdrantFilter();
54311
- const d = await this.#searchWithQdrantFilter(filter);
54312
- console.log(d);
54322
+ return await this.#searchWithQdrantFilter(filter);
54313
54323
  };
54314
54324
 
54315
54325
  #q2 = async () => {
54316
54326
  const filter = await this.#generateQdrantFilter();
54317
- const d = await this.#searchWithQdrantFilter(filter);
54318
- console.log(d);
54327
+ const searchResults = await this.#searchWithQdrantFilter(filter);
54328
+
54329
+ const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
54330
+ const columnInfo = this.#getColumnInfo();
54331
+ const uniqueKey = this.#getUniqueKey();
54332
+
54333
+ if (!searchResults || searchResults.length == 0) {
54334
+ elAiChat.add("ai", "관련된 정보가 없습니다.");
54335
+ }
54336
+ else if (searchResults.length > 100) {
54337
+ elAiChat.add("ai", `${searchResults.length}건의 정보를 찾았습니다.`, columnInfo, searchResults.map(item => item.payload), uniqueKey);
54338
+ }
54339
+ else {
54340
+ let arr = searchResults.map(item => item.payload);
54341
+ let contextText = `당신은 주어진 정보를 참고하여 답변하는 AI 입니다. 주어진 '정보'를 바탕으로 데이타를 분석해줘. 데이타는 "context" 항목에 있어. 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다. 이전에 너가 찾아준 데이타를 다시 보내는거니깐 첫 줄에는 "${arr.length}건을 찾았습니다." 라고 답변을 달아줘.\n\ncontext: `;
54342
+
54343
+ columnInfo.forEach(info => {
54344
+ contextText += `${info.desc}\t`;
54345
+ });
54346
+ contextText += "\n";
54347
+
54348
+ for (const o of arr) {
54349
+ columnInfo.forEach(info => {
54350
+ contextText += `${o[info.name]}\t`;
54351
+ });
54352
+
54353
+ contextText += "\n";
54354
+ //contextText += `문서ID: ${o.doc_id}, 문서명: ${o.doc_nm}, 매출액: ${o.amt}, 수정자: ${o.update_user}, 수정일: ${o.update_dt}\n`;
54355
+ }
54356
+
54357
+ //console.log(contextText);
54358
+
54359
+ const prompt = prompts.PromptTemplate.fromTemplate(
54360
+ contextText
54361
+ );
54362
+
54363
+ const chain = prompt
54364
+ .pipe(this.#model)
54365
+ .pipe(new output_parsers.StringOutputParser());
54366
+
54367
+ const result = await chain.invoke();
54368
+
54369
+ elAiChat.add("ai", result, columnInfo, arr, uniqueKey);
54370
+ }
54319
54371
  };
54320
54372
 
54321
54373
  #q3 = async () => {
54322
54374
  const filter = await this.#generateQdrantFilter();
54323
- const d = await this.#searchWithQdrantFilter(filter);
54324
- console.log(d);
54375
+ return await this.#searchWithQdrantFilter(filter);
54325
54376
  };
54326
54377
 
54327
54378
  #init = (info) => {
@@ -3,6 +3,8 @@ import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
3
3
  import { Ollama, OllamaEmbeddings } from '@langchain/ollama';
4
4
  import { ChatOpenAI } from '@langchain/openai';
5
5
  import { SystemMessage, HumanMessage } from '@langchain/core/messages';
6
+ import { StringOutputParser } from '@langchain/core/output_parsers';
7
+ import { PromptTemplate } from '@langchain/core/prompts';
6
8
  import require$$0 from 'assert';
7
9
  import require$$4 from 'net';
8
10
  import require$$2 from 'http';
@@ -54195,8 +54197,16 @@ class aiContainer extends HTMLElement
54195
54197
  return colInfo;
54196
54198
  };
54197
54199
 
54200
+ #getUniqueKey = () => {
54201
+ if (this.#target.tagName === "NINE-GRID") {
54202
+ return this.#target.dataset.unique;
54203
+ }
54204
+ };
54205
+
54198
54206
 
54199
- #generateQdrantFilter = async (userInput) => {
54207
+ #generateQdrantFilter = async () => {
54208
+
54209
+ const userInput = this.shadowRoot.querySelector("textarea").value.trim();
54200
54210
 
54201
54211
  const systemMessage = "You are a helpful assistant.";
54202
54212
  // Qdrant 필터로 변환하기 위한 프롬프트 엔지니어링
@@ -54230,6 +54240,7 @@ class aiContainer extends HTMLElement
54230
54240
  Qdrant 필터 JSON:
54231
54241
  `;
54232
54242
 
54243
+
54233
54244
  //try {
54234
54245
  const response = await this.#model.invoke([
54235
54246
  new SystemMessage(systemMessage),
@@ -54306,20 +54317,60 @@ class aiContainer extends HTMLElement
54306
54317
 
54307
54318
  #q1 = async () => {
54308
54319
  const filter = await this.#generateQdrantFilter();
54309
- const d = await this.#searchWithQdrantFilter(filter);
54310
- console.log(d);
54320
+ return await this.#searchWithQdrantFilter(filter);
54311
54321
  };
54312
54322
 
54313
54323
  #q2 = async () => {
54314
54324
  const filter = await this.#generateQdrantFilter();
54315
- const d = await this.#searchWithQdrantFilter(filter);
54316
- console.log(d);
54325
+ const searchResults = await this.#searchWithQdrantFilter(filter);
54326
+
54327
+ const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
54328
+ const columnInfo = this.#getColumnInfo();
54329
+ const uniqueKey = this.#getUniqueKey();
54330
+
54331
+ if (!searchResults || searchResults.length == 0) {
54332
+ elAiChat.add("ai", "관련된 정보가 없습니다.");
54333
+ }
54334
+ else if (searchResults.length > 100) {
54335
+ elAiChat.add("ai", `${searchResults.length}건의 정보를 찾았습니다.`, columnInfo, searchResults.map(item => item.payload), uniqueKey);
54336
+ }
54337
+ else {
54338
+ let arr = searchResults.map(item => item.payload);
54339
+ let contextText = `당신은 주어진 정보를 참고하여 답변하는 AI 입니다. 주어진 '정보'를 바탕으로 데이타를 분석해줘. 데이타는 "context" 항목에 있어. 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다. 이전에 너가 찾아준 데이타를 다시 보내는거니깐 첫 줄에는 "${arr.length}건을 찾았습니다." 라고 답변을 달아줘.\n\ncontext: `;
54340
+
54341
+ columnInfo.forEach(info => {
54342
+ contextText += `${info.desc}\t`;
54343
+ });
54344
+ contextText += "\n";
54345
+
54346
+ for (const o of arr) {
54347
+ columnInfo.forEach(info => {
54348
+ contextText += `${o[info.name]}\t`;
54349
+ });
54350
+
54351
+ contextText += "\n";
54352
+ //contextText += `문서ID: ${o.doc_id}, 문서명: ${o.doc_nm}, 매출액: ${o.amt}, 수정자: ${o.update_user}, 수정일: ${o.update_dt}\n`;
54353
+ }
54354
+
54355
+ //console.log(contextText);
54356
+
54357
+ const prompt = PromptTemplate.fromTemplate(
54358
+ contextText
54359
+ );
54360
+
54361
+ const chain = prompt
54362
+ .pipe(this.#model)
54363
+ .pipe(new StringOutputParser());
54364
+
54365
+ const result = await chain.invoke();
54366
+
54367
+ elAiChat.add("ai", result, columnInfo, arr, uniqueKey);
54368
+ }
54317
54369
  };
54318
54370
 
54319
54371
  #q3 = async () => {
54320
54372
  const filter = await this.#generateQdrantFilter();
54321
- const d = await this.#searchWithQdrantFilter(filter);
54322
- console.log(d);
54373
+ return await this.#searchWithQdrantFilter(filter);
54323
54374
  };
54324
54375
 
54325
54376
  #init = (info) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ninegrid2",
3
3
  "type": "module",
4
- "version": "6.518.0",
4
+ "version": "6.520.0",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
7
7
  "import": "./dist/index.js",
@@ -5,6 +5,8 @@ import { ChatOpenAI } from '@langchain/openai';
5
5
  import { HumanMessage, SystemMessage } from '@langchain/core/messages';
6
6
  import { OllamaEmbeddings } from "@langchain/ollama";
7
7
  import { QdrantClient } from "@qdrant/js-client-rest";
8
+ import { StringOutputParser } from "@langchain/core/output_parsers"
9
+ import { PromptTemplate} from "@langchain/core/prompts"
8
10
 
9
11
  class aiContainer extends HTMLElement
10
12
  {
@@ -103,8 +105,16 @@ class aiContainer extends HTMLElement
103
105
  return colInfo;
104
106
  };
105
107
 
108
+ #getUniqueKey = () => {
109
+ if (this.#target.tagName === "NINE-GRID") {
110
+ return this.#target.dataset.unique;
111
+ }
112
+ };
113
+
106
114
 
107
- #generateQdrantFilter = async (userInput) => {
115
+ #generateQdrantFilter = async () => {
116
+
117
+ const userInput = this.shadowRoot.querySelector("textarea").value.trim();
108
118
 
109
119
  const systemMessage = "You are a helpful assistant.";
110
120
  // Qdrant 필터로 변환하기 위한 프롬프트 엔지니어링
@@ -138,6 +148,7 @@ class aiContainer extends HTMLElement
138
148
  Qdrant 필터 JSON:
139
149
  `;
140
150
 
151
+
141
152
  //try {
142
153
  const response = await this.#model.invoke([
143
154
  new SystemMessage(systemMessage),
@@ -218,20 +229,80 @@ class aiContainer extends HTMLElement
218
229
 
219
230
  #q1 = async () => {
220
231
  const filter = await this.#generateQdrantFilter();
221
- const d = await this.#searchWithQdrantFilter(filter);
222
- console.log(d);
232
+ return await this.#searchWithQdrantFilter(filter);
223
233
  };
224
234
 
225
235
  #q2 = async () => {
226
236
  const filter = await this.#generateQdrantFilter();
227
- const d = await this.#searchWithQdrantFilter(filter);
228
- console.log(d);
237
+ const searchResults = await this.#searchWithQdrantFilter(filter);
238
+
239
+ const elAiChat = this.shadowRoot.querySelector("nx-ai-chat");
240
+ const columnInfo = this.#getColumnInfo();
241
+ const uniqueKey = this.#getUniqueKey();
242
+
243
+ if (!searchResults || searchResults.length == 0) {
244
+ elAiChat.add("ai", "관련된 정보가 없습니다.");
245
+ }
246
+ else if (searchResults.length > 100) {
247
+ elAiChat.add("ai", `${searchResults.length}건의 정보를 찾았습니다.`, columnInfo, searchResults.map(item => item.payload), uniqueKey);
248
+ }
249
+ else {
250
+ let arr = searchResults.map(item => item.payload);
251
+ let contextText = `당신은 주어진 정보를 참고하여 답변하는 AI 입니다. 주어진 '정보'를 바탕으로 데이타를 분석해줘. 데이타는 "context" 항목에 있어. 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다. 이전에 너가 찾아준 데이타를 다시 보내는거니깐 첫 줄에는 "${arr.length}건을 찾았습니다." 라고 답변을 달아줘.\n\ncontext: `;
252
+
253
+ let contextText1 = `당신은 주어진 데이터를 분석하고 핵심 인사이트를 도출하는 전문 데이터 분석가입니다.
254
+
255
+ 아래에 제공될 데이터는 CSV 형식이며, 첫 번째 줄은 컬럼명입니다.
256
+
257
+ 이 데이터를 철저히 분석하여 다음 질문에 대한 답변을 제공해주세요:
258
+ - 데이터의 주요 트렌드는 무엇인가요?
259
+ - 특이하거나 주목할 만한 패턴이 있나요?
260
+ - 가장 빈번하게 나타나는 항목(또는 값)은 무엇인가요?
261
+ - 데이터에서 발견할 수 있는 잠재적인 문제점이나 개선점은 무엇인가요?
262
+ - 각 데이터 레코드를 기반으로 한 간략한 요약 또는 분류가 가능할까요?
263
+
264
+ 분석 결과는 다음 형식으로 제공해주세요:
265
+ 1. **주요 트렌드**: 불릿 포인트 형식으로 요약
266
+ 2. **주목할 만한 패턴/이상치**: 구체적인 예시와 함께 설명
267
+ 3. **가장 빈번한 항목**: 항목명과 빈도수를 포함 (테이블 형식도 가능)
268
+ 4. **개선점/문제점**: 텍스트 설명
269
+ 5. **각 레코드에 대한 간략한 요약 또는 분류**: (선택 사항, 필요시)
270
+
271
+ context:\n`;
272
+
273
+ columnInfo.forEach(info => {
274
+ contextText += `${info.desc}\t`;
275
+ });
276
+ contextText += "\n";
277
+
278
+ for (const o of arr) {
279
+ columnInfo.forEach(info => {
280
+ contextText += `${o[info.name]}\t`;
281
+ });
282
+
283
+ contextText += "\n";
284
+ //contextText += `문서ID: ${o.doc_id}, 문서명: ${o.doc_nm}, 매출액: ${o.amt}, 수정자: ${o.update_user}, 수정일: ${o.update_dt}\n`;
285
+ }
286
+
287
+ //console.log(contextText);
288
+
289
+ const prompt = PromptTemplate.fromTemplate(
290
+ contextText
291
+ )
292
+
293
+ const chain = prompt
294
+ .pipe(this.#model)
295
+ .pipe(new StringOutputParser())
296
+
297
+ const result = await chain.invoke();
298
+
299
+ elAiChat.add("ai", result, columnInfo, arr, uniqueKey);
300
+ }
229
301
  };
230
302
 
231
303
  #q3 = async () => {
232
304
  const filter = await this.#generateQdrantFilter();
233
- const d = await this.#searchWithQdrantFilter(filter);
234
- console.log(d);
305
+ return await this.#searchWithQdrantFilter(filter);
235
306
  };
236
307
 
237
308
  #init = (info) => {