← All ivy-nodes
IVYXSTUDIO · IVY NODE
J
JSON Prompt Creator
ivy.node.json-prompt-creator · v0.1.0
ivyx✓
Returns a function that turns a context and a question into a JSON prompt, with a preview of what it writes. The function is a handle for prompt-generator.
#json#prompt#creator
Inputs
No fields declared.
Outputs
| Field | Type | Description |
|---|---|---|
| prompt_creatorrequired | Not declared | A function (context, question) -> a JSON prompt, for prompt-generator. |
| previewrequired | string | The prompt it makes for the context and question in the preview. |
Source
python
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
import json
# json.dumps, not string formatting: the inherited cell put the context
# between quotes as-is, so a context containing a quote made invalid JSON.
def json_prompt_creator(context: str, question: str, **kwargs) -> str:
return json.dumps({"context": context, "question": question}, ensure_ascii=False, indent=4)
prompt_creator = json_prompt_creator
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["prompt_creator"] = prompt_creator
out["preview"] = prompt_creator('He said "hi"', "Who spoke?")Tests
Requires: python:3.9
- quotes-survive
A quote in the context stays valid JSON.