myesn

myEsn2E9

hi
github

OpenAI Translator 使用指南

  1. 下载 openai-translator 并双击安装
  2. 根据文档安装 SnipDo,通过 Microsoft Store 下载应用时记得关闭代理软件
  3. 打开代理软件,选中美国 IP 的代理
  4. 打开 OpenAI API keys 页面创建一个 API key(把别人的都删光光哈哈哈),从独角兽每日分享或其他平台获取免费的 ChatGPT 账号进行登录
  5. 将创建的 API key 填入 OpenAI Translator 中

删光脚本(运行于 F12 > Console):
不好意思,实在是不好意思,因为每个账号免费的额度太少了

// !!首次运行前需要设置 Authorization、apiKeySentitiveId 两个参数
const authorizationHeader = {
  Authorization: "Bearer sess-p70aSrrGmA5ZrlDCSFTlvmZoogv2Sjbx7OiYJgP6",
};
let apiKeySentitiveId = "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";

const apiKeyName = "this-account-belongs-me";
const interval = 5000;

async function bootstrap() {
  console.log("流程开启");

  const apiKeys = await retrieveApiKeys();
  // 删除所有 apiKeyName 不匹配的
  const otherApiKeys = apiKeys.filter((x) => x.name !== apiKeyName);

  for (const otherApiKey of otherApiKeys) {
    await deleteApiKey(otherApiKey.sensitive_id, otherApiKey.created);
  }
  console.log("无关数据删除完毕");

  const apiKey = apiKeys.find((x) => x.name === apiKeyName);

  if (!apiKey) {
    console.log(`找不到 ${apiKeyName},正在自动创建`);
    await createApiKey(apiKeyName);
    console.warn(`自动创建 API Key 成功,请手动复制然后重新设置翻译软件:`);
    console.log(apiKeySentitiveId);
  } else {    
    console.log(`API Key 已存在,不需要重新创建:`);
    console.log(apiKeySentitiveId);
  }

  console.log(`流程开启,${interval} 毫秒后会再次执行`);

  setTimeout(bootstrap, interval);
}
bootstrap();

async function retrieveApiKeys() {
  var apiKeysResponse = await fetch(
    "https://api.openai.com/dashboard/user/api_keys",
    {
      headers: {
        ...authorizationHeader,
      },
    }
  );
  var apiKeys = (await apiKeysResponse.json()).data;
  return apiKeys;
}

async function createApiKey(name) {
  var deleteApiKeyResponse = await fetch(
    "https://api.openai.com/dashboard/user/api_keys",
    {
      method: "POST",
      headers: {
        ...authorizationHeader,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        action: "create",
        name,
      }),
    }
  );

  const content = await deleteApiKeyResponse.json();
  const isSuccess = content.result === "success";

  if (isSuccess) {
    // 保存最新的 key
    apiKeySentitiveId = content.key.sensitive_id;
  }

  return isSuccess;
}

async function deleteApiKey(redacted_key, created_at) {
  var deleteApiKeyResponse = await fetch(
    "https://api.openai.com/dashboard/user/api_keys",
    {
      method: "POST",
      headers: {
        ...authorizationHeader,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        action: "delete",
        redacted_key: redacted_key,
        created_at: created_at,
      }),
    }
  );

  const content = await deleteApiKeyResponse.json();
  return content.result === "success";
}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。