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

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,103 @@ 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
+
302
+ <img width="600" alt="image" src="https://github.com/sanity-io/assist/assets/835514/c144985c-d828-4e55-8a6d-5d5da033791f">
303
+
304
+ AI Assist can generate assets for images configured with a prompt field.
305
+
306
+ Whenever the image prompt field is written to by an AI Assist instruction, the field value is used as a prompt to generate a new image.
307
+
308
+ To enable image generation for an image field, the image must:
309
+ - set `options.imagePromptField` to a child-path relative to the image
310
+ - have a `string` or `text` field that corresponds to the `imagePromptField` path
311
+
312
+ Next, create an AI Assist instruction that will visit the image prompt field.
313
+
314
+ This could be a document instruction, an instruction for the image field or parent object, or directly on the image prompt field.
315
+
316
+ Use AI context documents to apply a reusable styleguide to images as needed.
317
+
318
+ #### Example
319
+ Given the following document schema
320
+ ```ts
321
+ defineType({
322
+ type: 'document',
323
+ name: 'article',
324
+ fields: [
325
+ defineField({
326
+ type: 'image',
327
+ name: 'articleImage',
328
+ fields: [
329
+ defineField({
330
+ type: 'text',
331
+ name: 'imagePrompt',
332
+ title: 'Image prompt',
333
+ rows: 2,
334
+ }),
335
+ ],
336
+ options: {
337
+ imagePromptField: 'imagePromptField',
338
+ },
339
+ })
340
+ ]
341
+ })
342
+ ```
343
+
344
+ To directly generate an image, run the following instruction on the image prompt field:
345
+ "Repeat the value in {Reference to image-prompt-field}".
346
+
347
+ ### Example prompt expansion instruction
348
+
349
+ For better image results, use an instruction that expands the prompt to be more detailed.
350
+
351
+ Example instruction text:
352
+
353
+ "
354
+ Rewrite image prompts for image generation according to the following rules:
355
+ - 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".
356
+ - 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.
357
+ - 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".
358
+ - Color and Style: Mention specific colors and artistic styles you prefer. For instance, "bright, vivid colors with a watercolor effect".
359
+ - 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.
360
+ - Avoid Ambiguity: Be clear and direct. Avoid using vague or abstract concepts that the AI might struggle to interpret.
361
+ - 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.
362
+
363
+ Keep it 100 words or less.
364
+
365
+ The prompt to rewrite is:
366
+ {Reference to image-prompt-field}
367
+ "
368
+
369
+ 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.
370
+
272
371
  ## Full document translation
372
+ <img width="250" alt="Translate document action" src="https://github.com/sanity-io/assist/assets/835514/932968ee-1a8c-4389-8822-338188f88b40">
373
+
273
374
  AI assist offers full document translations, which is ideal for pairing with [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization).
274
375
 
275
376
  ### What AI Assist full document translations solves
@@ -349,6 +450,9 @@ assist({
349
450
  ```
350
451
 
351
452
  ## Field level translations
453
+ <img width="250" alt="Translate fields action" src="https://github.com/sanity-io/assist/assets/835514/99819cd4-578e-43b2-8c70-8e39afff5f09">
454
+
455
+ <img width="250" alt="Translate fields dialog" src="https://github.com/sanity-io/assist/assets/835514/fe3d289c-49b6-46dd-ae2f-cd509a01534a">
352
456
 
353
457
  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
458
 
@@ -597,39 +701,48 @@ assist({
597
701
  })
598
702
  ```
599
703
 
600
- ## Caveats
704
+ ## Adding translation actions to fields
601
705
 
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:
706
+ <img width="250" alt="Translate action on field" src="https://github.com/sanity-io/assist/assets/835514/e6dc0860-90a7-4f7a-b3d2-71893b09862f">
604
707
 
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
708
+ <img width="250" alt="Translate fields action on field" src="https://github.com/sanity-io/assist/assets/835514/acc5fa23-2022-4eae-922d-5c83dda7379c">
608
709
 
710
+ By default, “Translate document” and “Translate fields…” instructions are only added to the document instruction dropdown.
609
711
 
712
+ These instructions can also be added to fields by setting
713
+ `options.aiWritingAssistance.translateAction: true` for a field or type.
610
714
 
611
- ```tsx
715
+ This allows editors to translate only parts of the document, and can be useful to enable on `internatinalizedArrays` or `locale` wrapper object types.
716
+
717
+ 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
718
+
719
+ For document types configured for field translations, a "Translate fields..." action will be added. Running it will open a dialog with language selectors.
720
+
721
+
722
+ #### Example
723
+
724
+ ```ts
612
725
  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
- ],
726
+ name: 'subtitle',
727
+ type: 'internationalizedArrayString',
728
+ title: 'Subtitle',
623
729
  options: {
624
- captionField: 'caption',
730
+ aiWritingAssistance: {
731
+ translateAction: true
732
+ }
625
733
  },
626
734
  })
627
735
  ```
628
- This will add a "Generate caption" action to the configured field.
629
- "Generate caption" action will automatically run whenever the image changes.
630
736
 
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.
737
+ ## Caveats
738
+
739
+ Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored,
740
+ but some common caveats to the field that you may run into using AI Assist are:
741
+
742
+ * Limits to instruction length: Long instructions on deep content structures may exhaust model context
743
+ * Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
744
+ * Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained
745
+
633
746
 
634
747
  ## Third party sub-processors
635
748
 
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 {}