@ai-stack/payloadcms 3.0.0-beta.95.2 → 3.2.1-beta
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/LICENSE.md +2 -2
- package/README.md +19 -17
- package/dist/ai/models/anthropic/generateRichText.d.ts.map +1 -1
- package/dist/ai/models/anthropic/generateRichText.js +2 -2
- package/dist/ai/models/anthropic/generateRichText.js.map +1 -1
- package/dist/ai/models/anthropic/index.d.ts.map +1 -1
- package/dist/ai/models/anthropic/index.js +8 -32
- package/dist/ai/models/anthropic/index.js.map +1 -1
- package/dist/ai/models/elevenLabs/generateVoice.d.ts +1 -1
- package/dist/ai/models/elevenLabs/index.d.ts.map +1 -1
- package/dist/ai/models/elevenLabs/index.js +4 -3
- package/dist/ai/models/elevenLabs/index.js.map +1 -1
- package/dist/ai/models/openai/generateImage.d.ts +1 -1
- package/dist/ai/models/openai/generateRichText.js +2 -2
- package/dist/ai/models/openai/generateRichText.js.map +1 -1
- package/dist/ai/models/openai/generateVoice.d.ts +1 -1
- package/dist/ai/models/openai/index.d.ts.map +1 -1
- package/dist/ai/models/openai/index.js +9 -35
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/prompts.d.ts +1 -1
- package/dist/ai/prompts.d.ts.map +1 -1
- package/dist/ai/prompts.js +6 -3
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.d.ts +2 -0
- package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +1 -0
- package/dist/ai/schemas/lexicalJsonSchema.js +317 -0
- package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -0
- package/dist/ai/utils/generateFileNameByPrompt.js.map +1 -1
- package/dist/ai/utils/systemGenerate.d.ts +5 -0
- package/dist/ai/utils/systemGenerate.d.ts.map +1 -0
- package/dist/ai/utils/{generateSeedPrompt.js → systemGenerate.js} +2 -2
- package/dist/ai/utils/systemGenerate.js.map +1 -0
- package/dist/collections/Instructions.d.ts +1 -1
- package/dist/collections/Instructions.d.ts.map +1 -1
- package/dist/collections/Instructions.js +177 -85
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.js.map +1 -1
- package/dist/endpoints/fetchFields.d.ts +3 -0
- package/dist/endpoints/fetchFields.d.ts.map +1 -0
- package/dist/endpoints/fetchFields.js +21 -0
- package/dist/endpoints/fetchFields.js.map +1 -0
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +12 -18
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/fields.d.ts +2 -1
- package/dist/exports/fields.d.ts.map +1 -1
- package/dist/exports/fields.js +2 -1
- package/dist/exports/fields.js.map +1 -1
- package/dist/fields/ComposeField/ComposeField.d.ts +3 -0
- package/dist/fields/ComposeField/ComposeField.d.ts.map +1 -0
- package/dist/fields/ComposeField/ComposeField.js +24 -0
- package/dist/fields/ComposeField/ComposeField.js.map +1 -0
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts +2 -0
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +1 -0
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.js +28 -0
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.js.map +1 -0
- package/dist/fields/LexicalEditor/feature.client.d.ts +4 -1
- package/dist/fields/LexicalEditor/feature.client.d.ts.map +1 -1
- package/dist/fields/LexicalEditor/feature.client.js +15 -7
- package/dist/fields/LexicalEditor/feature.client.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts +2 -2
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +4 -8
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/SelectField/SelectField.d.ts +3 -2
- package/dist/fields/SelectField/SelectField.d.ts.map +1 -1
- package/dist/fields/SelectField/SelectField.js +2 -3
- package/dist/fields/SelectField/SelectField.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +2 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +22 -21
- package/dist/init.js.map +1 -1
- package/dist/libraries/autocomplete/AutocompleteTextArea.js +9 -7
- package/dist/libraries/autocomplete/AutocompleteTextArea.js.map +1 -1
- package/dist/libraries/handlebars/asyncHandlebars.js +1 -1
- package/dist/libraries/handlebars/asyncHandlebars.js.map +1 -1
- package/dist/libraries/handlebars/helpers.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +30 -41
- package/dist/plugin.js.map +1 -1
- package/dist/providers/FieldProvider/FieldProvider.d.ts +15 -0
- package/dist/providers/FieldProvider/FieldProvider.d.ts.map +1 -0
- package/dist/providers/FieldProvider/FieldProvider.js +33 -0
- package/dist/providers/FieldProvider/FieldProvider.js.map +1 -0
- package/dist/providers/FieldProvider/useFieldProps.d.ts +6 -0
- package/dist/providers/FieldProvider/useFieldProps.d.ts.map +1 -0
- package/dist/providers/FieldProvider/useFieldProps.js +12 -0
- package/dist/providers/FieldProvider/useFieldProps.js.map +1 -0
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +5 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js +12 -7
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.d.ts +2 -2
- package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.js +17 -4
- package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
- package/dist/types.d.ts +9 -41
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -4
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.d.ts +9 -0
- package/dist/ui/Compose/Compose.d.ts.map +1 -0
- package/dist/ui/{Actions/Actions.js → Compose/Compose.js} +49 -39
- package/dist/ui/Compose/Compose.js.map +1 -0
- package/dist/ui/{Actions → Compose}/UndoRedoActions.d.ts.map +1 -1
- package/dist/ui/{Actions → Compose}/UndoRedoActions.js +15 -2
- package/dist/ui/Compose/UndoRedoActions.js.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/menu/Item.d.ts +1 -1
- package/dist/ui/{Actions → Compose}/hooks/menu/Item.d.ts.map +1 -1
- package/dist/ui/{Actions → Compose}/hooks/menu/Item.js +2 -2
- package/dist/ui/{Actions → Compose}/hooks/menu/Item.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/menu/TranslateMenu.js +11 -11
- package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/menu/items.d.ts +8 -8
- package/dist/ui/{Actions → Compose}/hooks/menu/items.d.ts.map +1 -1
- package/dist/ui/{Actions → Compose}/hooks/menu/items.js.map +1 -1
- package/dist/ui/{Actions → Compose}/hooks/menu/itemsMap.d.ts +1 -1
- package/dist/ui/Compose/hooks/menu/itemsMap.d.ts.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/menu/itemsMap.js +1 -2
- package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -0
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/menu/useMenu.js +2 -1
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/useGenerate.d.ts +3 -1
- package/dist/ui/Compose/hooks/useGenerate.d.ts.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/useGenerate.js +19 -24
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -0
- package/dist/ui/Compose/hooks/useHistory.d.ts.map +1 -0
- package/dist/ui/{Actions → Compose}/hooks/useHistory.js +6 -3
- package/dist/ui/Compose/hooks/useHistory.js.map +1 -0
- package/dist/utilities/setSafeLexicalState.d.ts +2 -2
- package/dist/utilities/setSafeLexicalState.d.ts.map +1 -1
- package/dist/utilities/setSafeLexicalState.js +5 -12
- package/dist/utilities/setSafeLexicalState.js.map +1 -1
- package/dist/utilities/updateFieldsConfig.d.ts.map +1 -1
- package/dist/utilities/updateFieldsConfig.js +18 -6
- package/dist/utilities/updateFieldsConfig.js.map +1 -1
- package/package.json +33 -60
- package/dist/ai/schemas/lexical.schema.d.ts +0 -31
- package/dist/ai/schemas/lexical.schema.d.ts.map +0 -1
- package/dist/ai/schemas/lexical.schema.js +0 -102
- package/dist/ai/schemas/lexical.schema.js.map +0 -1
- package/dist/ai/utils/generateSeedPrompt.d.ts +0 -5
- package/dist/ai/utils/generateSeedPrompt.d.ts.map +0 -1
- package/dist/ai/utils/generateSeedPrompt.js.map +0 -1
- package/dist/fields/DescriptionField/DescriptionField.d.ts +0 -4
- package/dist/fields/DescriptionField/DescriptionField.d.ts.map +0 -1
- package/dist/fields/DescriptionField/DescriptionField.js +0 -18
- package/dist/fields/DescriptionField/DescriptionField.js.map +0 -1
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.d.ts +0 -2
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.d.ts.map +0 -1
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.js +0 -15
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.js.map +0 -1
- package/dist/ui/Actions/Actions.d.ts +0 -5
- package/dist/ui/Actions/Actions.d.ts.map +0 -1
- package/dist/ui/Actions/Actions.js.map +0 -1
- package/dist/ui/Actions/UndoRedoActions.js.map +0 -1
- package/dist/ui/Actions/hooks/menu/TranslateMenu.d.ts.map +0 -1
- package/dist/ui/Actions/hooks/menu/TranslateMenu.js.map +0 -1
- package/dist/ui/Actions/hooks/menu/itemsMap.d.ts.map +0 -1
- package/dist/ui/Actions/hooks/menu/itemsMap.js.map +0 -1
- package/dist/ui/Actions/hooks/menu/useMenu.d.ts.map +0 -1
- package/dist/ui/Actions/hooks/menu/useMenu.js.map +0 -1
- package/dist/ui/Actions/hooks/useGenerate.d.ts.map +0 -1
- package/dist/ui/Actions/hooks/useGenerate.js.map +0 -1
- package/dist/ui/Actions/hooks/useHistory.d.ts.map +0 -1
- package/dist/ui/Actions/hooks/useHistory.js.map +0 -1
- package/dist/utilities/jsonToZod.d.ts +0 -3
- package/dist/utilities/jsonToZod.d.ts.map +0 -1
- package/dist/utilities/jsonToZod.js +0 -33
- package/dist/utilities/jsonToZod.js.map +0 -1
- /package/dist/ui/{Actions → Compose}/UndoRedoActions.d.ts +0 -0
- /package/dist/ui/{Actions/actions.module.scss → Compose/compose.module.scss} +0 -0
- /package/dist/ui/{Actions → Compose}/hooks/menu/TranslateMenu.d.ts +0 -0
- /package/dist/ui/{Actions → Compose}/hooks/menu/items.js +0 -0
- /package/dist/ui/{Actions → Compose}/hooks/menu/menu.module.scss +0 -0
- /package/dist/ui/{Actions → Compose}/hooks/menu/useMenu.d.ts +0 -0
- /package/dist/ui/{Actions → Compose}/hooks/useHistory.d.ts +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
## 1. MIT License (for open-source use)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2024 Ashish Mishra
|
|
4
4
|
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
# Payload AI Plugin
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img alt="Payload AI Plugin" src="assets/
|
|
4
|
+
<img alt="Payload AI Plugin" src="assets/payload-ai-intro.gif" width="100%" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
## 🌟 Supercharge Your [Payload CMS](https://payloadcms.com) with AI-Powered Content Creation
|
|
8
8
|
|
|
9
9
|
The Payload AI Plugin is an advanced extension that integrates modern AI capabilities into your Payload CMS, streamlining content creation and management.
|
|
10
10
|
|
|
11
|
-
> **⚠️ Important:** This plugin is in active development. We're doing our best to improve its features and functionality. Please be prepared for regular updates; at the moment, the plugin has only been tested with Payload version
|
|
11
|
+
> **⚠️ Important:** This plugin is in active development. We're doing our best to improve its features and functionality. Please be prepared for regular updates; at the moment, the plugin has only been tested with Payload version v3.0.0-beta.104.
|
|
12
12
|
>
|
|
13
|
-
> To give it a try, we recommend using [Payload's website template](https://github.com/payloadcms/payload/tree/v3.0.0-beta.
|
|
13
|
+
> To give it a try, we recommend using [Payload's website template](https://github.com/payloadcms/payload/tree/v3.0.0-beta.104/templates/website).
|
|
14
|
+
|
|
15
|
+
---
|
|
14
16
|
|
|
15
17
|
### 🎥 [Watch the Magic in Action](https://youtu.be/qaYukeGpuu4)
|
|
18
|
+
Want to dive deeper?
|
|
19
|
+
### 🎥 [Explore More in Our Extended Demo](https://youtu.be/LEsuHbKalNY)
|
|
16
20
|
|
|
17
21
|
|
|
18
22
|
## ✨ Supported Fields and Features
|
|
@@ -38,6 +42,7 @@ The Payload AI Plugin is an advanced extension that integrates modern AI capabil
|
|
|
38
42
|
- ✅ **Fact Checking** (Coming Soon)
|
|
39
43
|
- 🔄 **Automated Content Workflows** (Coming Soon)
|
|
40
44
|
- 🌍 **Internationalization Support** (Coming Soon)
|
|
45
|
+
- 🌍 **Editor AI suggestions** (Coming Soon)
|
|
41
46
|
- 💬 **AI Chat Support** (Coming Soon)
|
|
42
47
|
|
|
43
48
|
## 📚 Table of Contents
|
|
@@ -46,7 +51,6 @@ The Payload AI Plugin is an advanced extension that integrates modern AI capabil
|
|
|
46
51
|
- [Usage](#-usage)
|
|
47
52
|
- [Configuration](#%EF%B8%8F-configuration)
|
|
48
53
|
- [Contributing](#-contributing)
|
|
49
|
-
- [License](#licensing)
|
|
50
54
|
|
|
51
55
|
## 📦 Installation
|
|
52
56
|
|
|
@@ -101,7 +105,8 @@ fields: [
|
|
|
101
105
|
|
|
102
106
|
## ⚙️ Configuration
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
Choose your AI model by providing one or more of the following environment variables.
|
|
109
|
+
Create a .env file in your project root and add any of the following variables:
|
|
105
110
|
|
|
106
111
|
```
|
|
107
112
|
OPENAI_API_KEY=your-openai-api-key
|
|
@@ -109,19 +114,16 @@ ANTHROPIC_API_KEY=your-anthropic-api-key
|
|
|
109
114
|
ELEVENLABS_API_KEY=your-elevenlabs-api-key
|
|
110
115
|
```
|
|
111
116
|
|
|
117
|
+
### Enabling AI for Custom Components
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
This plugin is available under dual licensing:
|
|
120
|
-
|
|
121
|
-
- ### Open-Source License
|
|
119
|
+
> **⚠️ Note:** Custom fields don't fully adhere to the Payload schema, making it difficult to determine which components support injecting ComposeField as a Description.
|
|
120
|
+
> If AI enabled fields don't display Compose settings, please manually add the following component path:
|
|
121
|
+
>
|
|
122
|
+
> `@ai-stack/payloadcms/fields#ComposeField`
|
|
123
|
+
>
|
|
124
|
+
> To view AI enabled fields, enable the `debugging` flag in your plugin config or check your server startup logs.
|
|
122
125
|
|
|
123
|
-
This plugin is available under the [MIT License](LICENSE.md). You can use, modify, and distribute it freely under the terms of this license.
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
## 👥 Contributing
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
Innovators: welcome! We're always excited to expand our community. Connect with us on [Discord](https://discord.com/channels/967097582721572934/1264949995656843345) to get started.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,SAAgB,MAAM,WAAW,GAAG,sBAiChE,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
2
|
-
import { streamObject } from 'ai';
|
|
2
|
+
import { jsonSchema, streamObject } from 'ai';
|
|
3
3
|
import { exampleOutput } from '../example.js';
|
|
4
4
|
export const generateRichText = async (text, options)=>{
|
|
5
5
|
const streamResult = await streamObject({
|
|
6
6
|
model: anthropic(options.model),
|
|
7
7
|
prompt: text,
|
|
8
|
-
schema: options.editorSchema,
|
|
8
|
+
schema: jsonSchema(options.editorSchema),
|
|
9
9
|
system: `${options.system}
|
|
10
10
|
|
|
11
11
|
RULES:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { streamObject } from 'ai'\nimport { exampleOutput } from '../example.js'\n\nexport const generateRichText = async (text: string, options: any) => {\n const streamResult = await streamObject({\n model: anthropic(options.model),\n prompt: text,\n schema: options.editorSchema,\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nSAMPLE OUTPUT OBJECT:\n${JSON.stringify(exampleOutput)}\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n- Double-check that all JSON fields are properly filled and formatted.`,\n })\n\n return streamResult.toTextStreamResponse()\n}\n"],"names":["anthropic","streamObject","exampleOutput","generateRichText","text","options","streamResult","model","prompt","schema","editorSchema","system","layout","JSON","stringify","toTextStreamResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,YAAY,QAAQ,KAAI;
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { jsonSchema, streamObject } from 'ai'\n\nimport { exampleOutput } from '../example.js'\n\nexport const generateRichText = async (text: string, options: any) => {\n const streamResult = await streamObject({\n model: anthropic(options.model),\n prompt: text,\n schema: jsonSchema(options.editorSchema),\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nSAMPLE OUTPUT OBJECT:\n${JSON.stringify(exampleOutput)}\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n- Double-check that all JSON fields are properly filled and formatted.`,\n })\n\n return streamResult.toTextStreamResponse()\n}\n"],"names":["anthropic","jsonSchema","streamObject","exampleOutput","generateRichText","text","options","streamResult","model","prompt","schema","editorSchema","system","layout","JSON","stringify","toTextStreamResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,aAAa,QAAQ,gBAAe;AAE7C,OAAO,MAAMC,mBAAmB,OAAOC,MAAcC;IACnD,MAAMC,eAAe,MAAML,aAAa;QACtCM,OAAOR,UAAUM,QAAQE,KAAK;QAC9BC,QAAQJ;QACRK,QAAQT,WAAWK,QAAQK,YAAY;QACvCC,QAAQ,GAAGN,QAAQM,MAAM,CAAC;;;;;;;;;;AAU9B,EAAEN,QAAQO,MAAM,CAAC;;;;;;;;AAQjB,EAAEC,KAAKC,SAAS,CAACZ,eAAe;;;;;;sEAMsC,CAAC;IACrE;IAEA,OAAOI,aAAaS,oBAAoB;AAC1C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/anthropic/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/anthropic/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAOzD,eAAO,MAAM,eAAe,EAAE,gBA+E7B,CAAA"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
2
2
|
import { streamText } from 'ai';
|
|
3
|
-
import { generateRichText } from './generateRichText.js';
|
|
4
3
|
import { defaultSystemPrompt } from '../../prompts.js';
|
|
4
|
+
import { generateRichText } from './generateRichText.js';
|
|
5
|
+
const MODEL_KEY = 'ANTH-C';
|
|
5
6
|
export const AnthropicConfig = {
|
|
6
7
|
models: [
|
|
7
8
|
{
|
|
8
|
-
id:
|
|
9
|
+
id: `${MODEL_KEY}-text`,
|
|
9
10
|
name: 'Anthropic Claude',
|
|
10
11
|
fields: [
|
|
11
12
|
'text',
|
|
12
13
|
'textarea'
|
|
13
14
|
],
|
|
14
15
|
handler: async (prompt, options)=>{
|
|
15
|
-
console.log('options ', options);
|
|
16
|
-
console.log('prompt ', prompt);
|
|
17
16
|
const streamTextResult = await streamText({
|
|
18
17
|
model: anthropic(options.model),
|
|
19
18
|
prompt,
|
|
@@ -23,11 +22,11 @@ export const AnthropicConfig = {
|
|
|
23
22
|
},
|
|
24
23
|
output: 'text',
|
|
25
24
|
settings: {
|
|
26
|
-
name:
|
|
25
|
+
name: `${MODEL_KEY}-text-settings`,
|
|
27
26
|
type: 'group',
|
|
28
27
|
admin: {
|
|
29
28
|
condition (data) {
|
|
30
|
-
return data['model-id'] ===
|
|
29
|
+
return data['model-id'] === `${MODEL_KEY}-text`;
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
fields: [
|
|
@@ -48,7 +47,7 @@ export const AnthropicConfig = {
|
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
{
|
|
51
|
-
id:
|
|
50
|
+
id: `${MODEL_KEY}-object`,
|
|
52
51
|
name: 'Anthropic Claude',
|
|
53
52
|
fields: [
|
|
54
53
|
'richText'
|
|
@@ -58,11 +57,11 @@ export const AnthropicConfig = {
|
|
|
58
57
|
},
|
|
59
58
|
output: 'text',
|
|
60
59
|
settings: {
|
|
61
|
-
name:
|
|
60
|
+
name: `${MODEL_KEY}-object-settings`,
|
|
62
61
|
type: 'group',
|
|
63
62
|
admin: {
|
|
64
63
|
condition (data) {
|
|
65
|
-
return data['model-id'] ===
|
|
64
|
+
return data['model-id'] === `${MODEL_KEY}-object`;
|
|
66
65
|
}
|
|
67
66
|
},
|
|
68
67
|
fields: [
|
|
@@ -77,29 +76,6 @@ export const AnthropicConfig = {
|
|
|
77
76
|
'claude-3-opus-20240229',
|
|
78
77
|
'claude-3-5-sonnet-20240620'
|
|
79
78
|
]
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'system',
|
|
83
|
-
type: 'textarea',
|
|
84
|
-
defaultValue: `INSTRUCTIONS:
|
|
85
|
-
You are a highly skilled and professional blog writer,
|
|
86
|
-
renowned for crafting engaging and well-organized articles.
|
|
87
|
-
When given a title, you meticulously create blogs that are not only
|
|
88
|
-
informative and accurate but also captivating and beautifully structured.`,
|
|
89
|
-
label: 'System prompt'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'layout',
|
|
93
|
-
type: 'textarea',
|
|
94
|
-
defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.
|
|
95
|
-
[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.
|
|
96
|
-
[list] - Create a list with 3-5 items. Each list item should contain:
|
|
97
|
-
a. [heading] - A brief, descriptive heading (up to 5 words)
|
|
98
|
-
b. [paragraph] - A short explanation or elaboration (1-2 sentences)
|
|
99
|
-
[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.
|
|
100
|
-
[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.
|
|
101
|
-
[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: "Quote text." - Author Name`,
|
|
102
|
-
label: 'Layout'
|
|
103
79
|
}
|
|
104
80
|
],
|
|
105
81
|
label: 'Anthropic Claude Settings'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/anthropic/index.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/anthropic/index.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateRichText } from './generateRichText.js'\n\nconst MODEL_KEY = 'ANTH-C'\n\nexport const AnthropicConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'Anthropic Claude',\n fields: ['text', 'textarea'],\n handler: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: anthropic(options.model),\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'claude-3-5-sonnet-20240620',\n label: 'Model',\n options: [\n 'claude-3-haiku-20240307',\n 'claude-3-sonnet-20240229',\n 'claude-3-opus-20240229',\n 'claude-3-5-sonnet-20240620',\n ],\n },\n ],\n label: 'Anthropic Claude Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'Anthropic Claude',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'claude-3-5-sonnet-20240620',\n label: 'Model',\n options: [\n 'claude-3-haiku-20240307',\n 'claude-3-sonnet-20240229',\n 'claude-3-opus-20240229',\n 'claude-3-5-sonnet-20240620',\n ],\n },\n ],\n label: 'Anthropic Claude Settings',\n },\n },\n ],\n provider: 'Anthropic',\n}\n"],"names":["anthropic","streamText","defaultSystemPrompt","generateRichText","MODEL_KEY","AnthropicConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","text","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I,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BACP;4BACA;4BACA;4BACA;yBACD;oBACH;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDE,UAAU;AACZ,EAAC"}
|
|
@@ -4,7 +4,7 @@ type ElevenLabsTextToSpeechOptions = {
|
|
|
4
4
|
} & Pick<ElevenLabs.TextToSpeechWithTimstampsRequest, 'model_id' | 'next_text' | 'previous_text' | 'seed' | 'voice_settings'>;
|
|
5
5
|
export declare const generateVoice: (text: string, options: ElevenLabsTextToSpeechOptions) => Promise<{
|
|
6
6
|
alignment: string[];
|
|
7
|
-
buffer: Buffer
|
|
7
|
+
buffer: Buffer<ArrayBuffer>;
|
|
8
8
|
}>;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=generateVoice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/elevenLabs/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/elevenLabs/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAmGzD,eAAO,MAAM,gBAAgB,EAAE,gBAmC9B,CAAA"}
|
|
@@ -87,10 +87,11 @@ if (voiceOptions.length) {
|
|
|
87
87
|
required: true
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
+
const MODEL_KEY = '11Labs';
|
|
90
91
|
export const ElevenLabsConfig = {
|
|
91
92
|
models: [
|
|
92
93
|
{
|
|
93
|
-
id:
|
|
94
|
+
id: `${MODEL_KEY}-m-v2`,
|
|
94
95
|
name: 'ElevenLabs Multilingual v2',
|
|
95
96
|
fields: [
|
|
96
97
|
'upload'
|
|
@@ -111,11 +112,11 @@ export const ElevenLabsConfig = {
|
|
|
111
112
|
},
|
|
112
113
|
output: 'audio',
|
|
113
114
|
settings: {
|
|
114
|
-
name:
|
|
115
|
+
name: `${MODEL_KEY}-settings`,
|
|
115
116
|
type: 'group',
|
|
116
117
|
admin: {
|
|
117
118
|
condition: (data)=>{
|
|
118
|
-
return data['model-id'] ===
|
|
119
|
+
return data['model-id'] === `${MODEL_KEY}-m-v2`;
|
|
119
120
|
}
|
|
120
121
|
},
|
|
121
122
|
fields,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/elevenLabs/index.ts"],"sourcesContent":["import type { Field, File } from 'payload'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateVoice } from './generateVoice.js'\nimport { getAllVoices } from './voices.js'\n\nconst { voices = [] } = await getAllVoices()\n\nconst voiceOptions = voices.map((voice) => {\n return {\n label: voice.name,\n value: voice.voice_id,\n ...voice,\n }\n})\n\nconst fieldVoiceOptions = voiceOptions.map((option) => {\n return {\n label: option.name,\n value: option.voice_id,\n }\n})\n\nconst fields: Field[] = [\n {\n type: 'collapsible',\n admin: {\n initCollapsed: false,\n },\n fields: [\n {\n name: 'stability',\n type: 'number',\n defaultValue: 0.5,\n label: 'Stability',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'similarity_boost',\n type: 'number',\n defaultValue: 0.5,\n label: 'Similarity Boost',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'style',\n type: 'number',\n defaultValue: 0.5,\n label: 'Style',\n max: 1,\n min: 0,\n },\n {\n name: 'use_speaker_boost',\n type: 'checkbox',\n label: 'Use Speaker Boost',\n },\n ],\n label: 'Voice Settings',\n },\n {\n name: 'seed',\n type: 'number',\n label: 'Seed',\n },\n {\n type: 'row',\n fields: [\n {\n name: 'previous_text',\n type: 'textarea',\n label: 'Previous Text',\n },\n {\n name: 'next_text',\n type: 'textarea',\n label: 'Next Text',\n },\n ],\n },\n]\n\nif (voiceOptions.length) {\n fields.unshift({\n name: 'voice_id',\n type: 'select',\n defaultValue: voiceOptions[0]?.voice_id,\n label: 'Voice',\n options: fieldVoiceOptions,\n required: true,\n })\n}\n\nexport const ElevenLabsConfig: GenerationConfig = {\n models: [\n {\n id:
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/elevenLabs/index.ts"],"sourcesContent":["import type { Field, File } from 'payload'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateVoice } from './generateVoice.js'\nimport { getAllVoices } from './voices.js'\n\nconst { voices = [] } = await getAllVoices()\n\nconst voiceOptions = voices.map((voice) => {\n return {\n label: voice.name,\n value: voice.voice_id,\n ...voice,\n }\n})\n\nconst fieldVoiceOptions = voiceOptions.map((option) => {\n return {\n label: option.name,\n value: option.voice_id,\n }\n})\n\nconst fields: Field[] = [\n {\n type: 'collapsible',\n admin: {\n initCollapsed: false,\n },\n fields: [\n {\n name: 'stability',\n type: 'number',\n defaultValue: 0.5,\n label: 'Stability',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'similarity_boost',\n type: 'number',\n defaultValue: 0.5,\n label: 'Similarity Boost',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'style',\n type: 'number',\n defaultValue: 0.5,\n label: 'Style',\n max: 1,\n min: 0,\n },\n {\n name: 'use_speaker_boost',\n type: 'checkbox',\n label: 'Use Speaker Boost',\n },\n ],\n label: 'Voice Settings',\n },\n {\n name: 'seed',\n type: 'number',\n label: 'Seed',\n },\n {\n type: 'row',\n fields: [\n {\n name: 'previous_text',\n type: 'textarea',\n label: 'Previous Text',\n },\n {\n name: 'next_text',\n type: 'textarea',\n label: 'Next Text',\n },\n ],\n },\n]\n\nif (voiceOptions.length) {\n fields.unshift({\n name: 'voice_id',\n type: 'select',\n defaultValue: voiceOptions[0]?.voice_id,\n label: 'Voice',\n options: fieldVoiceOptions,\n required: true,\n })\n}\n\nconst MODEL_KEY = '11Labs'\n\nexport const ElevenLabsConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-m-v2`,\n name: 'ElevenLabs Multilingual v2',\n fields: ['upload'],\n handler: async (text: string, options) => {\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: 'voice over',\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-settings`,\n type: 'group',\n admin: {\n condition: (data) => {\n return data['model-id'] === `${MODEL_KEY}-m-v2`\n },\n },\n fields,\n label: 'ElevenLabs Multilingual v2 Settings',\n },\n },\n ],\n provider: 'ElevenLabs',\n}\n"],"names":["generateFileNameByPrompt","generateVoice","getAllVoices","voices","voiceOptions","map","voice","label","name","value","voice_id","fieldVoiceOptions","option","fields","type","admin","initCollapsed","defaultValue","max","min","required","length","unshift","options","MODEL_KEY","ElevenLabsConfig","models","id","handler","text","voiceData","data","alt","file","buffer","mimetype","size","byteLength","output","settings","condition","provider"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,YAAY,QAAQ,cAAa;AAE1C,MAAM,EAAEC,SAAS,EAAE,EAAE,GAAG,MAAMD;AAE9B,MAAME,eAAeD,OAAOE,GAAG,CAAC,CAACC;IAC/B,OAAO;QACLC,OAAOD,MAAME,IAAI;QACjBC,OAAOH,MAAMI,QAAQ;QACrB,GAAGJ,KAAK;IACV;AACF;AAEA,MAAMK,oBAAoBP,aAAaC,GAAG,CAAC,CAACO;IAC1C,OAAO;QACLL,OAAOK,OAAOJ,IAAI;QAClBC,OAAOG,OAAOF,QAAQ;IACxB;AACF;AAEA,MAAMG,SAAkB;IACtB;QACEC,MAAM;QACNC,OAAO;YACLC,eAAe;QACjB;QACAH,QAAQ;YACN;gBACEL,MAAM;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AM;gBACNC,OAAO;oBACLyB,WAAW,CAACT;wBACV,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGP,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAX;gBACAN,OAAO;YACT;QACF;KACD;IACDkC,UAAU;AACZ,EAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { openai } from '@ai-sdk/openai';
|
|
2
|
-
import { streamObject } from 'ai';
|
|
2
|
+
import { jsonSchema, streamObject } from 'ai';
|
|
3
3
|
import { exampleOutput } from '../example.js';
|
|
4
4
|
export const generateRichText = async (text, options)=>{
|
|
5
5
|
const streamResult = await streamObject({
|
|
6
6
|
model: openai(options.model),
|
|
7
7
|
prompt: text,
|
|
8
|
-
schema: options.editorSchema,
|
|
8
|
+
schema: jsonSchema(options.editorSchema),
|
|
9
9
|
system: `${options.system}
|
|
10
10
|
|
|
11
11
|
RULES:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { openai } from '@ai-sdk/openai'\nimport { streamObject } from 'ai'\n\nimport { exampleOutput } from '../example.js'\n\nexport const generateRichText = async (text: string, options: any) => {\n const streamResult = await streamObject({\n model: openai(options.model),\n prompt: text,\n schema: options.editorSchema,\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nSAMPLE OUTPUT OBJECT:\n${JSON.stringify(exampleOutput)}\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n- Double-check that all JSON fields are properly filled and formatted.`,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["openai","streamObject","exampleOutput","generateRichText","text","options","streamResult","model","prompt","schema","editorSchema","system","layout","JSON","stringify","toTextStreamResponse"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,YAAY,QAAQ,KAAI;
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { openai } from '@ai-sdk/openai'\nimport { jsonSchema, streamObject } from 'ai'\n\nimport { exampleOutput } from '../example.js'\n\nexport const generateRichText = async (text: string, options: any) => {\n const streamResult = await streamObject({\n model: openai(options.model),\n prompt: text,\n schema: jsonSchema(options.editorSchema),\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nSAMPLE OUTPUT OBJECT:\n${JSON.stringify(exampleOutput)}\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n- Double-check that all JSON fields are properly filled and formatted.`,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["openai","jsonSchema","streamObject","exampleOutput","generateRichText","text","options","streamResult","model","prompt","schema","editorSchema","system","layout","JSON","stringify","toTextStreamResponse"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,aAAa,QAAQ,gBAAe;AAE7C,OAAO,MAAMC,mBAAmB,OAAOC,MAAcC;IACnD,MAAMC,eAAe,MAAML,aAAa;QACtCM,OAAOR,OAAOM,QAAQE,KAAK;QAC3BC,QAAQJ;QACRK,QAAQT,WAAWK,QAAQK,YAAY;QACvCC,QAAQ,GAAGN,QAAQM,MAAM,CAAC;;;;;;;;;;AAU9B,EAAEN,QAAQO,MAAM,CAAC;;;;;;;;AAQjB,EAAEC,KAAKC,SAAS,CAACZ,eAAe;;;;;;sEAMsC,CAAC;IACrE;IACA,OAAOI,aAAaS,oBAAoB;AAC1C,EAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SpeechCreateParams } from 'openai/resources/audio/speech';
|
|
2
2
|
type OpenAITextToSpeechOptions = Exclude<SpeechCreateParams, 'input'>;
|
|
3
3
|
export declare const generateVoice: (text: string, options: OpenAITextToSpeechOptions) => Promise<{
|
|
4
|
-
buffer: Buffer
|
|
4
|
+
buffer: Buffer<ArrayBufferLike>;
|
|
5
5
|
}>;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=generateVoice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAWzD,eAAO,MAAM,YAAY,EAAE,gBAsM1B,CAAA"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { openai } from '@ai-sdk/openai';
|
|
2
2
|
import { streamText } from 'ai';
|
|
3
|
+
import { defaultSystemPrompt } from '../../prompts.js';
|
|
3
4
|
import { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js';
|
|
4
5
|
import { generateImage } from './generateImage.js';
|
|
5
6
|
import { generateRichText } from './generateRichText.js';
|
|
6
7
|
import { generateVoice } from './generateVoice.js';
|
|
7
|
-
|
|
8
|
+
const MODEL_KEY = 'Oai';
|
|
8
9
|
//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code
|
|
9
10
|
export const OpenAIConfig = {
|
|
10
11
|
models: [
|
|
11
12
|
{
|
|
12
|
-
id:
|
|
13
|
+
id: `${MODEL_KEY}-text`,
|
|
13
14
|
name: 'OpenAI GPT Text',
|
|
14
15
|
fields: [
|
|
15
16
|
'text',
|
|
@@ -25,11 +26,11 @@ export const OpenAIConfig = {
|
|
|
25
26
|
},
|
|
26
27
|
output: 'text',
|
|
27
28
|
settings: {
|
|
28
|
-
name:
|
|
29
|
+
name: `${MODEL_KEY}-text-settings`,
|
|
29
30
|
type: 'group',
|
|
30
31
|
admin: {
|
|
31
32
|
condition (data) {
|
|
32
|
-
return data['model-id'] ===
|
|
33
|
+
return data['model-id'] === `${MODEL_KEY}-text`;
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
fields: [
|
|
@@ -149,7 +150,7 @@ export const OpenAIConfig = {
|
|
|
149
150
|
},
|
|
150
151
|
output: 'audio',
|
|
151
152
|
settings: {
|
|
152
|
-
name:
|
|
153
|
+
name: `${MODEL_KEY}-tts-settings`,
|
|
153
154
|
type: 'group',
|
|
154
155
|
admin: {
|
|
155
156
|
condition (data) {
|
|
@@ -208,7 +209,7 @@ export const OpenAIConfig = {
|
|
|
208
209
|
}
|
|
209
210
|
},
|
|
210
211
|
{
|
|
211
|
-
id:
|
|
212
|
+
id: `${MODEL_KEY}-object`,
|
|
212
213
|
name: 'OpenAI GPT',
|
|
213
214
|
fields: [
|
|
214
215
|
'richText'
|
|
@@ -218,11 +219,11 @@ export const OpenAIConfig = {
|
|
|
218
219
|
},
|
|
219
220
|
output: 'text',
|
|
220
221
|
settings: {
|
|
221
|
-
name:
|
|
222
|
+
name: `${MODEL_KEY}-object-settings`,
|
|
222
223
|
type: 'group',
|
|
223
224
|
admin: {
|
|
224
225
|
condition (data) {
|
|
225
|
-
return data['model-id'] ===
|
|
226
|
+
return data['model-id'] === `${MODEL_KEY}-object`;
|
|
226
227
|
}
|
|
227
228
|
},
|
|
228
229
|
fields: [
|
|
@@ -237,33 +238,6 @@ export const OpenAIConfig = {
|
|
|
237
238
|
'gpt-4o-mini',
|
|
238
239
|
'gpt-4o-2024-08-06'
|
|
239
240
|
]
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
name: 'system',
|
|
243
|
-
type: 'textarea',
|
|
244
|
-
defaultValue: `INSTRUCTIONS:
|
|
245
|
-
You are a highly skilled and professional blog writer,
|
|
246
|
-
renowned for crafting engaging and well-organized articles.
|
|
247
|
-
When given a title, you meticulously create blogs that are not only
|
|
248
|
-
informative and accurate but also captivating and beautifully structured.`,
|
|
249
|
-
label: 'System prompt'
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
/**TODO's:
|
|
253
|
-
* - Layouts can be saved in as an array
|
|
254
|
-
* - user can add their own layout to collections and use it later for generate specific rich text
|
|
255
|
-
* - user can select previously added layout
|
|
256
|
-
*/ name: 'layout',
|
|
257
|
-
type: 'textarea',
|
|
258
|
-
defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.
|
|
259
|
-
[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.
|
|
260
|
-
[list] - Create a list with 3-5 items. Each list item should contain:
|
|
261
|
-
a. [heading] - A brief, descriptive heading (up to 5 words)
|
|
262
|
-
b. [paragraph] - A short explanation or elaboration (1-2 sentences)
|
|
263
|
-
[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.
|
|
264
|
-
[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.
|
|
265
|
-
[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: "Quote text." - Author Name`,
|
|
266
|
-
label: 'Layout'
|
|
267
241
|
}
|
|
268
242
|
],
|
|
269
243
|
label: 'OpenAI GPT Settings'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { openai } from '@ai-sdk/openai'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\nimport { defaultSystemPrompt } from '../../prompts.js'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: 'openai-gpt-text',\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: 'openai-gpt-text-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'openai-gpt-text'\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-3.5-turbo'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: 'openai-tts-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as Array<\n SpeechCreateParams['response_format']\n >,\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: 'openai-gpt-object',\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: 'openai-gpt-object-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'openai-gpt-object'\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\n },\n {\n name: 'system',\n type: 'textarea',\n defaultValue: `INSTRUCTIONS:\nYou are a highly skilled and professional blog writer,\nrenowned for crafting engaging and well-organized articles.\nWhen given a title, you meticulously create blogs that are not only\ninformative and accurate but also captivating and beautifully structured.`,\n label: 'System prompt',\n },\n {\n /**TODO's:\n * - Layouts can be saved in as an array\n * - user can add their own layout to collections and use it later for generate specific rich text\n * - user can select previously added layout\n */\n name: 'layout',\n type: 'textarea',\n defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.\n[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.\n[list] - Create a list with 3-5 items. Each list item should contain:\n a. [heading] - A brief, descriptive heading (up to 5 words)\n b. [paragraph] - A short explanation or elaboration (1-2 sentences)\n[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.\n[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.\n[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: \"Quote text.\" - Author Name`,\n label: 'Layout',\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["openai","streamText","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","defaultSystemPrompt","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","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AAS;4BAAC;4BAAS;4BAAQ;4BAAS;4BAAQ;4BAAQ;yBAAU;oBAGhE;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAS;yBAAW;oBAChC;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAO;4BAAQ;4BAAO;4BAAQ;4BAAO;yBAAM;oBAGvD;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPU,KAAK;wBACLC,KAAK;oBACP;iBACD;gBACDX,OAAO;YACT;QACF;QACA;YACEjB,IAAI;YACJC,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACsB,MAAcpB;gBACtB,OAAOV,iBAAiB8B,MAAMpB;YAChC;YACAK,QAAQ;YACRC,UAAU;gBACRV,MAAM;gBACNW,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK;oBAC9B;gBACF;gBACAb,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc,CAAC;;;;yEAI8C,CAAC;wBAC9DC,OAAO;oBACT;oBACA;wBACE;;;;aAIC,GACDhB,MAAM;wBACNW,MAAM;wBACNI,cAAc,CAAC;;;;;;;2HAOgG,CAAC;wBAChHC,OAAO;oBACT;iBACD;gBACDA,OAAO;YACT;QACF;KACD;IACDY,UAAU;AACZ,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { openai } from '@ai-sdk/openai'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\n\nconst MODEL_KEY = 'Oai'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-3.5-turbo'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as Array<\n SpeechCreateParams['response_format']\n >,\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["openai","streamText","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","max","min","provider"],"mappings":"AAGA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,YAAY;AAElB,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBI,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,OACPC,QACAC;gBAEA,MAAMC,mBAAmB,MAAMf,WAAW;oBACxCgB,OAAOjB,OAAOe,QAAQE,KAAK;oBAC3BH;oBACAI,QAAQH,QAAQG,MAAM,IAAIhB;gBAC5B;gBAEA,OAAOc,iBAAiBG,oBAAoB;YAC9C;YACAC,QAAQ;YACRC,UAAU;gBACRV,MAAM,GAAGJ,UAAU,cAAc,CAAC;gBAClCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KA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CAAC;gBACpCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGlB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDY,UAAU;AACZ,EAAC"}
|
package/dist/ai/prompts.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ type ActionPrompt = {
|
|
|
10
10
|
name: ActionMenuItems;
|
|
11
11
|
system: (options: ActionPromptOptions) => string;
|
|
12
12
|
};
|
|
13
|
-
export declare const defaultSystemPrompt = "
|
|
13
|
+
export declare const defaultSystemPrompt = "IMPORTANT INSTRUCTION:\nProduce only the requested output text.\nDo not add any explanations, comments, or engagement.\nDo not use quotation marks in the response.\nBEGIN OUTPUT:";
|
|
14
14
|
export declare const defaultPrompts: ActionPrompt[];
|
|
15
15
|
export declare const seedPrompts: ({ fieldLabel, fieldSchemaPaths, fieldType, path }: {
|
|
16
16
|
fieldLabel: any;
|
package/dist/ai/prompts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/ai/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,mBAAmB,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,mBAAmB,KAAK,MAAM,CAAA;IAClD,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,MAAM,CAAA;CACjD,CAAA;
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/ai/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,mBAAmB,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,mBAAmB,KAAK,MAAM,CAAA;IAClD,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,MAAM,CAAA;CACjD,CAAA;AAGD,eAAO,MAAM,mBAAmB,uLAIlB,CAAA;AAEd,eAAO,MAAM,cAAc,EAAE,YAAY,EAyGxC,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;CA6GvB,CAAA"}
|
package/dist/ai/prompts.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//TODO: This is a temporary solution make use of structured output
|
|
2
|
+
export const defaultSystemPrompt = `IMPORTANT INSTRUCTION:
|
|
3
|
+
Produce only the requested output text.
|
|
4
|
+
Do not add any explanations, comments, or engagement.
|
|
5
|
+
Do not use quotation marks in the response.
|
|
6
|
+
BEGIN OUTPUT:`;
|
|
4
7
|
export const defaultPrompts = [
|
|
5
8
|
{
|
|
6
9
|
name: 'Rephrase',
|