fix: add core jimeng
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/ai",
|
"name": "@kevisual/ai",
|
||||||
"version": "0.0.15",
|
"version": "0.0.16",
|
||||||
"description": "AI Center Services",
|
"description": "AI Center Services",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"basename": "/root/ai-center-services",
|
"basename": "/root/ai-center-services",
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"ioredis": "^5.8.2",
|
"ioredis": "^5.8.2",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"openai": "6.9.1",
|
"openai": "6.10.0",
|
||||||
"pm2": "^6.0.14",
|
"pm2": "^6.0.14",
|
||||||
"rimraf": "^6.1.2",
|
"rimraf": "^6.1.2",
|
||||||
"rollup": "^4.53.3",
|
"rollup": "^4.53.3",
|
||||||
@@ -86,6 +86,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kevisual/logger": "^0.0.4",
|
"@kevisual/logger": "^0.0.4",
|
||||||
"@kevisual/permission": "^0.0.3"
|
"@kevisual/permission": "^0.0.3",
|
||||||
|
"@kevisual/query": "^0.0.30"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@@ -14,6 +14,9 @@ importers:
|
|||||||
'@kevisual/permission':
|
'@kevisual/permission':
|
||||||
specifier: ^0.0.3
|
specifier: ^0.0.3
|
||||||
version: 0.0.3
|
version: 0.0.3
|
||||||
|
'@kevisual/query':
|
||||||
|
specifier: ^0.0.30
|
||||||
|
version: 0.0.30
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@kevisual/code-center-module':
|
'@kevisual/code-center-module':
|
||||||
specifier: 0.0.24
|
specifier: 0.0.24
|
||||||
@@ -76,8 +79,8 @@ importers:
|
|||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
openai:
|
openai:
|
||||||
specifier: 6.9.1
|
specifier: 6.10.0
|
||||||
version: 6.9.1(ws@8.18.3)(zod@3.25.76)
|
version: 6.10.0(ws@8.18.3)(zod@3.25.76)
|
||||||
pm2:
|
pm2:
|
||||||
specifier: ^6.0.14
|
specifier: ^6.0.14
|
||||||
version: 6.0.14
|
version: 6.0.14
|
||||||
@@ -314,6 +317,9 @@ packages:
|
|||||||
'@kevisual/permission@0.0.3':
|
'@kevisual/permission@0.0.3':
|
||||||
resolution: {integrity: sha512-8JsA/5O5Ax/z+M+MYpFYdlioHE6jNmWMuFSokBWYs9CCAHNiSKMR01YLkoVDoPvncfH/Y8F5K/IEXRCbptuMNA==}
|
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':
|
'@kevisual/rollup-tools@0.0.1':
|
||||||
resolution: {integrity: sha512-TdCN+IU0fyHudiiqYvobXQ8r5MltfM/cKmSS59iopyL8YYwXwcipOS4S24NWA79g7uwJfSUNk5lg3yVhom79fQ==}
|
resolution: {integrity: sha512-TdCN+IU0fyHudiiqYvobXQ8r5MltfM/cKmSS59iopyL8YYwXwcipOS4S24NWA79g7uwJfSUNk5lg3yVhom79fQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -1587,8 +1593,8 @@ packages:
|
|||||||
once@1.4.0:
|
once@1.4.0:
|
||||||
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
||||||
|
|
||||||
openai@6.9.1:
|
openai@6.10.0:
|
||||||
resolution: {integrity: sha512-vQ5Rlt0ZgB3/BNmTa7bIijYFhz3YBceAA3Z4JuoMSBftBF9YqFHIEhZakSs+O/Ad7EaoEimZvHxD5ylRjN11Lg==}
|
resolution: {integrity: sha512-ITxOGo7rO3XRMiKA5l7tQ43iNNu+iXGFAcf2t+aWVzzqRaS0i7m1K2BhxNdaveB+5eENhO0VY1FkiZzhBk4v3A==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
ws: ^8.18.0
|
ws: ^8.18.0
|
||||||
@@ -2475,6 +2481,8 @@ snapshots:
|
|||||||
|
|
||||||
'@kevisual/permission@0.0.3': {}
|
'@kevisual/permission@0.0.3': {}
|
||||||
|
|
||||||
|
'@kevisual/query@0.0.30': {}
|
||||||
|
|
||||||
'@kevisual/rollup-tools@0.0.1(esbuild@0.25.8)':
|
'@kevisual/rollup-tools@0.0.1(esbuild@0.25.8)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@rollup/plugin-alias': 5.1.1(rollup@4.53.3)
|
'@rollup/plugin-alias': 5.1.1(rollup@4.53.3)
|
||||||
@@ -3838,7 +3846,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
wrappy: 1.0.2
|
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:
|
optionalDependencies:
|
||||||
ws: 8.18.3
|
ws: 8.18.3
|
||||||
zod: 3.25.76
|
zod: 3.25.76
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
onlyBuiltDependencies:
|
|
||||||
- esbuild
|
|
||||||
51
src/jimeng/core.ts
Normal file
51
src/jimeng/core.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
7
src/jimeng/index.ts
Normal file
7
src/jimeng/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Core, CoreOpts } from "./core.ts";
|
||||||
|
|
||||||
|
export class Jimen extends Core {
|
||||||
|
constructor(opts: CoreOpts = {}) {
|
||||||
|
super(opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/test/common.ts
Normal file
18
src/test/common.ts
Normal file
@@ -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);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user