pipelex
Version:
Node.js client for the Pipelex API - Pipelex is an open-source dev tool based on a simple declarative language that lets you define replicable, structured, composable LLM pipelines.
65 lines (64 loc) • 1.97 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PipelexClient = void 0;
const axios_1 = __importDefault(require("axios"));
class PipelexClient {
constructor(options) {
if (!options.apiKey) {
throw new Error('API key is required');
}
this.baseUrl = options.baseUrl || 'https://api.pipelex.com';
this.client = axios_1.default.create({
baseURL: this.baseUrl,
timeout: options.timeout || 30000,
headers: {
'Authorization': `Bearer ${options.apiKey}`,
'Content-Type': 'application/json',
'Accept': 'application/json',
},
});
}
/**
* Make a request to the Pipelex API
*/
async request(config) {
var _a;
try {
const response = await this.client.request(config);
return response.data;
}
catch (error) {
if (error.response) {
throw new Error(`API Error: ${error.response.status} - ${((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.message) || error.message}`);
}
throw new Error(`Network Error: ${error.message}`);
}
}
/**
* Example method - replace with actual API methods
*/
async exampleMethod(params = {}) {
return this.request({
method: 'GET',
url: '/example',
params,
});
}
/**
* Process data through the pipeline
*/
async process(data, options = {}) {
return this.request({
method: 'POST',
url: '/process',
data: {
input: data,
options,
},
});
}
}
exports.PipelexClient = PipelexClient;
;