概念

下 HTTP 客户客户

每个资源下有一个客户端。 它附加会话, 携带机器头, 分析答案, 并将失败变成输入错误, 然后再看它 。

one instance per IaGenifytyped failures
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

你很少直接碰它 api.models, api.storage 其余的人都经过它。知道它做什么还是值得一页,因为它的行为就是当一个电话发生意外时你正在调试。

每一次电话发生什么

Step它可以做什么
1 ・ 届会获得有效的 JWT,如果需要,可以刷新或交换密钥。略过少数不需要身份的电话。
2 信头添加版本、机器代号以及检测到的资源。
3 机构JSON除非您通过了 FormData —— 那么内容- 类型将留待运行时间 。
4 计时器超时后中止, 除非超时为 0 。
5 分析JSON 当它能够时; 否则, 原始文本, 以 { msg } 表示 。
6 失败401号的重试一次, 然后输入错误, 显示状态、 代码和细节 。

A. 不作答复的答复 JSON

客户从来不会丢给无法分析的身体。JSON 成功回来 回到 { msg: "…" } 而不是,这是你会看到的,如果有什么东西 在你和 API 答案在它的位置——代理、俘虏门户、网关错误页面。

const result = await assistant.generate({ inputs });

if (result.msg !== undefined && result.outputs === undefined) {
  // Something answered, but it was not the API
  console.error("unexpected body:", result.msg.slice(0, 200));
}
result = assistant.generate(inputs=inputs)

if "msg" in result and "outputs" not in result:
    # Something answered, but it was not the API
    print("unexpected body:", str(result["msg"])[:200])

上传

当身体 FormData,客户端没有设置 Content-Type。这是故意的:边界是由运行时间产生的,用手设定页眉会产生一个服务器无法分割的身体。

指在别的地方

// Explicit
const api = new IaGenify({ apiKey, baseUrl: "https://api.iagenify.com" });

// From the environment
// IAGENIFY_API_URL=https://api.iagenify.com
const api = new IaGenify({ apiKey });

api.baseUrl;   // whichever won
# Explicit
api = IaGenify(api_key=api_key, base_url="https://api.iagenify.com")

# From the environment
# IAGENIFY_API_URL=https://api.iagenify.com
api = IaGenify(api_key=api_key)

api.base_url   # whichever won

两者都没有,客户没有地址可以打电话,而且每个请求都失败 unreachable. 部署的单位, baseUrl 是首先检查的一件事: 读取 api.baseUrl 并且确认它 https://api.iagenify.com.