For an api foo
, the templates are:
foo/lib/request-tpl.jsonnet
andfoo/lib/document-tpl.jsonnet
.
There are also test files to check conversion.
cd foo
npm ci # once to setup the test project
npm test # run tests
Using jsonnet command-line tool:
jsonnet --jpath ./lib ./openai/lib/request-tpl.jsonnet -V prompt=hello \
-V secret1=TOKEN -V secret2=orgid
Output:
{
"body": {
"messages": [
{
"content": "hello",
"role": "user"
}
],
"model": "gpt-3.5-turbo"
},
"headers": {
"Authorization": "Bearer TOKEN",
"Content-type": "application/json",
"OpenAI-Organization": "orgid"
},
"method": "POST",
"url": "https://api.openai.com/v1/chat/completions"
}
Input:
secret1
: First secret, usually an API keysecret2
: Optionally second secret. In case of OpenAI API, it's an organization IDprompt
parent
: When using in a chain of templates,parent
contains the output of the previous template. Seeopenai-patch-example
how to patch the transformation.
Output:
An object, ready to use for fetch. The expected fields:
url
method
headers
body
: Type is thejson object
, notstring
The header Content-type: application/json
is often required by APIs, even if not mentioned in documentation.
There is a JSON schema for validation: ./schemas/request.json.
Input:
response
: body payload
Output:
{
doc: [
{
type: 'markdown',
content: [
{
type: 'text',
text: ... whatever ...
}
]
}
]
}
There could be several `type: markdown' objects.
There is a JSON schema for validation: ./schemas/document.json.
The document structure will be more rich in the future. It will be based on the ProseMirror's document model.
npm install https://github.com/olpa/templating-for-api/releases/download/apis-v1.1.5/apis-v1.1.5.tar.gz