DEV Community

Levan Kvirkvelia
Levan Kvirkvelia

Posted on

A better prompt engineering library built for JS. Langchain.js feels like a python team writing JS

As JS (Mostly TS) devs, we feel like AI or LLM tooling in JS kinda sucks rn, that said most production applications inevitably end up being in JS, so a friend and I started hacking on a new JS native library for making it easier to write prompts.

The idea of the library is to give a much more ergonomic syntax for writing complex prompts, the repo itself goes much more in detail

https://github.com/LevanKvirkvelia/salute

import { gpt3, gen, assistant, system, user } from "salute";

const agent = gpt3(
  ({ params })=>[
    system`You are a helpful and terse assistant.`,
    user`
      I want a response to the following question: 
      ${params.query}
      Don't answer the question yet.
      Name 3 world-class experts (past or present) who would be great at answering this?
    `,
    assistant`${gen("expertNames")}`,
    user`
      Great, now please answer the question as if these experts had collaborated in writing a joint anonymous answer.
    `,
    assistant`${gen("answer")}`,
    user`Are you sure you gave a good answer? Write the answer again and fix it if necessary.`,
    assistant`${gen("fixedAnswer")}`,
  ]
);

const result = await agent(
  { query: `How can I be more productive?` },
  { render: true }
);

console.log(result);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)