langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
60 lines (59 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const prompts_1 = require("@langchain/core/prompts");
const openai_1 = require("@langchain/openai");
const base_1 = require("../../base");
class AgentOpenAIPlugin {
constructor() {
this.name = "agentOpenAI";
this.description = "LangChain agent powered by OpenAI and tools";
this.type = types_1.PluginType.Agent;
this.RunConfigExample = {
input: ""
};
this.InitConfigExample = {
apiKey: "sk-xxx",
model: "gpt-4o",
temperature: 0.7,
tools: [], // örnek: [new Calculator()]
messages: [
{ role: "system", content: "Bir assistant gibi davran." },
{ role: "user", content: "{input}" },
{ role: "assistant", content: "{agent_scratchpad}" },
],
};
this.executor = null;
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
executor: this.executor
};
}
async init(config) {
var _a;
const llm = new openai_1.ChatOpenAI({
apiKey: config.apiKey,
model: config.model || "gpt-4o",
temperature: (_a = config.temperature) !== null && _a !== void 0 ? _a : 0.7,
});
const prompt = prompts_1.ChatPromptTemplate.fromMessages(config.messages.map((m) => [m.role, m.content]));
this.executor = await (0, base_1.createAgentExecutor)({
llm,
prompt,
tools: config.tools,
});
}
async run(args) {
if (!this.executor)
throw new Error("Agent not initialized.");
const result = await this.executor.invoke({ input: args.input });
return typeof result === "string" ? result : JSON.stringify(result, null, 2);
}
}
exports.default = AgentOpenAIPlugin;