Tagging
Compatibility
Must be used with an OpenAI Functions model.
This chain is designed to tag an input text according to properties defined in a schema.
import { createTaggingChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models/openai";
import type { FunctionParameters } from "langchain/output_parsers";
const schema: FunctionParameters = {
type: "object",
properties: {
sentiment: { type: "string" },
tone: { type: "string" },
language: { type: "string" },
},
required: ["tone"],
};
const chatModel = new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 });
const chain = createTaggingChain(schema, chatModel);
console.log(
await chain.run(
`Estoy increiblemente contento de haberte conocido! Creo que seremos muy buenos amigos!`
)
);
/*
{ tone: 'positive', language: 'Spanish' }
*/
API Reference:
- createTaggingChain from
langchain/chains
- ChatOpenAI from
langchain/chat_models/openai
- FunctionParameters from
langchain/output_parsers