UNPKG

@glodon-aiot/apis

Version:

aiot apis

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