@sanity/assist 1.2.15-lang.2 → 1.2.15-lang.4

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 CHANGED
@@ -21,9 +21,14 @@
21
21
  - [Included document types](#included-document-types)
22
22
  - [Field and type filters](#field-and-type-filters)
23
23
  - [Caption generation](#caption-generation)
24
+ - [Image generation](#image-generation)
24
25
  - [Full document translation](#full-document-translation)
25
26
  - [What it solves](#what-ai-assist-full-document-translations-solves)
26
27
  - [Configure](#configure-document-translations)
28
+ - [Field level translations](#field-level-translations)
29
+ - [What it solves](#what-ai-assist-field-level-translations-solves)
30
+ - [Configure](#configure-field-translations)
31
+ - [Adding translation actions to fields](#adding-translation-actions-to-fields)
27
32
  - [License](#license)
28
33
  - [Develop \& test](#develop--test)
29
34
  - [Release new version](#release-new-version)
@@ -269,7 +274,110 @@ AI Assist can optionally generate captions for images. This has to be enabled on
269
274
  by setting the `options.captionField` on the image type, where `captionField` is the field name of a
270
275
  custom string-field on the image object:
271
276
 
277
+ ```tsx
278
+ defineField({
279
+ type: 'image',
280
+ name: 'inlineImage',
281
+ title: 'Image',
282
+ fields: [
283
+ defineField({
284
+ type: 'string',
285
+ name: 'caption',
286
+ title: 'Caption',
287
+ }),
288
+ ],
289
+ options: {
290
+ captionField: 'caption',
291
+ },
292
+ })
293
+ ```
294
+ This will add a "Generate caption" action to the configured field.
295
+ "Generate caption" action will automatically run whenever the image changes.
296
+
297
+ `captionField` can be a nested field, if the image has object field, ie `captionField: 'wrapper.caption'`.
298
+ Fields within array items are not supported.
299
+
300
+ ## Image generation
301
+ <img width="600" alt="image" src="https://github.com/sanity-io/assist/assets/835514/c4de6791-f530-4cd1-b0c2-96ef988bc256">
302
+
303
+ AI Assist can generate assets for images configured with a prompt field.
304
+
305
+ An image is generated directly by using the "Generate image from prompt" instruction on the prompt field,
306
+ or indirectly whenever the image prompt field is written to by an AI Assist instruction.
307
+
308
+ ### Configure
309
+ To enable image generation for an image field, the image must:
310
+ - set `options.imagePromptField` to a child-path relative to the image
311
+ - have a `string` or `text` field that corresponds to the `imagePromptField` path
312
+
313
+ This will add a "Generate image from prompt" instruction to the image prompt field. Running it will generate and image.
314
+
315
+ Additionally, whenever an AI Assist instruction writes to the image prompt field, the image will be generated.
316
+
317
+ This could be a document instruction, an instruction for the image field or parent object, or directly on the image prompt field.
318
+
319
+ A common styleguide can achieved by adding an instruction to the image prompt field that rewrites whatever value is there, to include a common style.
320
+ Use AI context documents to apply a reusable styleguide to the prompt rewriting as needed.
321
+
322
+ #### Example
323
+
324
+ Given the following document schema
325
+ ```ts
326
+ defineType({
327
+ type: 'document',
328
+ name: 'article',
329
+ fields: [
330
+ defineField({
331
+ type: 'image',
332
+ name: 'articleImage',
333
+ fields: [
334
+ defineField({
335
+ type: 'text',
336
+ name: 'imagePrompt',
337
+ title: 'Image prompt',
338
+ rows: 2,
339
+ }),
340
+ ],
341
+ options: {
342
+ imagePromptField: 'imagePromptField',
343
+ },
344
+ })
345
+ ]
346
+ })
347
+ ```
348
+
349
+ To directly generate an image based on the value in the prompt field,
350
+ run the "Generate image from prompt" instruction that is automatically added.
351
+
352
+ For better image results or to ensure a consistent style, rewrite the prompt before generating the image:
353
+
354
+ ### Example prompt expansion instruction
355
+ <img width="267" alt="image" src="https://github.com/sanity-io/assist/assets/835514/dabc6910-80d3-4a69-940f-49ac5cae9ade">
356
+
357
+ For better image results, use an instruction that expands the prompt to be more detailed.
358
+
359
+ Example instruction text:
360
+
361
+ ```
362
+ Rewrite image prompts for image generation according to the following rules:
363
+ - Be Specific: Include detailed descriptions of the scene, objects, colors, and any characters. Instead of saying "a cat in a garden", say "a fluffy gray cat sitting beside pink tulips in a sunny garden".
364
+ - Set the Scene: Describe the environment or background. Mention if it's indoors or outdoors, the time of day, weather conditions, and any specific setting details like a beach, forest, cityscape, etc.
365
+ - Detail Characters: If your image includes people or animals, specify their appearance, clothing, poses, and expressions. For example, "a smiling young woman with short black hair, wearing a red dress, standing under a tree".
366
+ - Color and Style: Mention specific colors and artistic styles you prefer. For instance, "bright, vivid colors with a watercolor effect".
367
+ - Mood and Atmosphere: Describe the mood or atmosphere of the image. Words like 'peaceful', 'dynamic', 'mysterious', or 'joyful' can guide the AI in capturing the right tone.
368
+ - Avoid Ambiguity: Be clear and direct. Avoid using vague or abstract concepts that the AI might struggle to interpret.
369
+ - Follow the Guidelines: Ensure your prompt doesn't include any content against usage policies, such as depictions of real people, copyrighted characters, or sensitive subjects.
370
+
371
+ Keep it 100 words or less.
372
+
373
+ The prompt to rewrite is:
374
+ {Reference to image-prompt-field}
375
+ ```
376
+
377
+ The rules can be extracted into an AI Context document and reused in other instructions as needed. This approach can also be used to inform a reusable styleguide for image generation.
272
378
  ## Full document translation
379
+ <img width="250" alt="Translate document action" src="https://github.com/sanity-io/assist/assets/835514/932968ee-1a8c-4389-8822-338188f88b40">
380
+
273
381
  AI assist offers full document translations, which is ideal for pairing with [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization).
274
382
 
275
383
  ### What AI Assist full document translations solves
@@ -349,6 +457,9 @@ assist({
349
457
  ```
350
458
 
351
459
  ## Field level translations
460
+ <img width="250" alt="Translate fields action" src="https://github.com/sanity-io/assist/assets/835514/99819cd4-578e-43b2-8c70-8e39afff5f09">
461
+
462
+ <img width="250" alt="Translate fields dialog" src="https://github.com/sanity-io/assist/assets/835514/fe3d289c-49b6-46dd-ae2f-cd509a01534a">
352
463
 
353
464
  AI assist offers field-level translations, which is ideal for using alongside with[sanity-plugin-internationalized-array](https://github.com/sanity-io/sanity-plugin-internationalized-array?tab=readme-ov-file#sanity-plugin-internationalized-array) and (@sanity/language-filter)[https://github.com/sanity-io/language-filter]
354
465
 
@@ -597,39 +708,48 @@ assist({
597
708
  })
598
709
  ```
599
710
 
600
- ## Caveats
711
+ ## Adding translation actions to fields
601
712
 
602
- Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored,
603
- but some common caveats to the field that you may run into using AI Assist are:
713
+ <img width="250" alt="Translate action on field" src="https://github.com/sanity-io/assist/assets/835514/e6dc0860-90a7-4f7a-b3d2-71893b09862f">
604
714
 
605
- * Limits to instruction length: Long instructions on deep content structures may exhaust model context
606
- * Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
607
- * Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained
715
+ <img width="250" alt="Translate fields action on field" src="https://github.com/sanity-io/assist/assets/835514/acc5fa23-2022-4eae-922d-5c83dda7379c">
608
716
 
717
+ By default, “Translate document” and “Translate fields…” instructions are only added to the document instruction dropdown.
609
718
 
719
+ These instructions can also be added to fields by setting
720
+ `options.aiWritingAssistance.translateAction: true` for a field or type.
610
721
 
611
- ```tsx
722
+ This allows editors to translate only parts of the document, and can be useful to enable on `internatinalizedArrays` or `locale` wrapper object types.
723
+
724
+ For document types configured for full document translations, a "Translate" action will be added. Running it will translate the field to the language set in the language field
725
+
726
+ For document types configured for field translations, a "Translate fields..." action will be added. Running it will open a dialog with language selectors.
727
+
728
+
729
+ #### Example
730
+
731
+ ```ts
612
732
  defineField({
613
- type: 'image',
614
- name: 'inlineImage',
615
- title: 'Image',
616
- fields: [
617
- defineField({
618
- type: 'string',
619
- name: 'caption',
620
- title: 'Caption',
621
- }),
622
- ],
733
+ name: 'subtitle',
734
+ type: 'internationalizedArrayString',
735
+ title: 'Subtitle',
623
736
  options: {
624
- captionField: 'caption',
737
+ aiWritingAssistance: {
738
+ translateAction: true
739
+ }
625
740
  },
626
741
  })
627
742
  ```
628
- This will add a "Generate caption" action to the configured field.
629
- "Generate caption" action will automatically run whenever the image changes.
630
743
 
631
- `captionField` can be a nested field, if the image has object field, ie `captionField: 'wrapper.caption'`.
632
- Fields within array items are not supported.
744
+ ## Caveats
745
+
746
+ Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored,
747
+ but some common caveats to the field that you may run into using AI Assist are:
748
+
749
+ * Limits to instruction length: Long instructions on deep content structures may exhaust model context
750
+ * Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
751
+ * Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained
752
+
633
753
 
634
754
  ## Third party sub-processors
635
755
 
package/dist/index.d.ts CHANGED
@@ -11,6 +11,11 @@ export declare interface AssistOptions {
11
11
  aiWritingAssistance?: {
12
12
  /** Set to true to disable assistance for this field or type */
13
13
  exclude?: boolean
14
+ /**
15
+ * Set to true to add translation field-action to the field.
16
+ * Only has an effect in document types configured for document or field level translations.
17
+ */
18
+ translateAction?: boolean
14
19
  }
15
20
  }
16
21
 
@@ -196,7 +201,62 @@ declare module 'sanity' {
196
201
  interface FileOptions extends AssistOptions {}
197
202
  interface GeopointOptions extends AssistOptions {}
198
203
  interface ImageOptions extends AssistOptions {
204
+ /**
205
+ * When set, an image will be created whenever the `imagePromptField` is written to by
206
+ * an AI Assist instruction.
207
+ *
208
+ * The value output by AI Assist will be use as an image prompt for an generative image AI.
209
+ *
210
+ * This means that instructions directly for the field or instructions that visit the field when running,
211
+ * will result in the image being changed.
212
+ *
213
+ * `imagePromptField` must be a child-path relative to the image field.
214
+ * ### Example
215
+ * ```ts
216
+ * defineType({
217
+ * type: 'image',
218
+ * name: 'articleImage',
219
+ * fields: [
220
+ * defineField({
221
+ * type: 'text',
222
+ * name: 'imagePrompt',
223
+ * title: 'Image prompt',
224
+ * rows: 2,
225
+ * }),
226
+ * ],
227
+ * options: {
228
+ * imagePromptField: 'imagePromptField',
229
+ * },
230
+ * })
231
+ * ```
232
+ */
199
233
  imagePromptField?: string
234
+ /**
235
+ * When set, an image caption will be automatically created for the image.
236
+ *
237
+ * `captionField` must be a child-path relative to the image field.
238
+ *
239
+ * Whenever the image asset for the field is changed in the Studio,
240
+ * an image caption is generated and set into the `captionField`.
241
+ *
242
+ * ### Example
243
+ * ```ts
244
+ * defineType({
245
+ * type: 'image',
246
+ * name: 'articleImage',
247
+ * fields: [
248
+ * defineField({
249
+ * type: 'string',
250
+ * name: 'altText',
251
+ * title: 'Alt text',
252
+ * }),
253
+ * ],
254
+ * options: {
255
+ * captionField: 'altText',
256
+ * },
257
+ * })
258
+ * ```
259
+ */
200
260
  captionField?: string
201
261
  }
202
262
  interface NumberOptions extends AssistOptions {}