UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

62 lines (61 loc) 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const types_1 = require("../../types"); class HttpPlugin { constructor() { this.name = "http"; this.description = "Generic HTTP client using axios for API requests."; this.InitConfigExample = {}; this.RunConfigExample = { url: "", method: "GET", headers: {}, params: {}, data: [], timeout: 0 }; this.type = types_1.PluginType.LangCodeTool; this.response = null; this.config = null; } async init(config) { // Bu plugin için özel init gerekmez } expose() { return { name: this.name, description: this.description, type: this.type, InitConfigExample: this.InitConfigExample, RunConfigExample: this.RunConfigExample, response: this.response, config: this.config }; } async run(args) { var _a; const { url, method = "GET", headers = {}, params, data, timeout = 10000, } = args; const config = { url, method, headers, params, data, timeout, }; this.config = config; try { const response = await (0, axios_1.default)(config); this.response = response; return response === null || response === void 0 ? void 0 : response.data; } catch (error) { const message = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) || (error === null || error === void 0 ? void 0 : error.message) || "Unknown HTTP error"; throw new Error(`HTTP Error: ${message}`); } } } exports.default = HttpPlugin;