← All ivy-nodes
IVYXSTUDIO · IVY NODE
X
XML Prompt Creator
ivy.node.xml-prompt-creator · v0.1.0
ivyx✓
Returns a function that wraps a context and a question in XML tags as a prompt, with a preview of what it writes. The function is a handle for prompt-generator.
#xml#prompt#creator
Inputs
No fields declared.
Outputs
| Field | Type | Description |
|---|---|---|
| creatorrequired | Not declared | A function (context, question) -> an XML-tagged prompt, for prompt-generator. |
| previewrequired | string | The prompt it makes for context C and question Q. |
Source
python
# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
# Compute
class XMLPromptCreator:
"""Builds an XML-style prompt-formatting callable."""
def build(self):
def xml_prompt_creator(context: str, question: str, **kwargs) -> str:
return f"""
Use the following pieces of information enclosed in <context> tags to provide an answer to the question enclosed in <question> tags.
<context>
{context}
</context>
<question>
{question}
</question>
"""
return xml_prompt_creator
creator_node = XMLPromptCreator()
creator = creator_node.build()
# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["creator"] = creator
out["preview"] = creator("C", "Q")Tests
Requires: python:3.9
- preview
The context and the question each sit in their own tag.