@christianriedl/media 1.0.291 → 1.0.292

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": "@christianriedl/media",
3
- "version": "1.0.291",
3
+ "version": "1.0.292",
4
4
  "description": "RIC media interfaces",
5
5
 
6
6
  "main": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "author": "Christian Riedl",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
- "@christianriedl/utils": "^1.0.199",
21
+ "@christianriedl/utils": "^1.0.200",
22
22
  "@christianriedl/rest": "^1.0.97",
23
23
  "@christianriedl/epg": "^1.0.44",
24
24
  "buffer": "^6.0.3"
@@ -2,11 +2,12 @@
2
2
  import { inject, ref, reactive, watch, computed, onMounted, StyleValue } from 'vue';
3
3
  import { useRouter, useRoute } from 'vue-router';
4
4
  import { IAppState, Dictionary, appStateSymbol, appConfigSymbol, EScope, Helper } from '@christianriedl/utils';
5
- import { getOpenAISymbol, IOpenAIServiceWithVectorStore, getRagSymbol, IRagService } from '@christianriedl/utils';
5
+ import { getOpenAISymbol, IOpenAIServiceWithVectorStore, getRagSymbol, IRagService, IRagDocument } from '@christianriedl/utils';
6
6
  import { getMediaBinSymbol, getMediaInstanceSymbol, IDocumentInfo, IMediaAppConfig } from '@christianriedl/media';
7
7
  import FileUpload from '../components/FileUpload.vue';
8
8
  import Mail from '@christianriedl/office/src/components/Mail.vue';
9
9
  import RagDocuments from '@christianriedl/utils/src/components/RagDocuments.vue';
10
+ import RagBatches from '@christianriedl/utils/src/components/RagBatches.vue';
10
11
 
11
12
  interface IID {
12
13
  fileId: string;
@@ -17,8 +18,8 @@
17
18
  const router = useRouter();
18
19
  const appState = inject(appStateSymbol)!;
19
20
  const mediaAppConfig = inject(appConfigSymbol)! as unknown as IMediaAppConfig;
20
- const getRagService = inject(getRagSymbol);
21
- const ragService = getRagService() ?? null;
21
+ const getRagService = inject(getRagSymbol)!;
22
+ const ragService = getRagService();
22
23
  const getAiService = inject(getOpenAISymbol)!;
23
24
  const aiService = ragService ? null : getAiService() as IOpenAIServiceWithVectorStore;
24
25
  const officeExtensions: string[] = mediaAppConfig.officeExtensions.split(',');
@@ -32,6 +33,7 @@
32
33
  const backVisible = ref(false);
33
34
  const uploadVisible = ref(false);
34
35
  const ragVisible = ref(false);
36
+ const batchVisible = ref(false);
35
37
  const recursive = ref(true);
36
38
  const like = ref("");
37
39
  const contains = ref("");
@@ -42,11 +44,13 @@
42
44
  const directoryInfos = reactive<IDocumentInfo[]>([]);
43
45
  const fileInfos = reactive<IDocumentInfo[]>([]);
44
46
  const heightStyle = computed<StyleValue>(() => { return { height: appState.bodyHeight.value + 'px', overflowY: 'auto' } });
47
+ let addDocument: IRagDocument;
45
48
  let documentRoot = "";
46
49
 
47
50
  onMounted(async() => {
48
51
  mediaService.log.trace('Documents created');
49
- documentRoot = await mediaService.getDocumentInfo("").path;
52
+ const info = await mediaService.getDocumentInfo("");
53
+ documentRoot = info.path! + '\\';
50
54
  if (ragService)
51
55
  ragService.getSortedFileNames();
52
56
  if (aiService)
@@ -93,7 +97,7 @@
93
97
  }
94
98
  function makeRelPath(name: string, fpath?: string) : string {
95
99
  if (fpath)
96
- return fpath.substring(documentRoot.length).replace('\\', '/');
100
+ return fpath.substring(documentRoot.length).replaceAll('\\', '/');
97
101
  else
98
102
  return path.value.length > 0 ? (path.value + '/' + name) : name;
99
103
  }
@@ -101,7 +105,7 @@
101
105
  if (fpath)
102
106
  return fpath;
103
107
  else
104
- return documentRoot + '\\' + (path.value.length > 0 ? (path.value + '\\' + name) : name);
108
+ return documentRoot + (path.value.length > 0 ? (path.value + '\\' + name) : name);
105
109
  }
106
110
  function download(name: string, fpath?: string) {
107
111
  const fullPath = makeRelPath(name, fpath);
@@ -144,7 +148,7 @@
144
148
  if (!info)
145
149
  window.alert("Not found: " + fullPath);
146
150
  else {
147
- attachment.value = info.path;
151
+ attachment.value = info.path!;
148
152
  showSendMail.value = true;
149
153
  }
150
154
  }
@@ -177,7 +181,7 @@
177
181
  return false;
178
182
  }
179
183
  function getFileId(file: string): IID | undefined {
180
- if (aiService.vectorStore) {
184
+ if (aiService && aiService.vectorStore) {
181
185
  for (const key in aiService.vectorStore) {
182
186
  const store = aiService.vectorStore[key];
183
187
  for (const id in store.files) {
@@ -192,7 +196,7 @@
192
196
  function ragClass(name: string, fpath?: string): Dictionary<boolean> {
193
197
  const cls: Dictionary<boolean> = { 'bg-office': true };
194
198
  if (ragService) {
195
- if (ragService.containsFile(makeAbsPath(name, fpath)) {
199
+ if (ragService.containsFile(makeAbsPath(name, fpath))) {
196
200
  cls['text-warning'] = true;
197
201
  }
198
202
  }
@@ -206,7 +210,7 @@
206
210
  async function checkRag(name: string, fpath?: string) {
207
211
  if (ragService) {
208
212
  const fullPath = makeAbsPath(name, fpath);
209
- if (ragService.contains(fullPath); {
213
+ if (ragService.containsFile(fullPath)) {
210
214
  if (window.confirm(`File ist in Vectorstore, remove ?`)) {
211
215
  const docs = await ragService.getDocuments();
212
216
  const found = docs.find(x => x.fileName == fullPath);
@@ -217,25 +221,45 @@
217
221
  alert("Nicht gefunden: " + fullPath);
218
222
  }
219
223
  }
220
- else
221
- alert("Mit Batch in Vectorstore einf�gen");
222
- return;
223
- }
224
- const iid = getFileId(name);
225
- if (iid) {
226
- if (window.confirm(`File is in vectorstore ${iid.vectorStore}, delete ?`)) {
227
- const rc = await aiService.deleteFile(iid.fileId);
224
+ else {
225
+ if (window.confirm(`File ist nicht in Vectorstore, add it ?`)) {
226
+ const relPath = makeRelPath(name, fpath);
227
+ let url = mediaService.getFileUrl(relPath);
228
+ addDocument = {
229
+ key: 0,
230
+ fileName: fullPath,
231
+ description: "",
232
+ url: mediaService.getFileUrl(relPath),
233
+ documentCategories: [],
234
+ documentType: ""
235
+ } as IRagDocument;
236
+ batchVisible.value = true;
237
+ }
228
238
  }
229
239
  }
230
- else {
231
- const vsname = window.prompt(`Enter vectorstore name for ${name} to add it`);
232
- if (vsname != null) {
233
- if (!folder)
234
- folder = path.value;
235
- let url = mediaService.getFileUrl(folder.length > 0 ? (folder + '/' + name) : name);
236
- const rc = await aiService.addFile(url, vsname);
240
+ if (aiService) {
241
+ const iid = getFileId(name);
242
+ if (iid) {
243
+ if (window.confirm(`File is in vectorstore ${iid.vectorStore}, delete ?`)) {
244
+ const rc = await aiService.deleteFile(iid.fileId);
245
+ }
246
+ }
247
+ else {
248
+ const vsname = window.prompt(`Enter vectorstore name for ${name} to add it`);
249
+ if (vsname != null) {
250
+ const fullPath = makeRelPath(name, fpath);
251
+ let url = mediaService.getFileUrl(fullPath);
252
+ const rc = await aiService.addFile(url, vsname);
253
+ }
237
254
  }
238
255
  }
256
+ }
257
+ async function showRag() {
258
+ var entries = await ragService.getEntries();
259
+ if (entries && entries.length > 0)
260
+ batchVisible.value = true;
261
+ else
262
+ ragVisible.value = true;
239
263
  }
240
264
  function info(item: IDocumentInfo): string {
241
265
  let sizeStr = "";
@@ -252,7 +276,8 @@
252
276
  }
253
277
  </script>
254
278
  <template>
255
- <rag-documents v-if="ragVisible" @back="ragVisible=false"></rag-documents>
279
+ <rag-batches v-if="batchVisible" :addDocument="addDocument" @back="batchVisible=false"></rag-batches>
280
+ <rag-documents v-else-if="ragVisible" @back="ragVisible=false"></rag-documents>
256
281
  <v-card v-else class="bg-office">
257
282
  <v-card-title>{{path}}</v-card-title>
258
283
  <v-container v-if="isMobile" fluid>
@@ -285,7 +310,7 @@
285
310
  <v-btn prepend-icon="$search" variant="tonal" @click="onSearch">SEARCH</v-btn>
286
311
  </v-col>
287
312
  <v-col v-if="isAdmin" cols="1">
288
- <v-btn prepend-icon="$pencil" variant="tonal" @click.stop="ragVisible = true">Show RAG</v-btn>
313
+ <v-btn prepend-icon="$pencil" variant="tonal" @click.stop="showRag()">Show RAG</v-btn>
289
314
  </v-col>
290
315
  <v-col v-if="isAdmin" cols="1">
291
316
  <v-btn prepend-icon="$upload" variant="tonal" @click.stop="uploadVisible = !uploadVisible">UPLOAD</v-btn>