diff --git a/package.json b/package.json index fcff228..f2501f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/ai", - "version": "0.0.15", + "version": "0.0.16", "description": "AI Center Services", "main": "index.js", "basename": "/root/ai-center-services", @@ -73,7 +73,7 @@ "ioredis": "^5.8.2", "json5": "^2.2.3", "lodash-es": "^4.17.21", - "openai": "6.9.1", + "openai": "6.10.0", "pm2": "^6.0.14", "rimraf": "^6.1.2", "rollup": "^4.53.3", @@ -86,6 +86,7 @@ }, "dependencies": { "@kevisual/logger": "^0.0.4", - "@kevisual/permission": "^0.0.3" + "@kevisual/permission": "^0.0.3", + "@kevisual/query": "^0.0.30" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad48ebe..84d7275 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@kevisual/permission': specifier: ^0.0.3 version: 0.0.3 + '@kevisual/query': + specifier: ^0.0.30 + version: 0.0.30 devDependencies: '@kevisual/code-center-module': specifier: 0.0.24 @@ -76,8 +79,8 @@ importers: specifier: ^4.17.21 version: 4.17.21 openai: - specifier: 6.9.1 - version: 6.9.1(ws@8.18.3)(zod@3.25.76) + specifier: 6.10.0 + version: 6.10.0(ws@8.18.3)(zod@3.25.76) pm2: specifier: ^6.0.14 version: 6.0.14 @@ -314,6 +317,9 @@ packages: '@kevisual/permission@0.0.3': resolution: {integrity: sha512-8JsA/5O5Ax/z+M+MYpFYdlioHE6jNmWMuFSokBWYs9CCAHNiSKMR01YLkoVDoPvncfH/Y8F5K/IEXRCbptuMNA==} + '@kevisual/query@0.0.30': + resolution: {integrity: sha512-mDPEaLX9LdTRgi9anmWQ4EJ491umsASu/gs6K85J5nJqtUN/kfnZ3x5IouUr6aNbgAhrNLv/vTqpQTBsQhEYHQ==} + '@kevisual/rollup-tools@0.0.1': resolution: {integrity: sha512-TdCN+IU0fyHudiiqYvobXQ8r5MltfM/cKmSS59iopyL8YYwXwcipOS4S24NWA79g7uwJfSUNk5lg3yVhom79fQ==} hasBin: true @@ -1587,8 +1593,8 @@ packages: once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} - openai@6.9.1: - resolution: {integrity: sha512-vQ5Rlt0ZgB3/BNmTa7bIijYFhz3YBceAA3Z4JuoMSBftBF9YqFHIEhZakSs+O/Ad7EaoEimZvHxD5ylRjN11Lg==} + openai@6.10.0: + resolution: {integrity: sha512-ITxOGo7rO3XRMiKA5l7tQ43iNNu+iXGFAcf2t+aWVzzqRaS0i7m1K2BhxNdaveB+5eENhO0VY1FkiZzhBk4v3A==} hasBin: true peerDependencies: ws: ^8.18.0 @@ -2475,6 +2481,8 @@ snapshots: '@kevisual/permission@0.0.3': {} + '@kevisual/query@0.0.30': {} + '@kevisual/rollup-tools@0.0.1(esbuild@0.25.8)': dependencies: '@rollup/plugin-alias': 5.1.1(rollup@4.53.3) @@ -3838,7 +3846,7 @@ snapshots: dependencies: wrappy: 1.0.2 - openai@6.9.1(ws@8.18.3)(zod@3.25.76): + openai@6.10.0(ws@8.18.3)(zod@3.25.76): optionalDependencies: ws: 8.18.3 zod: 3.25.76 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml deleted file mode 100644 index efc037a..0000000 --- a/pnpm-workspace.yaml +++ /dev/null @@ -1,2 +0,0 @@ -onlyBuiltDependencies: - - esbuild diff --git a/src/jimeng/core.ts b/src/jimeng/core.ts new file mode 100644 index 0000000..2cb47ab --- /dev/null +++ b/src/jimeng/core.ts @@ -0,0 +1,51 @@ +import { adapter } from '@kevisual/query/query' +export type CoreOpts = { + baseURL?: string; + token?: string; +} +export class Core { + baseURL: string = 'https://jimeng-api.kevisual.cn/v1'; + token?: string; + constructor(opts: CoreOpts = {}) { + console.log("Core initialized"); + if (opts.baseURL) { + this.baseURL = opts.baseURL; + } + if (opts.token) { + this.token = opts.token; + } + } + makeHeader() { + return { + Authorization: this.token ? `Bearer ${this.token}` : undefined, + 'Content-Type': 'application/json' + } + } + generateImage({ model = 'jimeng-4.0', prompt, resolution = '2k' }: ImageOptions) { + const url = `${this.baseURL}/images/generations`; + return adapter({ + url, + headers: this.makeHeader(), + body: { + model, + prompt, + resolution + } + }); + } +} + +export type ImageOptions = { + model?: string; + prompt: string; + /** + * 宽高比,如 "16:9", "4:3", "1:1" 等 + */ + ratio?: string; + /** + * + * 图片分辨率,如 "1024x768", "512x512" 等 + * 4k 2k + */ + resolution?: string; +} \ No newline at end of file diff --git a/src/jimeng/index.ts b/src/jimeng/index.ts new file mode 100644 index 0000000..f4d476b --- /dev/null +++ b/src/jimeng/index.ts @@ -0,0 +1,7 @@ +import { Core, CoreOpts } from "./core.ts"; + +export class Jimen extends Core { + constructor(opts: CoreOpts = {}) { + super(opts); + } +} \ No newline at end of file diff --git a/src/test/common.ts b/src/test/common.ts new file mode 100644 index 0000000..09d8db5 --- /dev/null +++ b/src/test/common.ts @@ -0,0 +1,18 @@ +import { Jimen } from "../jimeng/index.ts" +import dotenv from 'dotenv'; +dotenv.config(); + +const jimeng = new Jimen({ + token: process.env.JIMENG_TOKEN, +}) + +console.log("Generating image..."); + +await jimeng.generateImage({ + prompt: "创建一幅未来城市的数字艺术作品,充满科技感和创新元素,色彩鲜艳,细节丰富", + resolution: "2k" +}).then((res) => { + console.log("Image generation response:", res); +}).catch((err) => { + console.error("Error generating image:", err); +}); \ No newline at end of file