UNPKG

@gaiot/apis

Version:

aiot apis

98 lines (97 loc) 2.45 kB
var o = (h, t, e) => new Promise((i, r) => { var n = (s) => { try { c(e.next(s)); } catch (a) { r(a); } }, m = (s) => { try { c(e.throw(s)); } catch (a) { r(a); } }, c = (s) => s.done ? i(s.value) : Promise.resolve(s.value).then(n, m); c((e = e.apply(h, t)).next()); }); import p from "axios"; import { ImodelStoreEnum as u } from "../cvforce-modelservice/model.mjs"; import { BaseApi as d } from "../base/index.mjs"; class f extends d { constructor(t, e) { super(t != null ? t : p.create(), e); } //之前用的接口,处理单个逻辑(兼容不同传参和响应格式) ocr(t, e) { return o(this, null, function* () { if (e.modelStore === u.pvc) { const i = this.convertToBatchParams(e), r = yield this.ocrPvcBatch(t, i); return this.convertToMinioResult(r); } else return this.ocrMinio(t, e); }); } convertToBatchParams(t) { return { pages: [{ image: t.image }] }; } convertToMinioResult(t) { var e; return (e = t.pages) == null ? void 0 : e.flatMap((i) => { var r; return ((r = i.textItems) == null ? void 0 : r.map((n) => ({ box: n.bbox }))) || []; }); } //旧接口minio,处理单个逻辑 ocrMinio(t, e) { return o(this, null, function* () { return e.image && e.image.split("base64,").length > 1 && (e.image = e.image.split("base64,")[1]), this.post(`/v2/infer?serviceId=${t}`, e); }); } //新接口pvc,处理批量逻辑 ocrPvcBatch(t, e) { return o(this, null, function* () { return this.post(`/v2/infer?serviceId=${t}`, e); }); } // 接口延迟 getSleep(t) { return o(this, null, function* () { return new Promise((e) => { setTimeout(() => { e(!0); }, t * 1e3); }); }); } postChatCompletions(t) { return o(this, null, function* () { return this.postNonStandard("/v1/chat/completions", t); }); } detection(t, e) { return o(this, null, function* () { return this.post(`/v2/infer?serviceId=${t}`, e); }); } getBaseModel(t) { return o(this, null, function* () { return this.get("/v1/baseModel", { serviceId: t }); }); } postEmbeddings(t) { return o(this, null, function* () { return this.postNonStandard("/v1/embeddings", t); }); } } export { f as AIShopApi };