@kevisual/ai 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/ai",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "AI Center Services",
5
5
  "main": "index.js",
6
6
  "basename": "/root/ai-center-services",
@@ -73,7 +73,7 @@
73
73
  "ioredis": "^5.8.2",
74
74
  "json5": "^2.2.3",
75
75
  "lodash-es": "^4.17.21",
76
- "openai": "6.9.1",
76
+ "openai": "6.10.0",
77
77
  "pm2": "^6.0.14",
78
78
  "rimraf": "^6.1.2",
79
79
  "rollup": "^4.53.3",
@@ -86,6 +86,7 @@
86
86
  },
87
87
  "dependencies": {
88
88
  "@kevisual/logger": "^0.0.4",
89
- "@kevisual/permission": "^0.0.3"
89
+ "@kevisual/permission": "^0.0.3",
90
+ "@kevisual/query": "^0.0.30"
90
91
  }
91
92
  }
@@ -0,0 +1,51 @@
1
+ import { adapter } from '@kevisual/query/query'
2
+ export type CoreOpts = {
3
+ baseURL?: string;
4
+ token?: string;
5
+ }
6
+ export class Core {
7
+ baseURL: string = 'https://jimeng-api.kevisual.cn/v1';
8
+ token?: string;
9
+ constructor(opts: CoreOpts = {}) {
10
+ console.log("Core initialized");
11
+ if (opts.baseURL) {
12
+ this.baseURL = opts.baseURL;
13
+ }
14
+ if (opts.token) {
15
+ this.token = opts.token;
16
+ }
17
+ }
18
+ makeHeader() {
19
+ return {
20
+ Authorization: this.token ? `Bearer ${this.token}` : undefined,
21
+ 'Content-Type': 'application/json'
22
+ }
23
+ }
24
+ generateImage({ model = 'jimeng-4.0', prompt, resolution = '2k' }: ImageOptions) {
25
+ const url = `${this.baseURL}/images/generations`;
26
+ return adapter({
27
+ url,
28
+ headers: this.makeHeader(),
29
+ body: {
30
+ model,
31
+ prompt,
32
+ resolution
33
+ }
34
+ });
35
+ }
36
+ }
37
+
38
+ export type ImageOptions = {
39
+ model?: string;
40
+ prompt: string;
41
+ /**
42
+ * 宽高比,如 "16:9", "4:3", "1:1" 等
43
+ */
44
+ ratio?: string;
45
+ /**
46
+ *
47
+ * 图片分辨率,如 "1024x768", "512x512" 等
48
+ * 4k 2k
49
+ */
50
+ resolution?: string;
51
+ }
@@ -0,0 +1,7 @@
1
+ import { Core, CoreOpts } from "./core.ts";
2
+
3
+ export class Jimen extends Core {
4
+ constructor(opts: CoreOpts = {}) {
5
+ super(opts);
6
+ }
7
+ }
@@ -0,0 +1,18 @@
1
+ import { Jimen } from "../jimeng/index.ts"
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ const jimeng = new Jimen({
6
+ token: process.env.JIMENG_TOKEN,
7
+ })
8
+
9
+ console.log("Generating image...");
10
+
11
+ await jimeng.generateImage({
12
+ prompt: "创建一幅未来城市的数字艺术作品,充满科技感和创新元素,色彩鲜艳,细节丰富",
13
+ resolution: "2k"
14
+ }).then((res) => {
15
+ console.log("Image generation response:", res);
16
+ }).catch((err) => {
17
+ console.error("Error generating image:", err);
18
+ });