uapi-browser-sdk 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+
2
+ # PostTranslateStream500Response
3
+
4
+
5
+ ## Properties
6
+
7
+ Name | Type
8
+ ------------ | -------------
9
+ `error` | string
10
+ `code` | string
11
+
12
+ ## Example
13
+
14
+ ```typescript
15
+ import type { PostTranslateStream500Response } from 'uapi-browser-sdk-browser'
16
+
17
+ // TODO: Update the object below with actual values
18
+ const example = {
19
+ "error": Translation service unavailable,
20
+ "code": SERVICE_ERROR,
21
+ } satisfies PostTranslateStream500Response
22
+
23
+ console.log(example)
24
+
25
+ // Convert the instance to a JSON string
26
+ const exampleJSON: string = JSON.stringify(example)
27
+ console.log(exampleJSON)
28
+
29
+ // Parse the JSON string back to an object
30
+ const exampleParsed = JSON.parse(exampleJSON) as PostTranslateStream500Response
31
+ console.log(exampleParsed)
32
+ ```
33
+
34
+ [[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
35
+
36
+
@@ -0,0 +1,40 @@
1
+
2
+ # PostTranslateStreamRequest
3
+
4
+
5
+ ## Properties
6
+
7
+ Name | Type
8
+ ------------ | -------------
9
+ `query` | string
10
+ `toLang` | string
11
+ `fromLang` | string
12
+ `tone` | string
13
+
14
+ ## Example
15
+
16
+ ```typescript
17
+ import type { PostTranslateStreamRequest } from 'uapi-browser-sdk-browser'
18
+
19
+ // TODO: Update the object below with actual values
20
+ const example = {
21
+ "query": Hello, how are you?,
22
+ "toLang": 中文,
23
+ "fromLang": 英文,
24
+ "tone": ,
25
+ } satisfies PostTranslateStreamRequest
26
+
27
+ console.log(example)
28
+
29
+ // Convert the instance to a JSON string
30
+ const exampleJSON: string = JSON.stringify(example)
31
+ console.log(exampleJSON)
32
+
33
+ // Parse the JSON string back to an object
34
+ const exampleParsed = JSON.parse(exampleJSON) as PostTranslateStreamRequest
35
+ console.log(exampleParsed)
36
+ ```
37
+
38
+ [[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
39
+
40
+
@@ -6,6 +6,7 @@ All URIs are relative to *https://uapis.cn/api/v1*
6
6
  |------------- | ------------- | -------------|
7
7
  | [**getAiTranslateLanguages**](TranslateApi.md#getaitranslatelanguages) | **GET** /ai/translate/languages | 获取AI翻译支持的语言和配置 |
8
8
  | [**postAiTranslate**](TranslateApi.md#postaitranslateoperation) | **POST** /ai/translate | AI智能翻译 |
9
+ | [**postTranslateStream**](TranslateApi.md#posttranslatestreamoperation) | **POST** /translate/stream | 流式翻译(中英互译) |
9
10
  | [**postTranslateText**](TranslateApi.md#posttranslatetextoperation) | **POST** /translate/text | 多语言文本翻译 |
10
11
 
11
12
 
@@ -143,6 +144,75 @@ No authorization required
143
144
  [[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
144
145
 
145
146
 
147
+ ## postTranslateStream
148
+
149
+ > string postTranslateStream(postTranslateStreamRequest)
150
+
151
+ 流式翻译(中英互译)
152
+
153
+ 想让翻译结果像打字机一样逐字显示出来?这个流式翻译接口能实现这种效果。 ## 功能概述 不同于传统翻译API一次性返回完整结果,这个接口会实时地、一个字一个字地把翻译内容推给你(就像ChatGPT回复消息那样),非常适合用在聊天应用、直播字幕等需要即时反馈的场景。 ## 它能做什么 - **中英互译**:支持中文和英文之间的双向翻译 - **自动识别**:不确定源语言?设置为 `auto` 让我们自动检测 - **逐字返回**:翻译结果会像打字机一样逐字流式返回,用户体验更流畅 - **音频朗读**:部分翻译结果会附带音频链接,方便朗读 ## 支持的语言 目前专注于中英互译,支持以下选项: - `中文`(简体/繁体) - `英文` - `auto`(自动检测)
154
+
155
+ ### Example
156
+
157
+ ```ts
158
+ import {
159
+ Configuration,
160
+ TranslateApi,
161
+ } from 'uapi-browser-sdk-browser';
162
+ import type { PostTranslateStreamOperationRequest } from 'uapi-browser-sdk-browser';
163
+
164
+ async function example() {
165
+ console.log("🚀 Testing uapi-browser-sdk-browser SDK...");
166
+ const api = new TranslateApi();
167
+
168
+ const body = {
169
+ // PostTranslateStreamRequest | 包含翻译参数的JSON对象
170
+ postTranslateStreamRequest: ...,
171
+ } satisfies PostTranslateStreamOperationRequest;
172
+
173
+ try {
174
+ const data = await api.postTranslateStream(body);
175
+ console.log(data);
176
+ } catch (error) {
177
+ console.error(error);
178
+ }
179
+ }
180
+
181
+ // Run the test
182
+ example().catch(console.error);
183
+ ```
184
+
185
+ ### Parameters
186
+
187
+
188
+ | Name | Type | Description | Notes |
189
+ |------------- | ------------- | ------------- | -------------|
190
+ | **postTranslateStreamRequest** | [PostTranslateStreamRequest](PostTranslateStreamRequest.md) | 包含翻译参数的JSON对象 | |
191
+
192
+ ### Return type
193
+
194
+ **string**
195
+
196
+ ### Authorization
197
+
198
+ No authorization required
199
+
200
+ ### HTTP request headers
201
+
202
+ - **Content-Type**: `application/json`
203
+ - **Accept**: `text/event-stream`, `application/json`
204
+
205
+
206
+ ### HTTP response details
207
+ | Status code | Description | Response headers |
208
+ |-------------|-------------|------------------|
209
+ | **200** | SSE流式响应。Content-Type为text/event-stream | - |
210
+ | **400** | 请求参数错误 | - |
211
+ | **500** | 翻译服务错误 | - |
212
+
213
+ [[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
214
+
215
+
146
216
  ## postTranslateText
147
217
 
148
218
  > PostTranslateText200Response postTranslateText(toLang, postTranslateTextRequest)
@@ -22,6 +22,9 @@ import type {
22
22
  PostAiTranslate429Response,
23
23
  PostAiTranslate500Response,
24
24
  PostAiTranslateRequest,
25
+ PostTranslateStream400Response,
26
+ PostTranslateStream500Response,
27
+ PostTranslateStreamRequest,
25
28
  PostTranslateText200Response,
26
29
  PostTranslateText400Response,
27
30
  PostTranslateText500Response,
@@ -42,6 +45,12 @@ import {
42
45
  PostAiTranslate500ResponseToJSON,
43
46
  PostAiTranslateRequestFromJSON,
44
47
  PostAiTranslateRequestToJSON,
48
+ PostTranslateStream400ResponseFromJSON,
49
+ PostTranslateStream400ResponseToJSON,
50
+ PostTranslateStream500ResponseFromJSON,
51
+ PostTranslateStream500ResponseToJSON,
52
+ PostTranslateStreamRequestFromJSON,
53
+ PostTranslateStreamRequestToJSON,
45
54
  PostTranslateText200ResponseFromJSON,
46
55
  PostTranslateText200ResponseToJSON,
47
56
  PostTranslateText400ResponseFromJSON,
@@ -57,6 +66,10 @@ export interface PostAiTranslateOperationRequest {
57
66
  postAiTranslateRequest: PostAiTranslateRequest;
58
67
  }
59
68
 
69
+ export interface PostTranslateStreamOperationRequest {
70
+ postTranslateStreamRequest: PostTranslateStreamRequest;
71
+ }
72
+
60
73
  export interface PostTranslateTextOperationRequest {
61
74
  toLang: PostTranslateTextOperationToLangEnum;
62
75
  postTranslateTextRequest: PostTranslateTextRequest;
@@ -150,6 +163,51 @@ export class TranslateApi extends runtime.BaseAPI {
150
163
  return await response.value();
151
164
  }
152
165
 
166
+ /**
167
+ * 想让翻译结果像打字机一样逐字显示出来?这个流式翻译接口能实现这种效果。 ## 功能概述 不同于传统翻译API一次性返回完整结果,这个接口会实时地、一个字一个字地把翻译内容推给你(就像ChatGPT回复消息那样),非常适合用在聊天应用、直播字幕等需要即时反馈的场景。 ## 它能做什么 - **中英互译**:支持中文和英文之间的双向翻译 - **自动识别**:不确定源语言?设置为 `auto` 让我们自动检测 - **逐字返回**:翻译结果会像打字机一样逐字流式返回,用户体验更流畅 - **音频朗读**:部分翻译结果会附带音频链接,方便朗读 ## 支持的语言 目前专注于中英互译,支持以下选项: - `中文`(简体/繁体) - `英文` - `auto`(自动检测)
168
+ * 流式翻译(中英互译)
169
+ */
170
+ async postTranslateStreamRaw(requestParameters: PostTranslateStreamOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string>> {
171
+ if (requestParameters['postTranslateStreamRequest'] == null) {
172
+ throw new runtime.RequiredError(
173
+ 'postTranslateStreamRequest',
174
+ 'Required parameter "postTranslateStreamRequest" was null or undefined when calling postTranslateStream().'
175
+ );
176
+ }
177
+
178
+ const queryParameters: any = {};
179
+
180
+ const headerParameters: runtime.HTTPHeaders = {};
181
+
182
+ headerParameters['Content-Type'] = 'application/json';
183
+
184
+
185
+ let urlPath = `/translate/stream`;
186
+
187
+ const response = await this.request({
188
+ path: urlPath,
189
+ method: 'POST',
190
+ headers: headerParameters,
191
+ query: queryParameters,
192
+ body: PostTranslateStreamRequestToJSON(requestParameters['postTranslateStreamRequest']),
193
+ }, initOverrides);
194
+
195
+ if (this.isJsonMime(response.headers.get('content-type'))) {
196
+ return new runtime.JSONApiResponse<string>(response);
197
+ } else {
198
+ return new runtime.TextApiResponse(response) as any;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * 想让翻译结果像打字机一样逐字显示出来?这个流式翻译接口能实现这种效果。 ## 功能概述 不同于传统翻译API一次性返回完整结果,这个接口会实时地、一个字一个字地把翻译内容推给你(就像ChatGPT回复消息那样),非常适合用在聊天应用、直播字幕等需要即时反馈的场景。 ## 它能做什么 - **中英互译**:支持中文和英文之间的双向翻译 - **自动识别**:不确定源语言?设置为 `auto` 让我们自动检测 - **逐字返回**:翻译结果会像打字机一样逐字流式返回,用户体验更流畅 - **音频朗读**:部分翻译结果会附带音频链接,方便朗读 ## 支持的语言 目前专注于中英互译,支持以下选项: - `中文`(简体/繁体) - `英文` - `auto`(自动检测)
204
+ * 流式翻译(中英互译)
205
+ */
206
+ async postTranslateStream(requestParameters: PostTranslateStreamOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string> {
207
+ const response = await this.postTranslateStreamRaw(requestParameters, initOverrides);
208
+ return await response.value();
209
+ }
210
+
153
211
  /**
154
212
  * 需要跨越语言的鸿沟进行交流?这个翻译接口是你可靠的\'同声传译\'。 ## 功能概述 你可以将一段源语言文本(我们能自动检测源语言)翻译成你指定的任何目标语言。无论是中译英、日译法,都不在话下。 ## 支持的语言 我们支持超过100种语言的互译,包括但不限于:中文(简体/繁体)、英语、日语、韩语、法语、德语、西班牙语、俄语、阿拉伯语等主流语言,以及各种小语种。详见下方参数列表。
155
213
  * 多语言文本翻译
@@ -0,0 +1,85 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * UAPI
5
+ * UAPI 官方接口文档
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime';
16
+ /**
17
+ *
18
+ * @export
19
+ * @interface PostTranslateStream400Response
20
+ */
21
+ export interface PostTranslateStream400Response {
22
+ /**
23
+ * 错误描述
24
+ * @type {string}
25
+ * @memberof PostTranslateStream400Response
26
+ */
27
+ error?: string;
28
+ /**
29
+ * 错误码
30
+ * @type {string}
31
+ * @memberof PostTranslateStream400Response
32
+ */
33
+ code?: PostTranslateStream400ResponseCodeEnum;
34
+ }
35
+
36
+
37
+ /**
38
+ * @export
39
+ */
40
+ export const PostTranslateStream400ResponseCodeEnum = {
41
+ InvalidRequest: 'INVALID_REQUEST',
42
+ MissingQuery: 'MISSING_QUERY',
43
+ MissingTargetLang: 'MISSING_TARGET_LANG'
44
+ } as const;
45
+ export type PostTranslateStream400ResponseCodeEnum = typeof PostTranslateStream400ResponseCodeEnum[keyof typeof PostTranslateStream400ResponseCodeEnum];
46
+
47
+
48
+ /**
49
+ * Check if a given object implements the PostTranslateStream400Response interface.
50
+ */
51
+ export function instanceOfPostTranslateStream400Response(value: object): value is PostTranslateStream400Response {
52
+ return true;
53
+ }
54
+
55
+ export function PostTranslateStream400ResponseFromJSON(json: any): PostTranslateStream400Response {
56
+ return PostTranslateStream400ResponseFromJSONTyped(json, false);
57
+ }
58
+
59
+ export function PostTranslateStream400ResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): PostTranslateStream400Response {
60
+ if (json == null) {
61
+ return json;
62
+ }
63
+ return {
64
+
65
+ 'error': json['error'] == null ? undefined : json['error'],
66
+ 'code': json['code'] == null ? undefined : json['code'],
67
+ };
68
+ }
69
+
70
+ export function PostTranslateStream400ResponseToJSON(json: any): PostTranslateStream400Response {
71
+ return PostTranslateStream400ResponseToJSONTyped(json, false);
72
+ }
73
+
74
+ export function PostTranslateStream400ResponseToJSONTyped(value?: PostTranslateStream400Response | null, ignoreDiscriminator: boolean = false): any {
75
+ if (value == null) {
76
+ return value;
77
+ }
78
+
79
+ return {
80
+
81
+ 'error': value['error'],
82
+ 'code': value['code'],
83
+ };
84
+ }
85
+
@@ -0,0 +1,73 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * UAPI
5
+ * UAPI 官方接口文档
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime';
16
+ /**
17
+ *
18
+ * @export
19
+ * @interface PostTranslateStream500Response
20
+ */
21
+ export interface PostTranslateStream500Response {
22
+ /**
23
+ * 错误描述
24
+ * @type {string}
25
+ * @memberof PostTranslateStream500Response
26
+ */
27
+ error?: string;
28
+ /**
29
+ *
30
+ * @type {string}
31
+ * @memberof PostTranslateStream500Response
32
+ */
33
+ code?: string;
34
+ }
35
+
36
+ /**
37
+ * Check if a given object implements the PostTranslateStream500Response interface.
38
+ */
39
+ export function instanceOfPostTranslateStream500Response(value: object): value is PostTranslateStream500Response {
40
+ return true;
41
+ }
42
+
43
+ export function PostTranslateStream500ResponseFromJSON(json: any): PostTranslateStream500Response {
44
+ return PostTranslateStream500ResponseFromJSONTyped(json, false);
45
+ }
46
+
47
+ export function PostTranslateStream500ResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): PostTranslateStream500Response {
48
+ if (json == null) {
49
+ return json;
50
+ }
51
+ return {
52
+
53
+ 'error': json['error'] == null ? undefined : json['error'],
54
+ 'code': json['code'] == null ? undefined : json['code'],
55
+ };
56
+ }
57
+
58
+ export function PostTranslateStream500ResponseToJSON(json: any): PostTranslateStream500Response {
59
+ return PostTranslateStream500ResponseToJSONTyped(json, false);
60
+ }
61
+
62
+ export function PostTranslateStream500ResponseToJSONTyped(value?: PostTranslateStream500Response | null, ignoreDiscriminator: boolean = false): any {
63
+ if (value == null) {
64
+ return value;
65
+ }
66
+
67
+ return {
68
+
69
+ 'error': value['error'],
70
+ 'code': value['code'],
71
+ };
72
+ }
73
+
@@ -0,0 +1,112 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * UAPI
5
+ * UAPI 官方接口文档
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime';
16
+ /**
17
+ *
18
+ * @export
19
+ * @interface PostTranslateStreamRequest
20
+ */
21
+ export interface PostTranslateStreamRequest {
22
+ /**
23
+ * 待翻译的文本内容
24
+ * @type {string}
25
+ * @memberof PostTranslateStreamRequest
26
+ */
27
+ query: string;
28
+ /**
29
+ * 目标语言,支持:中文、英文
30
+ * @type {string}
31
+ * @memberof PostTranslateStreamRequest
32
+ */
33
+ toLang: PostTranslateStreamRequestToLangEnum;
34
+ /**
35
+ * 源语言,支持:中文、英文、auto(自动检测)。默认为auto
36
+ * @type {string}
37
+ * @memberof PostTranslateStreamRequest
38
+ */
39
+ fromLang?: PostTranslateStreamRequestFromLangEnum;
40
+ /**
41
+ * 语气参数,可选
42
+ * @type {string}
43
+ * @memberof PostTranslateStreamRequest
44
+ */
45
+ tone?: string;
46
+ }
47
+
48
+
49
+ /**
50
+ * @export
51
+ */
52
+ export const PostTranslateStreamRequestToLangEnum = {
53
+ : '中文',
54
+ 2: '英文'
55
+ } as const;
56
+ export type PostTranslateStreamRequestToLangEnum = typeof PostTranslateStreamRequestToLangEnum[keyof typeof PostTranslateStreamRequestToLangEnum];
57
+
58
+ /**
59
+ * @export
60
+ */
61
+ export const PostTranslateStreamRequestFromLangEnum = {
62
+ : '中文',
63
+ 2: '英文',
64
+ Auto: 'auto'
65
+ } as const;
66
+ export type PostTranslateStreamRequestFromLangEnum = typeof PostTranslateStreamRequestFromLangEnum[keyof typeof PostTranslateStreamRequestFromLangEnum];
67
+
68
+
69
+ /**
70
+ * Check if a given object implements the PostTranslateStreamRequest interface.
71
+ */
72
+ export function instanceOfPostTranslateStreamRequest(value: object): value is PostTranslateStreamRequest {
73
+ if (!('query' in value) || value['query'] === undefined) return false;
74
+ if (!('toLang' in value) || value['toLang'] === undefined) return false;
75
+ return true;
76
+ }
77
+
78
+ export function PostTranslateStreamRequestFromJSON(json: any): PostTranslateStreamRequest {
79
+ return PostTranslateStreamRequestFromJSONTyped(json, false);
80
+ }
81
+
82
+ export function PostTranslateStreamRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): PostTranslateStreamRequest {
83
+ if (json == null) {
84
+ return json;
85
+ }
86
+ return {
87
+
88
+ 'query': json['query'],
89
+ 'toLang': json['to_lang'],
90
+ 'fromLang': json['from_lang'] == null ? undefined : json['from_lang'],
91
+ 'tone': json['tone'] == null ? undefined : json['tone'],
92
+ };
93
+ }
94
+
95
+ export function PostTranslateStreamRequestToJSON(json: any): PostTranslateStreamRequest {
96
+ return PostTranslateStreamRequestToJSONTyped(json, false);
97
+ }
98
+
99
+ export function PostTranslateStreamRequestToJSONTyped(value?: PostTranslateStreamRequest | null, ignoreDiscriminator: boolean = false): any {
100
+ if (value == null) {
101
+ return value;
102
+ }
103
+
104
+ return {
105
+
106
+ 'query': value['query'],
107
+ 'to_lang': value['toLang'],
108
+ 'from_lang': value['fromLang'],
109
+ 'tone': value['tone'],
110
+ };
111
+ }
112
+
@@ -252,6 +252,9 @@ export * from './PostTextMd5Request';
252
252
  export * from './PostTextMd5Verify200Response';
253
253
  export * from './PostTextMd5Verify400Response';
254
254
  export * from './PostTextMd5VerifyRequest';
255
+ export * from './PostTranslateStream400Response';
256
+ export * from './PostTranslateStream500Response';
257
+ export * from './PostTranslateStreamRequest';
255
258
  export * from './PostTranslateText200Response';
256
259
  export * from './PostTranslateText400Response';
257
260
  export * from './PostTranslateText500Response';
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "uapi-browser-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "scripts": { "build": "tsc -p tsconfig.json" },
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.json"
9
+ },
8
10
  "devDependencies": {
9
11
  "typescript": "^5.4.0"
10
12
  }