This is a quick experiment to write AI functions using decorators in Typescript.
The main idea is to be able write this directly in your code base
@AiFn({
template: 'I really want to travel to {city} in {country}. What should I do there? Respond in one short sentence',
inputVariables: ['city', 'country']
})
async whatToVisit(city:string, country:string):AiFnOutput<string> {
}The implementation will be included through Typescript's decorator feature.
You can then call the code simply doing :
const result = await t.whatToVisit('Rome', 'Italy')
console.log(result);It should output
Visit the Colosseum, Vatican City, and eat authentic Italian cuisine.
npm installCopy .env.example to .env and add your OPENAI_API_KEY
npm install "@plosson/langchain-ai-functions"import {AiFn, AiFnOutput} from "@plosson/langchain-ai-functions";There is an example in the tests folder that can be executed using
npm run example