langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
56 lines (55 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const openai_1 = require("@langchain/openai");
const messages_1 = require("@langchain/core/messages");
const types_1 = require("../../types");
class OpenAIPlugin {
constructor() {
this.name = "openai";
this.description = "OpenAI GPT modellerini kullanır.";
this.type = types_1.PluginType.LLM;
this.llm = null;
this.RunConfigExample = {
prompt: ""
};
this.InitConfigExample = {
apiKey: "sk-...",
modelName: "gpt-4o",
temperature: 0
};
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
llm: this.llm
};
}
async init(config) {
const { apiKey, modelName = "gpt-4o", temperature = 0 } = config;
this.llm = new openai_1.ChatOpenAI({
apiKey,
model: modelName,
temperature,
});
// API anahtarının geçerliliğini kontrol etmek için basit bir test
try {
await this.llm.invoke([new messages_1.HumanMessage("Merhaba")]);
}
catch (error) {
throw new Error("OpenAI API anahtarı geçersiz veya erişim sağlanamıyor.");
}
}
async run(args) {
if (!this.llm) {
throw new Error("Plugin başlatılmadı. Lütfen önce init() metodunu çağırın.");
}
const { prompt } = args;
const response = await this.llm.invoke([new messages_1.HumanMessage(prompt)]);
return response.content;
}
}
exports.default = OpenAIPlugin;