Installation:
npm install https://github.com/olpa/templating-for-api/releases/download/tplfa-v1.1.2/tplfa-v1.1.2.tar.gz
For setup, create instances of
jsonnet
fromtplfa-jsonnet
packageTplfaValidator
TemplatingForApi
Run a query-template:
- Put the prompt and the secret to
TplfaReqVars
- If the template is a part of a chain, put the previous output to
parent
- If the template is a part of a chain, put the previous output to
- Load the code of the request template to
requestTemplate
- If the template is from
tpfa-apis
package, useloadLibTemplates
followed byloadTemplate
fromnodejs-loader.ts
- If the template is from
- Call
TemplatingForApi.toTplfaRequest
- You get a validated output of type
TplfaRequest
- You get a validated output of type
Query an API:
- Call
TemplatingForApi.toRequest
to convertRequest
fromtplfa
type tofetch
type - Call
fetch
Run a document-template:
Similar to running a query-template.
Workflow:
- Define a template loader
- Create an instance of
ApiClient
- Create a chain of templates as
TplfaTransformationVars[]
ApiClient.call
Complete example: ../in-action/nodejs-tplfa/.