A demonstration using this module with ChatGPT API and PandoraAI together.
node-bic-sydney
A Node.js module that provides some 'Copilot Image Creator' functions.
Prerequisites
- Node.js >= 16.0.0
- Sydney's optionsSets must contain 'gencontentv3' if you want Copilot to provide prompts for you.
Usage
Module
npm i @timefox/bic-sydney
Usage
Example 1. Create a client side render iframe
Create images by Copilot Image Creator, and get an iframe pointing to the page contains the images created.
This method is most likely what the original Copilot browser client does.
The format of {CopilotImageCreator} options is almost same as the CopilotAiClient options of '@waylaidwanderer/chatgpt-api'.
import { CopilotImageCreator } from '@timefox/bic-sydney';
import crypto from 'crypto';
const options = {
host: '',
userToken: '',
cookies: '',
proxy: '',
debug: false,
userAgent: '',
};
const prompt = 'a fox plays xbox';
const messageId = crypto.randomUUID();
const imageIframe = new CopilotImageCreator(options).genImageIframeCsr(prompt, messageId);
imageIframe.then((result) => {
console.debug(result);
}).catch((error) => {
console.debug(error);
});
Note: If this iframe is returned to client browser, the user must be logged in to Copilot.com in order to generate the image successfully. The user's cookie is required for the polling requests of the generation process.
Example 2. Create a server side render iframe
Create images by Copilot Image Creator, and get an iframe which uses the 'srcdoc' attribute to hold the rendered result page.
This method does not require the user to have logged in to Copilot.com on the client side. The entire request process is completed by the server proxy.
It's very useful for the clients can not visit the new Copilot's service directly.
import { CopilotImageCreator } from '@timefox/bic-sydney';
import crypto from 'crypto';
const options = {
host: '',
userToken: '',
cookies: '',
proxy: '',
debug: false,
userAgent: '',
};
const prompt = 'a fox plays xbox';
const messageId = crypto.randomUUID();
imageIframe = new CopilotImageCreator(options).genImageIframeSsr(
prompt,
messageId,
(progress) => {
if (progress?.contentIframe) {
console.debug('contentIframe:');
console.debug(progress.contentIframe);
}
if (progress?.pollingStartTime) {
console.debug(`pollingStartTime: ${progress.pollingStartTime}`);
}
},
);
imageIframe.then((result) => {
console.debug(result);
}).catch((error) => {
console.debug(error);
});
For more usage, please refer to the module's documentation.
Documents
npm run doc
It will generate the module's docs for you under ./docs.
License
This project is licensed under the MIT License.