@rinkuto/koishi-plugin-chatgpt
Version:
使用open ai的gpt-3.5-turbo模型
35 lines (34 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PuppeteerUtil = void 0;
class PuppeteerUtil {
static getInstance(ctx) {
if (this.instance === undefined) {
this.instance = new PuppeteerUtil(ctx);
}
return this.instance;
}
constructor(ctx) {
this.width = 350;
this.puppeteer = ctx.puppeteer;
}
async render(html) {
return await this.puppeteer.render(html, async (page, next) => {
await page.setViewport({ width: this.width, height: 10 });
const base64 = await page.screenshot({
encoding: 'base64', fullPage: true,
});
return Promise.resolve(base64);
});
}
async getHtml(reply) {
if (this.puppeteer === undefined)
return undefined;
return 'base64://' + await this.render(`
<div style="width: ${this.width - 5};margin:0 auto;word-wrap:break-word;
word-break:normal; font-size: 20px">
${reply}
</div>`);
}
}
exports.PuppeteerUtil = PuppeteerUtil;