@plosson/langchain-ai-functions
v1.0.8
Published
Very simple example of using typescript decorators to write AI functions
Downloads
4
Readme
Langchain Typescript AI decorators
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.
Project Setup
npm install
Copy .env.example to .env and add your OPENAI_API_KEY
Using the decorators in your project
npm install "@plosson/langchain-ai-functions"
import {AiFn, AiFnOutput} from "@plosson/langchain-ai-functions";
Examples
There is an example in the tests folder that can be executed using
npm run example