Skip to content

olpa/templating-for-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Templating for API

One tool for several generative AIs: we need a common interface to do so.

Tplfa ("templating for api") defines such common interface and provides API-specific templates.

The templates are written in jsonnet and can be used in most popular languages.

Tplfa is a part of Gewova collaborative prompt engineering project. Tplfa is published under permissive MIT license and can be included in commercial applications.

In action

cd in-action/nodejs-cli/
export OPENAI_API_KEY=...
npx ts-node src/index.ts --debug \
  --api ../../apis/openai/lib \
  --prompt "Tell me a joke about APIs."

The prompt is converted to a fetch-object:

{
   "url": "https://api.openai.com/v1/chat/completions",
   "method": "POST",
   "headers": {
      "Authorization": "...",
      "Content-type": "application/json"
   },
   "body": {
      "messages": [
         {
            "content": "Tell me a joke about APIs.",
            "role": "user"
         }
      ],
      "model": "gpt-3.5-turbo"
   }
}

The response from OpenAI is converted to the document representation:

{
  "doc": [
    {
      "content": [
        {
          "text": "Why did the API go to therapy? \n\nBecause it couldn't handle all the rejection codes!",
          "type": "text"
        }
      ],
      "type": "markdown"
    }
  ]
}

APIs

At the moment, there is only a template for OpenAI chat completion.

How to contribute an API

  • Copy-paste the openai template to a new directory
  • Modify the templates and update tests

Add templating to an application

There are official libraries for Python, Go, C and C++, plus unofficial third-party bindings: https://jsonnet.org/ref/bindings.html.

This repository templating-for-api provides JavaScript and TypeScript bindings to jsonnet through WebAssembly compilation. There is no npm package, you are supposed to copy files into your project: ./jsonnet/dist/, ./jsonnet/typescript/jsonnet.ts

Contents

About

Construct API queries from templates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published