qh-ai-jssdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

潜海AI前端SDK

本项目依赖promise,如果需要在不支持promise的浏览器中使用,请安装polyfill 本项目仅在浏览器端可以运行

使用步骤

  1. npm install qh-ai-jssdk
  2. import QhAi from 'qh-ai-jssdk'
  3. 如果类型报错请在tsconfig.json中添加配置
{
    ...
    "compilerOptions": {
        "types": ["qh-ai-jssdk"]
    }
    ...
}
  1. token使用方式
    如果要token来请求接口,需要使用实例的axios属性(axios由axios.create()创建)
    请求token的接口需要在各自应用实现,支持传入Promise以及Axios请求配置
const qhAi = new QhAi({
    tokenRefresh: () => {
        return new Promise((resolve, reject) => {
            // ...
            resolve('token')
        })
    }
})
qhAi.axios.request({
    url: '/meta/seo-prompt'
})
const qhAi = new QhAi({
    tokenRequestConfig: {
        url: 'http://localhost:18888/getToken',
        method: 'get'
    }
})
qhAi.axios.request({
    url: '/meta/seo-prompt'
})
  1. websocket使用方式
    websocket基于一次性的ticket,传入方式支持三种,直接传入,Axios请求配置,Promise
const wsUrl = await qhAi.createWsUrl({
    socketUrl: '/app/websocket',
    ticket: 'ticket'
});
const wsUrl = await qhAi.createWsUrl({
    socketUrl: '/app/websocket',
    ticketRefresh: async () => {
        const {
            data: { id: ticket },
        } = await getSignTicket();
        return ticket;
    },
});
const wsUrl = await qhAi.createWsUrl({
    socketUrl: '/app/websocket',
    ticketRequestConfig: {
        url: 'http://localhost:18888/getTicket',
        method: 'get'
    }
});

Readme

Keywords

Package Sidebar

Install

npm i qh-ai-jssdk

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

233 kB

Total Files

7

Last publish

Collaborators

  • resword