@d-mok/quasar-app-extension-quasar-axe 2.1.83 → 2.1.85

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": "@d-mok/quasar-app-extension-quasar-axe",
3
- "version": "2.1.83",
3
+ "version": "2.1.85",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -29,7 +29,8 @@
29
29
  "papaparse": "^5.4.1",
30
30
  "sapphire-js": "^2.1.5",
31
31
  "sortablejs": "^1.15.0",
32
- "vuedraggable": "^4.1.0"
32
+ "vuedraggable": "^4.1.0",
33
+ "pdfjs-dist": "^4.0.189"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@quasar/app-vite": "^1.7.1",
@@ -0,0 +1,109 @@
1
+ type SuccessResponse = [
2
+ {
3
+ cost: number
4
+ status: 'success'
5
+ message: { role: string; message: string }[]
6
+ provider: 'openai'
7
+ generated_text: string
8
+ }
9
+ ]
10
+
11
+ type InvalidRequestResponse = {
12
+ error: {
13
+ type: string
14
+ message: {
15
+ max_tokens: string[]
16
+ }
17
+ }
18
+ }
19
+
20
+ type TimeoutErrorResponse = [
21
+ {
22
+ cost: number
23
+ error: {
24
+ message: string
25
+ }
26
+ status: 'fail'
27
+ provider: 'openai'
28
+ provider_status_code: 408
29
+ }
30
+ ]
31
+
32
+ type TooManyRequestsErrorResponse = {
33
+ detail: string
34
+ }
35
+
36
+ async function fetchChatAPI(
37
+ EDEN_API_KEY: string,
38
+ prompt: string,
39
+ openai_model: string,
40
+ temperature: number
41
+ ) {
42
+ const res = await fetch('https://api.edenai.run/v2/text/chat', {
43
+ method: 'POST',
44
+ headers: {
45
+ accept: 'application/json',
46
+ 'content-type': 'application/json',
47
+ authorization: 'Bearer ' + EDEN_API_KEY,
48
+ },
49
+ body: JSON.stringify({
50
+ response_as_dict: false,
51
+ attributes_as_list: false,
52
+ show_original_response: false,
53
+ settings: `{"openai":"${openai_model}"}`,
54
+ temperature,
55
+ max_tokens:
56
+ {
57
+ 'gpt-3.5-turbo': 4000,
58
+ 'gpt-3.5-turbo-0301': 4000,
59
+ 'gpt-3.5-turbo-16k': 8000,
60
+ 'gpt-4': 4000,
61
+ 'gpt-4-0314': 4000,
62
+ 'gpt-4-1106-preview': 4000,
63
+ 'gpt-4-vision-preview': 4000,
64
+ }[openai_model] ?? 4000,
65
+ providers: 'openai',
66
+ text: prompt,
67
+ }),
68
+ })
69
+ const json:
70
+ | SuccessResponse
71
+ | InvalidRequestResponse
72
+ | TimeoutErrorResponse
73
+ | TooManyRequestsErrorResponse = await res.json()
74
+ if (Array.isArray(json) && json[0].status === 'success') {
75
+ return json[0].generated_text
76
+ }
77
+ console.error('Eden AI error:')
78
+ console.error(json)
79
+ return 'Error'
80
+ }
81
+
82
+ /** Scheduler (one fetch at a time) */
83
+
84
+ let occupied = false
85
+
86
+ function sleep(ms: number): Promise<void> {
87
+ return new Promise(resolve => setTimeout(resolve, ms))
88
+ }
89
+
90
+ export async function chatAPI(
91
+ EDEN_API_KEY: string,
92
+ prompt: string,
93
+ openai_model: string,
94
+ temperature: number
95
+ ): Promise<string> {
96
+ if (occupied) {
97
+ await sleep(5000)
98
+ return await chatAPI(EDEN_API_KEY, prompt, openai_model, temperature)
99
+ }
100
+ occupied = true
101
+ let res = await fetchChatAPI(
102
+ EDEN_API_KEY,
103
+ prompt,
104
+ openai_model,
105
+ temperature
106
+ )
107
+ occupied = false
108
+ return res
109
+ }
@@ -23,3 +23,7 @@ export type { zipFolder } from './zip'
23
23
  export * as gSheet from './gSheet'
24
24
 
25
25
  export { SupbaseBucket } from './storage'
26
+
27
+ export { extractTextFromPDF } from './pdf'
28
+
29
+ export { chatAPI } from './edenAI'
@@ -0,0 +1,25 @@
1
+ import * as PDFJS from 'pdfjs-dist'
2
+
3
+ //@ts-ignore
4
+ import * as pdfjsWorker from 'pdfjs-dist/build/pdf.worker.mjs'
5
+
6
+ PDFJS.GlobalWorkerOptions.workerSrc = pdfjsWorker
7
+
8
+ /**
9
+ * Extract text from a PDF file. Return an array of strings, one for each page.
10
+ */
11
+ export async function extractTextFromPDF(pdfFile: File): Promise<string[]> {
12
+ let str: string[] = []
13
+ let pdf = await PDFJS.getDocument(await pdfFile.arrayBuffer()).promise
14
+ for (let i = 1; i <= pdf.numPages; i++) {
15
+ let s: string[] = []
16
+ let page = await pdf.getPage(i)
17
+ let textContent = await page.getTextContent()
18
+ for (let item of textContent.items) {
19
+ if ('str' in item) s.push(item.str)
20
+ }
21
+ s.remove([''])
22
+ str.push(s.join(' '))
23
+ }
24
+ return str
25
+ }
@@ -145,13 +145,7 @@ export function TABLE<
145
145
 
146
146
  update(idVal: R[ClassT['_idKey']], row: Partial<R>) {
147
147
  let callback = ($: T[]) => {
148
- let oldie = this.find($ => $[idKey] === idVal)
149
- if (oldie !== undefined) {
150
- for (let newbie of $) {
151
- Object.assign(oldie, newbie)
152
- }
153
- }
154
- // this.merge($, idKey)
148
+ this.merge($, idKey)
155
149
  this.onChange()
156
150
  this.onEdit()
157
151
  }