# speedpix-javascript **Repository Path**: mirrors_aliyun/speedpix-javascript ## Basic Information - **Project Name**: speedpix-javascript - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-17 - **Last Updated**: 2025-10-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SpeedPix JavaScript SDK 智作工坊 SpeedPix 官方 JavaScript SDK,支持 Node.js 和浏览器环境。 ## 📚 关于智作工坊 智作工坊(AIGC Service Lab)是阿里云教育推出的 AIGC 生成服务,主要为泛教育、设计业务企业提供高效的 AIGC(人工智能生成内容)PAAS 服务。 ### 🎯 核心功能 - **文生图**:根据文本描述生成高质量图像 - **图生图**:基于输入图像进行风格转换或内容变换 - **文转视频**:将文本描述转换为动态视频内容 - **图转视频**:将静态图像转换为动态视频 ### 🔧 技术支持 - 支持**通义万相**以及开源的 **Stable Diffusion** 模型 - 提供 **WEB UI** 和 **ComfyUI** 两种模式 - 集成阿里云严格的**内容安全检测服务** - 支持自定义界面部署和权限管理 ### 📖 详细文档 - [智作工坊产品文档](https://help.aliyun.com/document_detail/2804197.html) - [产品概述](https://help.aliyun.com/document_detail/2804199.html) - [智作工坊控制台](https://eduplatform-sp.console.aliyun.com/) --- ## 安装 ```bash npm install speedpix ``` ## 快速开始 ### 基础用法 ```javascript const SpeedPix = require("speedpix"); const speedpix = new SpeedPix({ endpoint: "your-endpoint.com", appKey: "your-app-key", appSecret: "your-app-secret" }); // 运行工作流 const output = await speedpix.run("workflow-id", { input: { prompt: "一只可爱的小猫" } }); // 处理输出结果 if (output.url) { await output.url.save("result.png"); console.log("图片已保存"); } ``` ### ESM 模块 ```javascript import SpeedPix from "speedpix"; const speedpix = new SpeedPix({ endpoint: "your-endpoint.com", appKey: "your-app-key", appSecret: "your-app-secret" }); const output = await speedpix.run("workflow-id", { input: { prompt: "生成图片" } }); if (output.url) { await output.url.save("result.png"); } ``` ### TypeScript ```typescript import SpeedPix from "speedpix"; const speedpix = new SpeedPix({ endpoint: "your-endpoint.com", appKey: "your-app-key", appSecret: "your-app-secret" }); const output = await speedpix.run("workflow-id", { input: { prompt: "TypeScript 示例" } }); ``` ## 环境配置 创建 `.env` 文件: ```env SPEEDPIX_ENDPOINT=your-endpoint.com # 可选,默认为 https://openai.edu-aliyun.com SPEEDPIX_APP_KEY=your-app-key # 必需 SPEEDPIX_APP_SECRET=your-app-secret # 必需 ``` ## 主要功能 ### 1. 运行工作流 ```javascript // 同步执行(等待完成) const output = await speedpix.run("workflow-id", { input: { prompt: "美丽的风景画", style: "油画风格" } }); // 异步执行(不等待完成) const prediction = await speedpix.run("workflow-id", { input: { prompt: "复杂场景" }, wait: false }); console.log(`任务ID: ${prediction.id}`); const result = await prediction.wait(); ``` ### 2. 文件上传 ```javascript // 上传本地文件 const file = await speedpix.files.create("./image.jpg"); // 在工作流中使用 const output = await speedpix.run("workflow-id", { input: { image: file.accessUrl, prompt: "处理这张图片" } }); ``` ### 3. 输出处理 输出结果始终为对象映射结构: ```javascript const output = await speedpix.run("workflow-id", { input: {...} }); // 单个文件输出 if (output.url) { await output.url.save("result.png"); console.log("下载链接:", output.url.toString()); } // 多个输出 if (output.image1) { await output.image1.save("image1.png"); } if (output.image2) { await output.image2.save("image2.png"); } ``` ### 4. 错误处理 ```javascript try { const output = await speedpix.run("workflow-id", { input: {...} }); } catch (error) { if (error instanceof SpeedPix.SpeedPixTimeoutError) { console.log("请求超时"); } else if (error instanceof SpeedPix.SpeedPixError) { console.log("API 错误:", error.message); } else { console.log("未知错误:", error.message); } } ``` ## API 参考 ### SpeedPix 类 ```javascript const speedpix = new SpeedPix({ endpoint: "string", // 必填:API 端点 appKey: "string", // 必填:应用密钥 appSecret: "string", // 必填:应用秘钥 userAgent: "string" // 可选:用户代理 }); ``` ### run() 方法 ```javascript await speedpix.run(workflowId, options); ``` **参数:** - `workflowId` (string): 工作流ID - `options` (object): - `input` (object): 输入参数 - `aliasId` (string, 可选): 版本别名 - `resourceConfigId` (string, 可选): 资源配置ID - `wait` (boolean, 可选): 是否等待完成,默认 true - `timeout` (number, 可选): 超时时间(秒) ### files.create() 方法 ```javascript const file = await speedpix.files.create(filePath); ``` **返回:** - `file.accessUrl`: 文件访问URL - `file.id`: 文件ID ## 许可证 MIT