diff --git a/package.json b/package.json index 495371c..a783067 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "@kevisual/app", - "version": "0.0.1", + "version": "0.0.2", "description": "", "main": "index.js", "scripts": { "dev": "bun" }, "files": [ - "src" + "src", + "mod.ts" ], "publishConfig": { "access": "public" diff --git a/readme.md b/readme.md index f89bdaf..8bc0995 100644 --- a/readme.md +++ b/readme.md @@ -6,4 +6,17 @@ 当调用外部系统的时候,通过 auth token 去获取自己的对应的外部系统的 token,然后再调用外部系统的接口。 -## \ No newline at end of file +## 举个例子,我要用 qwen 的接口 + +qwen 在我的系统中的存储的配置是 qwen.json + +目的是纯前端快速访问页面, 因为要快速生成页面 + +```ts +const app = new App({token}); +const config = await app.getConfig('qwen.json'); + +const qwen = new Qwen({token: config.token}); +const response = await qwen.chat({messages: [...]}); +console.log(response); +``` \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index 417303c..600859f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import { QueryRouterServer } from '@kevisual/router' import { use } from '@kevisual/context' import { Query } from '@kevisual/query' -import { Kevisual } from '@kevisual/ai' +import { Kevisual, ChatProviderMap } from '@kevisual/ai' import mitt from 'mitt'; const isBrowser = typeof window !== 'undefined' @@ -57,7 +57,13 @@ export class App { try { const config = await this.getConfig('ai.json'); if (config.token) { - this.ai = new Kevisual(config); + if (config.provider) { + const provider = config.provider; + // @ts-ignore + this.ai = ChatProviderMap[provider] ? new ChatProviderMap[provider](config) : new Kevisual(config); + } else { + this.ai = new Kevisual(config); + } } } catch (e) { } this.emitter.emit('ai-inited');