Function backfillV2

  • Takes a V2 card, and backfills V1 fields into it.

    Useful right before exporting a card, for backwards compatibility.

    Note: long-term, we would like to abandon V1 fields completely.

    To backfill an obsolescence notice instead, see: backfillV2WithObsolescenceNotice

    Example

    import * as Cards from 'character-card-utils'

    const v2Card = {
    spec: 'chara_card_v2',
    spec_version: '2.0',
    data: {
    name: 'Mary',
    description: '{{char}} is a woman.',
    personality: 'generous',
    scenario: '{{char}} loves {{user}}',
    first_mes: 'Hello!',
    mes_example: '',
    creator_notes: 'My first card.',
    system_prompt: '',
    post_history_instructions: 'Your message must start with the word "Sweetie".',
    alternate_greetings: ['Heeeey!'],
    character_book: undefined,
    tags: ['female', 'oc'],
    creator: 'darkpriest',
    character_version: '',
    extensions: {},
    },
    }

    const v2CardWithBackfilledV1Fields: Cards.BackfilledV2 = {
    name: 'Mary',
    description: '{{char}} is a woman.',
    personality: 'generous',
    scenario: '{{char}} loves {{user}}',
    first_mes: 'Hello!',
    mes_example: '',
    spec: 'chara_card_v2',
    spec_version: '2.0',
    data: {
    name: 'Mary',
    description: '{{char}} is a woman.',
    personality: 'generous',
    scenario: '{{char}} loves {{user}}',
    first_mes: 'Hello!',
    mes_example: '',
    creator_notes: 'My first card.',
    system_prompt: '',
    post_history_instructions: 'Your message must start with the word "Sweetie".',
    alternate_greetings: ['Heeeey!'],
    character_book: undefined,
    tags: ['female', 'oc'],
    creator: 'darkpriest',
    character_version: '',
    extensions: {},
    },
    }

    expect(Cards.backfillV2(v2Card)).toEqual(v2CardWithBackfilledV1Fields) * ```

    Parameters

    • v2Card: {
          spec: "chara_card_v2";
          spec_version: string;
          data: {
              name: string;
              description: string;
              personality: string;
              scenario: string;
              first_mes: string;
              mes_example: string;
              creator_notes: string;
              system_prompt: string;
              post_history_instructions: string;
              alternate_greetings: string[];
              character_book?: { entries: { keys: string[]; content: string; extensions: Record<string, any>; enabled: boolean; insertion_order: number; case_sensitive?: boolean | undefined; name?: string | undefined; ... 6 more ...; position?: "before_char" | ... 1 more ... | undefined; }[]; ... 5 more ...; recursive_scanning?: boolean | undefin...;
              tags: string[];
              creator: string;
              character_version: string;
              extensions: Record<string, any>;
          };
      }
      • spec: "chara_card_v2"

        Identifier for the Character Card spec used. Can only be 'chara_card_v2'.

      • spec_version: string

        Non-breaking minor spec version. Expected to be '2.0' at this time.

      • data: {
            name: string;
            description: string;
            personality: string;
            scenario: string;
            first_mes: string;
            mes_example: string;
            creator_notes: string;
            system_prompt: string;
            post_history_instructions: string;
            alternate_greetings: string[];
            character_book?: { entries: { keys: string[]; content: string; extensions: Record<string, any>; enabled: boolean; insertion_order: number; case_sensitive?: boolean | undefined; name?: string | undefined; ... 6 more ...; position?: "before_char" | ... 1 more ... | undefined; }[]; ... 5 more ...; recursive_scanning?: boolean | undefin...;
            tags: string[];
            creator: string;
            character_version: string;
            extensions: Record<string, any>;
        }
        • name: string
        • description: string
        • personality: string
        • scenario: string
        • first_mes: string
        • mes_example: string
        • creator_notes: string
        • system_prompt: string
        • post_history_instructions: string
        • alternate_greetings: string[]
        • Optional character_book?: { entries: { keys: string[]; content: string; extensions: Record<string, any>; enabled: boolean; insertion_order: number; case_sensitive?: boolean | undefined; name?: string | undefined; ... 6 more ...; position?: "before_char" | ... 1 more ... | undefined; }[]; ... 5 more ...; recursive_scanning?: boolean | undefin...
        • tags: string[]
        • creator: string
        • character_version: string
        • extensions: Record<string, any>

    Returns BackfilledV2

Generated using TypeDoc