payload-ai 0.0.52 → 0.0.54
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/README.md +23 -0
- package/dev/src/payload.config.ts +5 -0
- package/dev/src/server.ts +0 -2
- package/package.json +1 -1
- package/src/aiTranslate.ts +12 -10
- package/src/components/Translator/index.tsx +46 -8
- package/src/deepCompareAndMerge.ts +7 -3
- package/src/handleTranslate.ts +3 -0
- package/src/plugin.ts +1 -1
- package/src/stringTranslations.ts +100 -97
- package/src/translateTextAndObjects.ts +21 -10
- package/dist/access/admins.d.ts +0 -4
- package/dist/access/admins.js +0 -12
- package/dist/access/admins.js.map +0 -1
- package/dist/access/adminsOrPublished.d.ts +0 -2
- package/dist/access/adminsOrPublished.js +0 -18
- package/dist/access/adminsOrPublished.js.map +0 -1
- package/dist/access/anyone.d.ts +0 -2
- package/dist/access/anyone.js +0 -6
- package/dist/access/anyone.js.map +0 -1
- package/dist/access/checkRole.d.ts +0 -1
- package/dist/access/checkRole.js +0 -18
- package/dist/access/checkRole.js.map +0 -1
- package/dist/aiTranslate.d.ts +0 -7
- package/dist/aiTranslate.js +0 -149
- package/dist/aiTranslate.js.map +0 -1
- package/dist/components/AfterDashboard/index.d.ts +0 -3
- package/dist/components/AfterDashboard/index.js +0 -17
- package/dist/components/AfterDashboard/index.js.map +0 -1
- package/dist/components/AfterDashboard/index.scss +0 -10
- package/dist/components/Metadata/index.d.ts +0 -2
- package/dist/components/Metadata/index.js +0 -101
- package/dist/components/Metadata/index.js.map +0 -1
- package/dist/components/Metadata/index.scss +0 -10
- package/dist/components/Translator/Translator.scss +0 -6
- package/dist/components/Translator/index.d.ts +0 -4
- package/dist/components/Translator/index.js +0 -176
- package/dist/components/Translator/index.js.map +0 -1
- package/dist/deepCompareAndMerge.d.ts +0 -5
- package/dist/deepCompareAndMerge.js +0 -96
- package/dist/deepCompareAndMerge.js.map +0 -1
- package/dist/generateImage.d.ts +0 -1
- package/dist/generateImage.js +0 -80
- package/dist/generateImage.js.map +0 -1
- package/dist/generateText.d.ts +0 -5
- package/dist/generateText.js +0 -90
- package/dist/generateText.js.map +0 -1
- package/dist/handleTranslate.d.ts +0 -3
- package/dist/handleTranslate.js +0 -83
- package/dist/handleTranslate.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js.map +0 -1
- package/dist/mocks/mockFile.d.ts +0 -1
- package/dist/mocks/mockFile.js +0 -3
- package/dist/mocks/mockFile.js.map +0 -1
- package/dist/onInitExtension.d.ts +0 -3
- package/dist/onInitExtension.js +0 -17
- package/dist/onInitExtension.js.map +0 -1
- package/dist/plugin.d.ts +0 -3
- package/dist/plugin.js +0 -174
- package/dist/plugin.js.map +0 -1
- package/dist/seoTools.d.ts +0 -2
- package/dist/seoTools.js +0 -135
- package/dist/seoTools.js.map +0 -1
- package/dist/stringTranslations.d.ts +0 -3
- package/dist/stringTranslations.js +0 -174
- package/dist/stringTranslations.js.map +0 -1
- package/dist/translateTextAndObjects.d.ts +0 -1
- package/dist/translateTextAndObjects.js +0 -235
- package/dist/translateTextAndObjects.js.map +0 -1
- package/dist/types.d.ts +0 -20
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/webpack.d.ts +0 -3
- package/dist/webpack.js +0 -32
- package/dist/webpack.js.map +0 -1
package/README.md
CHANGED
|
@@ -121,6 +121,28 @@ plugins: [
|
|
|
121
121
|
}),
|
|
122
122
|
],
|
|
123
123
|
```
|
|
124
|
+
#### Change model for string translation
|
|
125
|
+
|
|
126
|
+
To update the model you can change the collection settings in the same way as with other collections.
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
plugins: [
|
|
130
|
+
aiTranslatorPlugin({
|
|
131
|
+
enabled: true,
|
|
132
|
+
stringTranslation: {
|
|
133
|
+
enabled: true
|
|
134
|
+
}
|
|
135
|
+
collections: {
|
|
136
|
+
translations: {
|
|
137
|
+
settings: {
|
|
138
|
+
model: 'gpt-4',
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
```
|
|
145
|
+
|
|
124
146
|
|
|
125
147
|
### Generate SEO
|
|
126
148
|
|
|
@@ -133,6 +155,7 @@ plugins: [
|
|
|
133
155
|
- custom access control
|
|
134
156
|
- custom overrides for translation
|
|
135
157
|
- generate images based on input
|
|
158
|
+
- generate Open Graph based on content
|
|
136
159
|
|
|
137
160
|
Payload is built with a robust infrastructure intended to support Plugins with ease. This provides a simple, modular, and reusable way for developers to extend the core capabilities of Payload.
|
|
138
161
|
|
package/dev/src/server.ts
CHANGED
package/package.json
CHANGED
package/src/aiTranslate.ts
CHANGED
|
@@ -4,10 +4,18 @@ import { deepCompareTranslateAndMerge } from './deepCompareAndMerge'
|
|
|
4
4
|
|
|
5
5
|
const aiTranslateHook =
|
|
6
6
|
(
|
|
7
|
-
{
|
|
7
|
+
{
|
|
8
|
+
collectionOptions,
|
|
9
|
+
collection,
|
|
10
|
+
pluginOptions,
|
|
11
|
+
}: { collectionOptions: any; collection: object; pluginOptions: any },
|
|
8
12
|
fallback?: string,
|
|
9
13
|
): CollectionAfterChangeHook =>
|
|
10
14
|
async ({ doc, req, previousDoc, context, collection }) => {
|
|
15
|
+
const settings = pluginOptions.collections?.[collection.slug]?.settings
|
|
16
|
+
|
|
17
|
+
console.log('rreeeeq', settings)
|
|
18
|
+
|
|
11
19
|
return await translateCollection({
|
|
12
20
|
doc,
|
|
13
21
|
req,
|
|
@@ -15,6 +23,7 @@ const aiTranslateHook =
|
|
|
15
23
|
context,
|
|
16
24
|
collection,
|
|
17
25
|
collectionOptions,
|
|
26
|
+
settings,
|
|
18
27
|
})
|
|
19
28
|
}
|
|
20
29
|
|
|
@@ -29,6 +38,7 @@ export async function translateCollection({
|
|
|
29
38
|
collectionOptions,
|
|
30
39
|
onlyMissing,
|
|
31
40
|
codes,
|
|
41
|
+
settings,
|
|
32
42
|
}: any) {
|
|
33
43
|
if (
|
|
34
44
|
context.triggerAfterChange === false ||
|
|
@@ -38,15 +48,6 @@ export async function translateCollection({
|
|
|
38
48
|
|
|
39
49
|
const localCodes: string[] = req.payload.config.localization.localeCodes
|
|
40
50
|
|
|
41
|
-
console.log(
|
|
42
|
-
'filter codes',
|
|
43
|
-
localCodes.filter(
|
|
44
|
-
targetLanguage =>
|
|
45
|
-
targetLanguage !== req.payload.config.localization.defaultLocale &&
|
|
46
|
-
(!codes || codes.includes(targetLanguage)),
|
|
47
|
-
),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
51
|
const translationPromises = localCodes
|
|
51
52
|
.filter(
|
|
52
53
|
targetLanguage =>
|
|
@@ -72,6 +73,7 @@ export async function translateCollection({
|
|
|
72
73
|
previousDoc.id ? 'update' : 'create',
|
|
73
74
|
onlyMissing,
|
|
74
75
|
req.payload.config.localization.defaultLocale,
|
|
76
|
+
settings,
|
|
75
77
|
)
|
|
76
78
|
|
|
77
79
|
const { id, _status, updatedAt, createdAt, publishedDate, ...dataNew } =
|
|
@@ -4,6 +4,7 @@ import { Button, Drawer, DrawerToggler } from 'payload/components/elements'
|
|
|
4
4
|
import { useDocumentInfo, useLocale } from 'payload/components/utilities'
|
|
5
5
|
import { useModal } from '@faceless-ui/modal'
|
|
6
6
|
import './Translator.scss'
|
|
7
|
+
import { SelectInput, useForm } from 'payload/components/forms'
|
|
7
8
|
|
|
8
9
|
const baseClass = 'after-dashboard'
|
|
9
10
|
|
|
@@ -46,11 +47,18 @@ export const DrawerTogglerAlt: any = ({
|
|
|
46
47
|
|
|
47
48
|
export const Translator: React.FC = () => {
|
|
48
49
|
const baseClass = 'ai-translator'
|
|
50
|
+
|
|
51
|
+
//const { fields, getDataByPath } = useForm()
|
|
52
|
+
|
|
49
53
|
const [isLoading, setIsLoading] = React.useState(false)
|
|
54
|
+
const [selectedModel, setSelectedModel] = React.useState<string>('default')
|
|
50
55
|
|
|
51
56
|
const locale = useLocale()
|
|
52
57
|
const documentInfo: any = useDocumentInfo()
|
|
53
58
|
const translate = async ({ codes }: any) => {
|
|
59
|
+
const settings = {
|
|
60
|
+
model: selectedModel === 'default' ? undefined : selectedModel,
|
|
61
|
+
}
|
|
54
62
|
setIsLoading(true)
|
|
55
63
|
try {
|
|
56
64
|
const response = await fetch(`/api/${documentInfo.collection.slug}/translate`, {
|
|
@@ -61,6 +69,7 @@ export const Translator: React.FC = () => {
|
|
|
61
69
|
body: JSON.stringify({
|
|
62
70
|
id: documentInfo.id,
|
|
63
71
|
codes,
|
|
72
|
+
settings,
|
|
64
73
|
}),
|
|
65
74
|
})
|
|
66
75
|
|
|
@@ -87,23 +96,52 @@ export const Translator: React.FC = () => {
|
|
|
87
96
|
/*
|
|
88
97
|
<Button onClick={handleClick}>Results are loading...</Button>
|
|
89
98
|
*/
|
|
99
|
+
|
|
100
|
+
const options = [
|
|
101
|
+
{
|
|
102
|
+
label: 'Default',
|
|
103
|
+
value: 'default',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
label: 'GPT-3.5 Turbo (1106)',
|
|
107
|
+
value: 'gpt-3.5-turbo-1106',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
label: 'GPT-4',
|
|
111
|
+
value: 'gpt-4',
|
|
112
|
+
},
|
|
113
|
+
]
|
|
90
114
|
return (
|
|
91
115
|
<div className={baseClass}>
|
|
92
116
|
<DrawerToggler slug="ai-translator" className={`${baseClass}__drawer__toggler`}>
|
|
93
117
|
Translator
|
|
94
118
|
</DrawerToggler>
|
|
119
|
+
|
|
95
120
|
<Drawer title="Translator" slug="ai-translator">
|
|
96
121
|
{isLoading ? (
|
|
97
122
|
<Button disabled={true}>Results are loading...</Button>
|
|
98
123
|
) : (
|
|
99
|
-
|
|
100
|
-
<
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
124
|
+
<>
|
|
125
|
+
<div>
|
|
126
|
+
<SelectInput
|
|
127
|
+
onChange={(e: any) => {
|
|
128
|
+
setSelectedModel(e.value)
|
|
129
|
+
}}
|
|
130
|
+
name="selectedModel"
|
|
131
|
+
value={selectedModel}
|
|
132
|
+
path="model"
|
|
133
|
+
options={options}
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
<div className={`${baseClass}__translation-buttons`}>
|
|
137
|
+
<Button disabled={isLoading} onClick={() => translate({})}>
|
|
138
|
+
<span>Translate content to all languages</span>
|
|
139
|
+
</Button>
|
|
140
|
+
<Button disabled={isLoading} onClick={() => translate({ codes: [locale.code] })}>
|
|
141
|
+
<span>Translate only {locale.label as string}</span>
|
|
142
|
+
</Button>
|
|
143
|
+
</div>
|
|
144
|
+
</>
|
|
107
145
|
)}
|
|
108
146
|
</Drawer>
|
|
109
147
|
</div>
|
|
@@ -17,6 +17,7 @@ export async function deepCompareTranslateAndMerge(
|
|
|
17
17
|
action?: 'create' | 'update',
|
|
18
18
|
onlyMissing?: boolean,
|
|
19
19
|
sourceLanguage?: string,
|
|
20
|
+
settings?: any,
|
|
20
21
|
): Promise<CollectionObjType> {
|
|
21
22
|
if (Array.isArray(newOriginalObj)) {
|
|
22
23
|
return Promise.all(
|
|
@@ -30,6 +31,7 @@ export async function deepCompareTranslateAndMerge(
|
|
|
30
31
|
action,
|
|
31
32
|
onlyMissing,
|
|
32
33
|
sourceLanguage,
|
|
34
|
+
settings,
|
|
33
35
|
),
|
|
34
36
|
),
|
|
35
37
|
)
|
|
@@ -45,11 +47,12 @@ export async function deepCompareTranslateAndMerge(
|
|
|
45
47
|
// Translate the text and merge it into the English object
|
|
46
48
|
|
|
47
49
|
if (!onlyMissing || targetObj[prop] === undefined || targetObj[prop] === '') {
|
|
48
|
-
targetObj[prop] = await translateTextOrObject(
|
|
49
|
-
newOriginalObj[prop],
|
|
50
|
+
targetObj[prop] = await translateTextOrObject({
|
|
51
|
+
text: newOriginalObj[prop],
|
|
50
52
|
language,
|
|
51
53
|
sourceLanguage,
|
|
52
|
-
|
|
54
|
+
settings,
|
|
55
|
+
})
|
|
53
56
|
} else {
|
|
54
57
|
// targetObj[prop] = 'not translated'
|
|
55
58
|
}
|
|
@@ -67,6 +70,7 @@ export async function deepCompareTranslateAndMerge(
|
|
|
67
70
|
action,
|
|
68
71
|
onlyMissing,
|
|
69
72
|
sourceLanguage,
|
|
73
|
+
settings,
|
|
70
74
|
)
|
|
71
75
|
}
|
|
72
76
|
}
|
package/src/handleTranslate.ts
CHANGED
|
@@ -13,6 +13,8 @@ export const createTranslatorHandler = (translatorConfig: PluginTypes): PayloadH
|
|
|
13
13
|
|
|
14
14
|
const collectionOptions = translatorConfig.collections[req.collection.config.slug]
|
|
15
15
|
|
|
16
|
+
const settings = req.body.settings || {}
|
|
17
|
+
|
|
16
18
|
// const translator = aiTranslate({ collectionOptions, collection: req.collection }, 'fallback')
|
|
17
19
|
|
|
18
20
|
const result = await translateCollection({
|
|
@@ -24,6 +26,7 @@ export const createTranslatorHandler = (translatorConfig: PluginTypes): PayloadH
|
|
|
24
26
|
collection: req.collection.config,
|
|
25
27
|
onlyMissing: req.body.onlyMissing,
|
|
26
28
|
codes: req.body.codes,
|
|
29
|
+
settings,
|
|
27
30
|
})
|
|
28
31
|
/*if (translatorConfig.access) {
|
|
29
32
|
const hasAccesses = await translatorConfig.access(req)
|
package/src/plugin.ts
CHANGED
|
@@ -125,7 +125,7 @@ export const aiTranslatorPlugin =
|
|
|
125
125
|
return config
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
config.collections = [...(config.collections || []), stringTranslations]
|
|
128
|
+
config.collections = [...(config.collections || []), stringTranslations(pluginOptions)]
|
|
129
129
|
|
|
130
130
|
config.globals = [
|
|
131
131
|
...(config.globals || []),
|
|
@@ -19,26 +19,28 @@ const TextAreaBlock: Block = {
|
|
|
19
19
|
],
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const stringTranslations: CollectionConfig
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const stringTranslations = (pluginOptions: any): CollectionConfig => {
|
|
23
|
+
return {
|
|
24
|
+
slug: 'translations',
|
|
25
|
+
admin: {
|
|
26
|
+
useAsTitle: 'key',
|
|
27
|
+
},
|
|
28
|
+
access: {
|
|
29
|
+
read: anyone,
|
|
30
|
+
/*update: admins,
|
|
30
31
|
create: admins,
|
|
31
32
|
delete: admins,*/
|
|
32
|
-
|
|
33
|
+
},
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
hooks: {
|
|
36
|
+
afterChange: [
|
|
37
|
+
aiTranslate({
|
|
38
|
+
collection: { slug: 'translations' },
|
|
39
|
+
collectionOptions: { fields: ['content'] },
|
|
40
|
+
pluginOptions,
|
|
41
|
+
}),
|
|
42
|
+
async (req: any) => {
|
|
43
|
+
/*if (req.user && req.user.role === 'admin') {
|
|
42
44
|
return req
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -52,94 +54,95 @@ const stringTranslations: CollectionConfig = {
|
|
|
52
54
|
},
|
|
53
55
|
},
|
|
54
56
|
}*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
collection: 'translations',
|
|
66
|
-
where: {
|
|
67
|
-
key: {
|
|
68
|
-
equals: req.body.key,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
if (posts.docs.length > 0) {
|
|
74
|
-
res.status(200).send(posts.docs)
|
|
75
|
-
} else {
|
|
76
|
-
const newPost = await req.payload.create({
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
endpoints: [
|
|
61
|
+
{
|
|
62
|
+
path: '/create-missing',
|
|
63
|
+
//path: '/:id/tracking',
|
|
64
|
+
method: 'post',
|
|
65
|
+
handler: async (req: any, res: any, next: any) => {
|
|
66
|
+
const posts = await req.payload.find({
|
|
77
67
|
collection: 'translations',
|
|
78
|
-
|
|
79
|
-
key:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
content: req.body.content,
|
|
84
|
-
blockType: 'translation-textarea',
|
|
85
|
-
},
|
|
86
|
-
],
|
|
68
|
+
where: {
|
|
69
|
+
key: {
|
|
70
|
+
equals: req.body.key,
|
|
71
|
+
},
|
|
87
72
|
},
|
|
88
73
|
})
|
|
89
74
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
if (posts.docs.length > 0) {
|
|
76
|
+
res.status(200).send(posts.docs)
|
|
77
|
+
} else {
|
|
78
|
+
const newPost = await req.payload.create({
|
|
79
|
+
collection: 'translations',
|
|
80
|
+
data: {
|
|
81
|
+
key: req.body.key,
|
|
82
|
+
namespace: req.body.namespace,
|
|
83
|
+
translation: [
|
|
84
|
+
{
|
|
85
|
+
content: req.body.content,
|
|
86
|
+
blockType: 'translation-textarea',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
res.status(200).send(newPost)
|
|
93
|
+
//res.status(404).send({ error: 'not found' })
|
|
94
|
+
}
|
|
95
|
+
},
|
|
93
96
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
{
|
|
98
|
+
path: '/translate',
|
|
99
|
+
method: 'post',
|
|
100
|
+
handler: createTranslatorHandler({
|
|
101
|
+
collections: {
|
|
102
|
+
translations: {
|
|
103
|
+
fields: ['content'],
|
|
104
|
+
},
|
|
102
105
|
},
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
fields: [
|
|
110
|
+
{
|
|
111
|
+
type: 'row',
|
|
112
|
+
fields: [
|
|
113
|
+
{
|
|
114
|
+
name: 'key',
|
|
115
|
+
type: 'text',
|
|
116
|
+
required: true,
|
|
117
|
+
admin: {
|
|
118
|
+
width: '50%',
|
|
119
|
+
},
|
|
117
120
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: 'translation',
|
|
127
|
-
type: 'blocks',
|
|
128
|
-
minRows: 1,
|
|
129
|
-
maxRows: 1,
|
|
130
|
-
blocks: [TextAreaBlock],
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: 'translator',
|
|
134
|
-
type: 'ui',
|
|
135
|
-
admin: {
|
|
136
|
-
position: 'sidebar',
|
|
137
|
-
components: {
|
|
138
|
-
Field: Translator,
|
|
139
|
-
},
|
|
121
|
+
{
|
|
122
|
+
name: 'namespace',
|
|
123
|
+
type: 'text',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
140
126
|
},
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
{
|
|
128
|
+
name: 'translation',
|
|
129
|
+
type: 'blocks',
|
|
130
|
+
minRows: 1,
|
|
131
|
+
maxRows: 1,
|
|
132
|
+
blocks: [TextAreaBlock],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'translator',
|
|
136
|
+
type: 'ui',
|
|
137
|
+
admin: {
|
|
138
|
+
position: 'sidebar',
|
|
139
|
+
components: {
|
|
140
|
+
Field: Translator,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
} as Field,
|
|
144
|
+
],
|
|
145
|
+
}
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
export default stringTranslations
|
|
@@ -94,12 +94,21 @@ function reapplyText(
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
text: any
|
|
99
|
-
language: string
|
|
100
|
-
sourceLanguage?: string
|
|
101
|
-
retryCount
|
|
102
|
-
|
|
97
|
+
interface TranslateTextOrObject {
|
|
98
|
+
text: any
|
|
99
|
+
language: string
|
|
100
|
+
sourceLanguage?: string
|
|
101
|
+
retryCount?: number
|
|
102
|
+
setting: any
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function translateTextOrObject({
|
|
106
|
+
text,
|
|
107
|
+
language,
|
|
108
|
+
sourceLanguage,
|
|
109
|
+
retryCount = 0,
|
|
110
|
+
settings,
|
|
111
|
+
}: any) {
|
|
103
112
|
function isTranslateNode(node: any, key: string) {
|
|
104
113
|
return (key === 'text' && typeof node[key] === 'string') || key === 'name'
|
|
105
114
|
}
|
|
@@ -115,7 +124,6 @@ export async function translateTextOrObject(
|
|
|
115
124
|
extractAndCapitalizeText(text.root, ['root'], textMap, isTranslateNode)
|
|
116
125
|
}
|
|
117
126
|
|
|
118
|
-
console.log('textMap', JSON.stringify(text, null, 2))
|
|
119
127
|
const chatCompletion = await openai.chat.completions.create({
|
|
120
128
|
model: /* textAsString.length > 2000 ? 'gpt-3.5-turbo-16k' :*/ 'gpt-3.5-turbo-1106', /// 'gpt-3.5-turbo', // gpt-3.5-turbo-1106 // gpt-3.5-turbo-16k-0613
|
|
121
129
|
messages:
|
|
@@ -131,6 +139,7 @@ export async function translateTextOrObject(
|
|
|
131
139
|
top_p: 1,
|
|
132
140
|
frequency_penalty: 0,
|
|
133
141
|
presence_penalty: 0,
|
|
142
|
+
...settings,
|
|
134
143
|
})
|
|
135
144
|
|
|
136
145
|
console.log(
|
|
@@ -162,12 +171,14 @@ export async function translateTextOrObject(
|
|
|
162
171
|
)
|
|
163
172
|
|
|
164
173
|
await new Promise(resolve => setTimeout(resolve, error.headers['retry-after-ms']))
|
|
165
|
-
const newResult: any = await translateTextOrObject(
|
|
174
|
+
const newResult: any = await translateTextOrObject({
|
|
166
175
|
text,
|
|
167
176
|
language,
|
|
168
177
|
sourceLanguage,
|
|
169
|
-
retryCount + 1,
|
|
170
|
-
|
|
178
|
+
retryCount: retryCount + 1,
|
|
179
|
+
settings,
|
|
180
|
+
})
|
|
181
|
+
|
|
171
182
|
return newResult
|
|
172
183
|
} else {
|
|
173
184
|
console.log(
|
package/dist/access/admins.d.ts
DELETED
package/dist/access/admins.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.admins = void 0;
|
|
4
|
-
var checkRole_1 = require("./checkRole");
|
|
5
|
-
var admins = function (_a) {
|
|
6
|
-
var user = _a.req.user;
|
|
7
|
-
if (!user)
|
|
8
|
-
return false;
|
|
9
|
-
return (0, checkRole_1.checkRole)(['admin'], user);
|
|
10
|
-
};
|
|
11
|
-
exports.admins = admins;
|
|
12
|
-
//# sourceMappingURL=admins.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admins.js","sourceRoot":"","sources":["../../src/access/admins.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAKhC,IAAM,MAAM,GAAY,UAAC,EAAiB;QAAR,IAAI,cAAA;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IACvB,OAAO,IAAA,qBAAS,EAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC,CAAA;AAHY,QAAA,MAAM,UAGlB"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.adminsOrPublished = void 0;
|
|
4
|
-
var checkRole_1 = require("./checkRole");
|
|
5
|
-
var adminsOrPublished = function (_a) {
|
|
6
|
-
var user = _a.req.user;
|
|
7
|
-
if (user && (0, checkRole_1.checkRole)(['admin'], user)) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
return true;
|
|
11
|
-
return {
|
|
12
|
-
_status: {
|
|
13
|
-
equals: 'published',
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
exports.adminsOrPublished = adminsOrPublished;
|
|
18
|
-
//# sourceMappingURL=adminsOrPublished.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adminsOrPublished.js","sourceRoot":"","sources":["../../src/access/adminsOrPublished.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAEhC,IAAM,iBAAiB,GAAW,UAAC,EAAiB;QAAR,IAAI,cAAA;IACrD,IAAI,IAAI,IAAI,IAAA,qBAAS,EAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE;QACtC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAI,CAAA;IACX,OAAO;QACL,OAAO,EAAE;YACP,MAAM,EAAE,WAAW;SACpB;KACF,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,iBAAiB,qBAW7B"}
|
package/dist/access/anyone.d.ts
DELETED
package/dist/access/anyone.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anyone.js","sourceRoot":"","sources":["../../src/access/anyone.ts"],"names":[],"mappings":";;;AAEO,IAAM,MAAM,GAAW,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAA;AAA3B,QAAA,MAAM,UAAqB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const checkRole: (allRoles: any, user?: any) => boolean;
|
package/dist/access/checkRole.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//import type { User } from '../../payload-types'
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.checkRole = void 0;
|
|
5
|
-
var checkRole = function (allRoles /* User['roles'] = [] */, user) {
|
|
6
|
-
if (user) {
|
|
7
|
-
if (allRoles.some(function (role) {
|
|
8
|
-
var _a;
|
|
9
|
-
return (_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.some(function (individualRole) {
|
|
10
|
-
return individualRole === role;
|
|
11
|
-
});
|
|
12
|
-
}))
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
17
|
-
exports.checkRole = checkRole;
|
|
18
|
-
//# sourceMappingURL=checkRole.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkRole.js","sourceRoot":"","sources":["../../src/access/checkRole.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAE1C,IAAM,SAAS,GAAG,UAAC,QAAa,CAAC,wBAAwB,EAAE,IAAU;IAC1E,IAAI,IAAI,EAAE;QACR,IACE,QAAQ,CAAC,IAAI,CAAC,UAAC,IAAS;;YACtB,OAAO,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,IAAI,CAAC,UAAC,cAAmB;gBAC3C,OAAO,cAAc,KAAK,IAAI,CAAA;YAChC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC;YAEF,OAAO,IAAI,CAAA;KACd;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAbY,QAAA,SAAS,aAarB"}
|
package/dist/aiTranslate.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CollectionAfterChangeHook } from 'payload/types';
|
|
2
|
-
declare const aiTranslateHook: ({ collectionOptions, collection }: {
|
|
3
|
-
collectionOptions: any;
|
|
4
|
-
collection: object;
|
|
5
|
-
}, fallback?: string) => CollectionAfterChangeHook;
|
|
6
|
-
export default aiTranslateHook;
|
|
7
|
-
export declare function translateCollection({ req, doc, collection, previousDoc, context, collectionOptions, onlyMissing, codes, }: any): Promise<void>;
|