langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
40 lines (39 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const openai_1 = require("@langchain/openai");
class OpenAIEmbeddingPlugin {
constructor() {
this.name = "openAIEmbedding";
this.description = "Get embeddings from OpenAI for a given text.";
this.type = types_1.PluginType.Embedding;
this.RunConfigExample = {
text: ""
};
this.InitConfigExample = {
apiKey: "sk-...",
model: "text-embedding-3-small",
};
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
embeddingModel: this.embeddingModel
};
}
async init(config) {
this.embeddingModel = new openai_1.OpenAIEmbeddings({
apiKey: config.apiKey,
model: config.model || "text-embedding-3-small",
});
}
async run(args) {
const result = await this.embeddingModel.embedQuery(args.text);
return result;
}
}
exports.default = OpenAIEmbeddingPlugin;