@baiducloud/qianfan
Advanced tools
Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "@baiducloud/qianfan", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public", |
@@ -29,3 +29,3 @@ // Copyright (c) 2024 Baidu, Inc. All Rights Reserved. | ||
*/ | ||
public async chat(body: ChatBody, model = 'ERNIE-Bot-turbo'): Promise<Resp | AsyncIterable<Resp>> { | ||
public async chat(body: ChatBody, model = 'ERNIE-Lite-8K'): Promise<Resp | AsyncIterable<Resp>> { | ||
const stream = body.stream ?? false; | ||
@@ -32,0 +32,0 @@ const {modelInfoMapUppercase, modelUppercase, modelLowercase} = getUpperCaseModelAndModelMap( |
@@ -168,6 +168,10 @@ // Copyright (c) 2024 Baidu, Inc. All Rights Reserved. | ||
let buffer = new Uint8Array(); // 初始化缓存的 Buffer | ||
let previousChunkLastByte: number | null = null; | ||
const iter = readableStreamAsyncIterable<Bytes>(response.body); | ||
for await (const chunk of iter) { | ||
if (endsWith1010(chunk as Uint8Array)) { | ||
if (chunk[0] === 10) { | ||
continue; | ||
} | ||
if (previousChunkLastByte === 10) { | ||
buffer = concatUint8Arrays(buffer, chunk as Uint8Array); | ||
@@ -187,2 +191,4 @@ | ||
} | ||
// 保存当前 chunk 的最后一个字节 | ||
previousChunkLastByte = chunk[chunk.length - 1] as number; ; | ||
} | ||
@@ -370,11 +376,2 @@ | ||
// 判断 Uint8Array 是否以 10,10 结尾 | ||
function endsWith1010(uintArray: Uint8Array): boolean { | ||
const len = uintArray.length; | ||
if (len < 2) { | ||
return false; | ||
} | ||
return uintArray[len - 2] === 10 && uintArray[len - 1] === 10; | ||
} | ||
// 合并两个 Uint8Array | ||
@@ -381,0 +378,0 @@ function concatUint8Arrays(a: Uint8Array, b: Uint8Array): Uint8Array { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3016535
101528
65