Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@baiducloud/qianfan

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@baiducloud/qianfan - npm Package Compare versions

Comparing version 0.1.5-beta.2 to 0.1.5

3

package.json
{
"name": "@baiducloud/qianfan",
"version": "0.1.5-beta.2",
"version": "0.1.5",
"publishConfig": {

@@ -37,2 +37,3 @@ "access": "public",

"node-fetch": "2.7.0",
"qianfan-wt": "^0.0.20",
"rollup": "^3.29.4",

@@ -39,0 +40,0 @@ "typescript": "^5.3.3",

@@ -103,2 +103,35 @@ // Copyright (c) 2024 Baidu, Inc. All Rights Reserved.

/**
* 获取 IAM 路径 (配置proxy情况下)
*
* @param type 路径类型
* @param model 模型名称
* @returns 返回 IAM 路径
* @throws 当 qianfanBaseUrl 包含 'aip.baidubce.com' 时,抛出错误提示设置 proxy 的 baseUrl
* @throws 当 qianfanConsoleApiBaseUrl 未设置时,抛出错误提示未设置 qianfanConsoleApiBaseUrl
* @throws 当 Endpoint 未设置且 qianfanConsoleApiBaseUrl 不包含 'qianfan.baidubce.com' 时,抛出错误提示未设置 Endpoint
*/
private async getIAMPath(type, model) {
if (this.qianfanBaseUrl.includes('aip.baidubce.com')) {
throw new Error('请设置proxy的baseUrl');
}
const dynamicModelEndpoint = new DynamicModelEndpoint(
null,
this.qianfanConsoleApiBaseUrl,
this.qianfanBaseUrl
);
return await dynamicModelEndpoint.getEndpoint(type, model);
}
public async getAllModels(type): Promise<string[]> {
const dynamicModelEndpoint = new DynamicModelEndpoint(
null,
this.qianfanConsoleApiBaseUrl,
this.qianfanBaseUrl
);
const map = await dynamicModelEndpoint.getDynamicMap(type);
const keysArray: string[] = Array.from(map.keys()); // 将Map的键转换为数组
return keysArray;
}
protected async sendRequest(

@@ -111,3 +144,2 @@ type: string,

): Promise<Resp | AsyncIterableType> {
// 判断当前环境,node需要鉴权,浏览器不需要鉴权(需要设置proxy的baseUrl、consoleUrl)·
let fetchOptions;

@@ -167,34 +199,12 @@ // 如果baseUrl是aip.baidubce.com,证明用户未配置proxy url,则认为需要放开鉴权

// 设置了proxy url走prxoy
if (this.qianfanBaseUrl.includes('aip.baidubce.com')) {
throw new Error('请设置proxy的baseUrl');
const IAMPath = await this.getIAMPath(type, model);
if (!IAMPath) {
throw new Error(`${model} is not supported`);
}
// 如果设置了管控api,则使用管控api获取最新模型
if (this.qianfanConsoleApiBaseUrl && !this.qianfanConsoleApiBaseUrl.includes('qianfan.baidubce.com')) {
const dynamicModelEndpoint = new DynamicModelEndpoint(
null,
this.qianfanConsoleApiBaseUrl,
this.qianfanBaseUrl
);
let IAMPath = '';
if (this.Endpoint) {
IAMPath = getPath({
Authentication: 'IAM',
api_base: this.qianfanBaseUrl,
endpoint: this.Endpoint,
type,
});
}
else {
IAMPath = await dynamicModelEndpoint.getEndpoint(type, model);
}
if (!IAMPath) {
throw new Error(`${model} is not supported`);
}
fetchOptions = {
url: `${this.qianfanBaseUrl}${IAMPath}`,
method: 'POST',
headers: this.headers,
body: requestBody,
};
}
fetchOptions = {
url: `${this.qianfanBaseUrl}${IAMPath}`,
method: 'POST',
headers: this.headers,
body: requestBody,
};
}

@@ -201,0 +211,0 @@ try {

@@ -21,2 +21,3 @@ // Copyright (c) 2024 Baidu, Inc. All Rights Reserved.

const type = ModelType.CHAT;
class ChatCompletion extends BaseClient {

@@ -33,3 +34,2 @@ /**

const modelKey = model.toLowerCase();
const type = ModelType.CHAT;
const typeMap = getTypeMap(typeModelEndpointMap, type) ?? new Map();

@@ -45,4 +45,8 @@ const endPoint = typeMap.get(modelKey) || '';

}
public async getModels(): Promise<string[]> {
return this.getAllModels(type);
}
}
export default ChatCompletion;

@@ -143,2 +143,6 @@ import {Mutex} from 'async-mutex';

}
public async getDynamicMap(type: string): Promise<Map<string, string> | undefined> {
await this.updateDynamicModelEndpoint(type);
return this.getDynamicTypeModelEndpointMap().get(type);
}

@@ -145,0 +149,0 @@ getDynamicMapExpireAt() {

@@ -172,5 +172,2 @@ // Copyright (c) 2024 Baidu, Inc. All Rights Reserved.

for await (const chunk of iter) {
if (chunk[0] === 10) {
continue;
}
if (previousChunkLastByte === 10) {

@@ -177,0 +174,0 @@ buffer = concatUint8Arrays(buffer, chunk as 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc