UNPKG

@xiaoluo_aigc0708/aigc-sdk

Version:

AI智能建筑 - 完整的AIGC图片生成SDK

172 lines (139 loc) 4.05 kB
# 🚀 AIGC SDK 快速启动指南 ## ⚡ 立即使用 (无需构建) 您可以直接从源码使用SDK,无需等待构建过程: ### 1. 直接导入使用 ```typescript // 直接从源码目录导入 import { AIGCCore } from './aigc-sdk/packages/core/src/index'; import type { AIGCConfig } from './aigc-sdk/packages/types/src/index'; // 配置 const config: AIGCConfig = { comfyui: { apiUrl: 'http://100.72.216.20:7865/api/comfy/run_workflow', imageServiceUrl: 'http://100.72.216.20:8288', timeout: 30000 }, oss: { region: 'oss-cn-beijing', accessKeyId: process.env.OSS_ACCESS_KEY_ID!, accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET!, bucket: 'qinghua-ib-ai', endpoint: 'oss-cn-beijing.aliyuncs.com' } }; // 初始化SDK const aigc = new AIGCCore(config); // 使用 const result = await aigc.generateTextToImage({ prompt: 'a beautiful landscape', width: 1024, height: 1024, n_iter: 2 }); ``` ### 2. 创建简化服务 ```typescript // services/aigc-simple.service.ts import { AIGCCore } from '../aigc-sdk/packages/core/src/index'; import type { AIGCConfig, TextToImageParams, ImageToImageParams } from '../aigc-sdk/packages/types/src/index'; export class SimpleAIGCService { private aigc: AIGCCore; constructor(config: AIGCConfig) { this.aigc = new AIGCCore(config); } async textToImage(prompt: string, options?: Partial<TextToImageParams>) { return this.aigc.generateTextToImage({ prompt, width: 1024, height: 1024, n_iter: 2, ...options }); } async imageToImage(prompt: string, baseImage: string, options?: Partial<ImageToImageParams>) { return this.aigc.generateImageToImage({ prompt, init_images: [baseImage], batch_size: 2, ...options }); } async uploadStyle(file: File) { return this.aigc.uploadStyleImage(file); } async uploadBase(file: File) { return this.aigc.uploadBaseImage(file); } getImageUrl(filename: string) { return this.aigc.getImageUrl(filename); } } ``` ### 3. 在您的项目中使用 ```typescript // 在您的组件中 import { SimpleAIGCService } from '../services/aigc-simple.service'; const aigcService = new SimpleAIGCService({ comfyui: { apiUrl: 'http://100.72.216.20:7865/api/comfy/run_workflow', imageServiceUrl: 'http://100.72.216.20:8288' }, oss: { region: 'oss-cn-beijing', accessKeyId: process.env.OSS_ACCESS_KEY_ID!, accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET!, bucket: 'qinghua-ib-ai', endpoint: 'oss-cn-beijing.aliyuncs.com' } }); // 使用 const handleGenerate = async () => { try { const result = await aigcService.textToImage('一幅美丽的风景画'); console.log('生成成功:', result); } catch (error) { console.error('生成失败:', error); } }; ``` ## 🔧 TypeScript 配置 在您的 `tsconfig.json` 中添加路径映射: ```json { "compilerOptions": { "baseUrl": ".", "paths": { "@aigc-sdk/*": ["./aigc-sdk/packages/*/src"] } } } ``` 然后您可以这样导入: ```typescript import { AIGCCore } from '@aigc-sdk/core'; import type { AIGCConfig } from '@aigc-sdk/types'; ``` ## 📦 后续构建 当您准备好发布时,可以运行构建: ```bash # 方法1: 使用我们的自定义构建脚本 cd aigc-sdk npm run build # 方法2: 手动构建每个包 cd packages/types && npx tsc cd ../comfyui-client && npx tsc cd ../oss-storage && npx tsc cd ../core && npx tsc ``` ## 🎯 核心功能 SDK已经包含了您项目中的所有核心功能: - ✅ 智能工作流选择 (文生图/图生图,有无参考) - ✅ OSS文件上传 (风格图片/基底图片) - ✅ 错误处理和重试机制 - ✅ TypeScript类型安全 - ✅ 网络超时和降级处理 您现在就可以开始在项目中使用这个SDK了!🚀