UNPKG

aiwrapper

Version:

A Universal AI Wrapper for JavaScript & TypeScript

31 lines 1 kB
import { httpRequestWithRetry as fetch } from "../../http-request.js"; export class OpenAILangVecs { constructor(options) { this._config = { apiKey: options.apiKey, model: "text-embedding-ada-002", }; this.name = this._config.model; } async ask(text, onResult) { const obj = await fetch("https://api.openai.com/v1/embeddings", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${this._config.apiKey}`, }, body: JSON.stringify({ "input": text, "model": this.name, }), }).then((response) => { return response.json(); }); const vecs = obj.data[0].embedding; onResult === null || onResult === void 0 ? void 0 : onResult({ vector: vecs, }); return vecs; } } //# sourceMappingURL=openai-lang-vecs.js.map