← All ivy-nodes
IVYXSTUDIO · IVY NODE
D

Default Prompt Creator

ivy.node.default-prompt-creator · v0.1.0

ivyx✓

Returns a function that turns a context and a question into a plain-text prompt, with a preview of what it writes. The function is a handle for prompt-generator.

#prompt#creator

Inputs

No fields declared.

Outputs

FieldTypeDescription
prompt_creatorrequiredNot declaredA function (context, question) -> prompt text, for prompt-generator.
previewrequiredstringThe prompt it makes for context C and question Q.

Source

python

# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]

# Compute
class DefaultPromptCreator:
    """Builds a default prompt-formatting callable."""

    def build(self):
        def default_prompt_creator(context: str, question: str, **kwargs) -> str:
            return (
                f"Context: {context}\n\n"
                f"Question: {question}\n\n"
                "Answer the question based on the context above. If the context is not relevant, use your own knowledge."
            )
        return default_prompt_creator

creator_node = DefaultPromptCreator()
prompt_creator = creator_node.build()

# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["prompt_creator"] = prompt_creator
out["preview"] = prompt_creator("C", "Q")

Tests

Requires: python:3.9

  • preview

    The prompt names the context, then the question, then the instruction.