//! The one place prompt text is built. Corpus text reaches a model call only as //! a [`Prompt`], and a `Prompt` is made only by minting from [`TrainItems`], by //! encoding one item an [`EncoderOffer`] holds, or by lowering one //! [`LoweringInput`], which holds no corpus text, item key, group or speaker: //! Train-only minting, per-item encoding and text-free lowering //! (leak-owned-by-flow-and-scorer-3, loop-context-builder-2). Instruction text //! is [`MINT_INSTRUCTIONS`], [`ENCODE_INSTRUCTIONS`] and [`LOWER_INSTRUCTIONS`], //! consts in this module; every prompt also lists the inventory at the run's //! revision. A mint prompt is the editor's: it reads [`TrainItems`], an //! [`Inventory`] and an [`EditFeedback`] and nothing else, so no held-out text, //! key or per-item score can reach it. A lowering prompt names the language it //! is said in on a language line; every language is named by its tag, none by a //! default. A lowering prompt also prints the target language's ontology //! entries that `ontology::select` chose for the view; the caller never names //! entries. //! //! An ontology mint prompt is a second Train-only prompt: the [`TrainItems`] of //! one language, the inventory's Stance, Discourse and Scene features (the only //! ones a condition can read) and that language's existing entry lines. It reads //! no packet, no score and no held-out text. //! //! Item text may hold line breaks; the renderer indents every continuation line //! (`indented`), so item text cannot forge a `[key]` line or a paragraph. //! Item blocks are data from the run's pinned corpus, reached only through //! `RunStores`, the one public producer of `TrainItems` and `EncoderOffer` //! (forged-item-text-in-prompt). A forged item in a scratch store is a different //! run with a different corpus digest, visible in its record; nothing inside a //! process its forger controls can stop it. use std::collections::BTreeMap; use std::marker::PhantomData; use serde::Serialize; use crate::corpus::{CorpusItem, CorpusItemId}; use crate::inventory::{Inventory, InventoryEntry, OptionLabel, Slot, ValueKind}; use crate::lower::{EntityForms, LowerError, entity}; use crate::encode::{EntryOntologyDraft, OntologyDraft}; use crate::ontology::{Condition, Layer, Ontology, Test, select}; use crate::packet::{ Context, Discourse, EntityId, Extension, FeatValue, Grade, Predication, Referent, Relation, Stance, }; use crate::run::LADDER_STEP; use crate::split::{Checkpoint, Split, SplitScheme, fnv1a64, hex16}; use crate::store::{CorpusStore, normalized}; use crate::validate::{LoweringInput, SceneRead}; /// The instructions a mint prompt starts with: the editor's whole brief. Fixed /// per run by `PROMPT_SOURCE_DIGEST`. pub const MINT_INSTRUCTIONS: &str = "\ Propose one edit to the inventory below, so that the lines below can be encoded and lowered, each in its own language, more faithfully. Answer with one JSON object and nothing else: no code fence, no commentary. Shape: {\"add\": [{\"family\", \"gloss\", \"value_kind\", \"applies_to\"}], \"retire\": [ids]}; 1 to 8 changes in all, adds and retires together. - family: one of Concept, Frame, Role, Relation, SpeechAct, Feature, ReferentKind, Extension. - gloss: 1 to 120 bytes naming a general meaning, never a quoted line. - value_kind and applies_to only on a Feature; value_kind only on an Extension. value_kind is \"Grade\", \"Flag\" or {\"Options\": [labels]}; applies_to is a list of slots. - ids and revision numbers are the store's: write an id only to retire a live entry, by the id the inventory lists. The line after this brief says whether your last edit was kept and the held-out composite score at the current inventory."; /// The instructions an encode prompt starts with: the encoder's whole brief. /// Fixed per run by `PROMPT_SOURCE_DIGEST`. pub const ENCODE_INSTRUCTIONS: &str = "\ Encode the line below as one packet draft, the meaning of the line and nothing else. Answer with one JSON object and nothing else: no code fence, no commentary. Fields: - confidence: 0 to 1000. - context: {setting, medium, participants, audience}; setting and medium are concept ids or null, participants and audience are lists of node ids. - discourse: {speech_act, addressee, addressee_consent, features}; speech_act is a speech_act id, addressee a node id or null, addressee_consent always null. - referents: a list of {id, kind, concept, entity, features}; kind is a referent_kind id, concept a concept id, entity an entity id from the entities line or null. - predications: a list of {id, concept, frame, roles, features}; roles is a list of {role, filler}, filler a node id. - relations: a list of {relation, from, to, features}. - stance: {features}; the speaker's felt affect and restraint, never the affect the line displays. Node ids are n1, n2, and so on, one per referent and predication. Every other id comes from the inventory listed below and must be live at its revision. Write each id in full, exactly as the inventory lines spell it, family prefix included: concept:7, never 7. An entity comes only from the entities line. A referent's concept is never null, even when it carries an entity: give the nearest concept id. Participants and audience list the node ids of referents, never an entity id: an entity speaker is a referent whose entity field holds it, and participants lists that referent's node id. A predication holds each role at most once, and a feature list each feature at most once: two or more fillers of one role are one referent of kind group that fills the role, and each member is related to it by a member_of relation from the member to the group. A feature is {feature, value}; value is {\"Grade\": 0 to 1000}, {\"Option\": label} or {\"Flag\": true or false}, as the inventory lists the feature's kind."; /// The instructions a lowering prompt starts with: the lowerer's whole brief. /// Fixed per run by `PROMPT_SOURCE_DIGEST`. pub const LOWER_INSTRUCTIONS: &str = "\ Say the packet below in the language on the language line, as one utterance of its speaker: all of its meaning and nothing it does not carry. Every id is the inventory's listed below and every feature value is as listed; a grade is permille, 0 to 1000. The stance is the speaker's felt affect and restraint: it shapes how the utterance is said, not what it says. The ontology lines are choices this language makes for this speaker, stance and scene: realize each where the packet allows; they add no meaning. A referent with an entity is named by one of that entity's forms on the entities line. Answer with one JSON object and nothing else: {\"text\": \"...\"}. No code fence, no commentary."; /// The instructions of a recall probe (`lowering-recall-diagnostic`): a /// completion of a passage from its opening, asked of a model that has no /// packet and no inventory. It measures recitation, not lowering. pub const RECALL_INSTRUCTIONS: &str = "\ Below is the opening of a passage, with what is known of where it comes from. Continue it exactly as its source words it, from memory, until the passage ends. If you do not remember it, give your best guess in the same voice. Answer with one JSON object and nothing else: {\"text\": \"...\"}, the continuation only, not the opening. No code fence, no commentary."; /// The instructions of an ontology mint: drafting entries for one language from /// its Train lines. Fixed per run by `PROMPT_SOURCE_DIGEST`. pub const MINT_ONTOLOGY_INSTRUCTIONS: &str = "\ Below are lines written in one language (the language line), the features an ontology condition may test, and the entries that language's ontology already has. Draft new entries: choices this language's culture makes, for a speaker in a stance and scene, about word, grammar, discourse, sound or script, that the lines show. Answer with one JSON object and nothing else: {\"entries\": [{\"layer\": \"...\", \"when\": [...], \"choice\": \"...\", \"examples\": [...]}]}. No code fence, no commentary. Give only entries the lines show, as many as they support (a language holds at most 64 in all). layer is exactly one of Lexicon, Grammar, Discourse, Phonology, Orthography. when holds at most 4 conditions, each {\"slot\": \"Stance\" | \"Discourse\" | \"Scene\", \"feature\": \"\", \"test\": ...}, where is the id printed before the colon of a listed feature (\"feature:10\", never its name) and its slot is one that feature lists. test is {\"AtLeast\": }, {\"AtMost\": } or {\"AtMostOrUnset\": } on a grade feature, or {\"Is\": {\"Option\": \"