aiwrapper
Version:
A Universal AI Wrapper for JavaScript & TypeScript
40 lines (39 loc) • 1.25 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { httpRequestWithRetry as fetch } from "../../http-request.js";
class OpenAILangVecs {
constructor(options) {
__publicField(this, "name");
__publicField(this, "_config");
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 ? void 0 : onResult({
vector: vecs
});
return vecs;
}
}
export {
OpenAILangVecs
};
//# sourceMappingURL=openai-lang-vecs.js.map