Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需要文本翻译 API,以及 Node.js SDK 使用例子。 #3

Open
1c7 opened this issue Mar 12, 2023 · 3 comments
Open

需要文本翻译 API,以及 Node.js SDK 使用例子。 #3

1c7 opened this issue Mar 12, 2023 · 3 comments

Comments

@1c7
Copy link

1c7 commented Mar 12, 2023

https://www.volcengine.com/docs/4640/65067
image

  1. 文档里没有把 http endpoint 地址写清楚。
@1c7 1c7 changed the title 需要文本翻译 API 需要文本翻译 API,以及 Node.js SDK 使用例子。 Mar 12, 2023
@Otto-J
Copy link

Otto-J commented Mar 14, 2023

刚跑通了, node 的例子,供参考,里面的魔法字符串挺多,如果可以,建议研发把这些常量改为枚举,比如 servicename region version 等

import { Service } from "@volcengine/openapi";

const accessKeyId = env.VOLC_ACCESSKEY;
const secretKey = env.VOLC_SECRETKEY;

const postBody = {
  SourceLanguage: "en",
  TargetLanguage: "zh",
  TextList: ["hello world"],
};

const service = new Service({
  host: "open.volcengineapi.com",
  serviceName: "translate",
  region: "cn-north-1",
  accessKeyId,
  secretKey,
});

const fetchApi = service.createAPI("TranslateText", {
  Version: "2020-06-01",
  method: "POST",
  contentType: "json",
});

const rr = await fetchApi(postBody, {});

// [ { Translation: '你好世界', DetectedSourceLanguage: '', Extra: null } ]
console.log(rr.TranslationList);

@1c7
Copy link
Author

1c7 commented Mar 14, 2023

@Otto-J 非常感谢!

@1c7
Copy link
Author

1c7 commented Mar 17, 2023

实测的确能用

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants