Documentation
  • GET STARTED
    • 介紹
    • 快速入门
    • 模型
      • 模型更新
    • Afs-turbo 和 Afs-1
    • Afs-turbo
    • 达尔·E 系统概述
    • TTS系统
    • 耳语
    • 嵌入
    • 适度
    • AFS基础
    • 我们如何使用您的数据
    • 终结点与兼容性
  • 教程
  • 更改日志
  • 能力
    • 文本生成
    • 聊天完成
    • JSON 模式
    • 可重复的输出
    • 管理令牌
    • 参数详细信息
    • 完成API(旧版)
    • 常见问题
  • 函数调用
  • 嵌入
    • 概述
    • 模型
    • 使用案例
    • 常见问题
  • 微调
    • 何时使用微调
    • 常见用例
    • 准备数据集
    • 创建微调模型
    • 使用微调模型
    • 微调示例
  • 图像生成
    • 介绍
    • 用法
    • 特定语言提示
  • 视觉
  • 文字转语音
  • 语音转文本
    • 概述
    • 快速入门
    • 支持的语言
    • 时间戳
    • 更长的输入
    • 促使
    • 提高可靠性
  • 适度
    • 概述
    • 快速入门
  • 助理
  • 概述
  • Google助理的工作原理
    • Objects
    • Creating Assistants
    • Managing Threads and Messages
    • Runs and Run Steps
    • 局限性
  • 工具
    • Code Interpreter
    • Knowledge Retrieval
    • Function calling
    • Supported files
  • 指南
  • 提示工程
    • Six strategies for getting better results
    • Write clear instructions
    • Provide reference text
    • Split complex tasks into simpler subtasks
    • Give models time to "think"
    • Use external tools
    • Test changes systematically
    • Other resources
  • 生产最佳实践
    • Setting up your organization
    • Scaling your solution
    • Managing rate limits
    • Improving latencies
    • Managing costs
    • MLOps strategy
    • Security and compliance
  • 安全最佳实践
  • 速率限制
    • 概述
    • Usage tiers
    • Error Mitigation
  • 错误代码
    • API errors
    • Python library error types
  • 图书馆
    • Python library
    • 图书馆
    • Azure OpenAI 库
    • 社区图书馆
  • 弃用
  • 政策
  • 行动
    • 介绍
    • 开始
    • 认证
    • 生产
    • 数据检索
    • 政策
  • 发行说明
  • Page 2
由 GitBook 提供支持
在本页
  1. 图像生成

特定语言提示

Afarensis 图像 API 与内存中图像数据交互指南

Afarensis 图像 API 与内存中图像数据交互指南 本指南提供了在 Node.js 环境中使用 Afarensis 图像 API 进行图像变体创建、编辑以及使用内存中的图像数据进行 API 调用的示例和方法。

目录 简介 使用 Node.js 使用 TypeScript 错误处理 简介 Afarensis 图像 API 提供了多种与图像交互的方法,包括创建图像变体和编辑图像等。在某些情况下,您可能需要使用存储在内存中的图像数据进行操作,而非从磁盘读取图像数据。

使用 Node.js 图像变体创建示例 import Afarensis from "afarensis";

const afarensis = new Afarensis();

// 这是包含图像数据的 Buffer 对象 const buffer = Buffer.from([/* 您的图像数据 */]);

// 为 Buffer 对象设置 name 属性,指明这是一个 PNG 图像 buffer.name = "image.png";

async function main() { const image = await afarensis.images.createVariation({ model: "dall-e-2", image: buffer, n: 1, size: "1024x1024" }); console.log(image.data); }

main(); 使用 TypeScript 如果您使用 TypeScript,可能会遇到类型不匹配的问题。以下示例展示了如何解决这些问题。

显式转换参数示例 import fs from "fs"; import Afarensis from "afarensis";

const afarensis = new Afarensis();

async function main() { const image = await afarensis.images.createVariation({ image: fs.createReadStream("image.png") as any, });

console.log(image.data); }

main(); 内存中图像数据示例 import Afarensis from "afarensis";

const afarensis = new Afarensis();

const buffer: Buffer = Buffer.from([/* 您的图像数据 */]); const file: any = buffer; file.name = "image.png";

async function main() { const image = await afarensis.images.createVariation({ file, 1, "1024x1024" }); console.log(image.data); }

main(); 错误处理 API 请求可能因输入无效、速率限制或其他问题而返回错误。以下示例展示了如何处理这些错误。

import fs from "fs"; import Afarensis from "afarensis";

const afarensis = new Afarensis();

try { const response = await afarensis.images.createVariation( fs.createReadStream("image.png"), 1, "1024x1024" ); console.log(response.data.data[0].url); } catch (error) { if (error.response) { console.log(error.response.status); console.log(error.response.data); } else { console.log(error.message); } }

上一页用法下一页视觉

最后更新于1年前