UNPKG

@axflow/models

Version:

Zero-dependency, modular SDK for building robust natural language applications

60 lines (56 loc) 1.93 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/openai/embedding.ts var embedding_exports = {}; __export(embedding_exports, { OpenAIEmbedding: () => OpenAIEmbedding }); module.exports = __toCommonJS(embedding_exports); var import_shared = require("@axflow/models/shared"); // src/openai/shared.ts function headers(apiKey, customHeaders) { const headers2 = { accept: "application/json", "content-type": "application/json", ...customHeaders }; if (typeof apiKey === "string") { headers2.authorization = `Bearer ${apiKey}`; } return headers2; } // src/openai/embedding.ts var OPENAI_COMPLETIONS_API_URL = "https://api.openai.com/v1/embeddings"; async function run(request, options) { const url = options.apiUrl || OPENAI_COMPLETIONS_API_URL; const response = await (0, import_shared.POST)(url, { headers: headers(options.apiKey, options.headers), body: JSON.stringify(request), fetch: options.fetch, signal: options.signal }); return response.json(); } var OpenAIEmbedding = class { static run = run; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { OpenAIEmbedding });