Merge pull request #293 from tianlinliang/main
更新了新的Bing search customer API支持
This commit is contained in:
commit
468a56e91f
|
@ -48,6 +48,19 @@ pnpm install
|
||||||
PORT: 3000,
|
PORT: 3000,
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
如果您注册的是Bing Customer Search的API,您可以修改您的配置文件为如下,并且填写您的Custom Configuration ID:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
export default {
|
||||||
|
LOG_LEVEL: 'debug',
|
||||||
|
BROWSER_TIMEOUT: 10000,
|
||||||
|
BING_SEARCH_API_URL: 'https://api.bing.microsoft.com/v7.0/custom/',
|
||||||
|
BING_SEARCH_API_KEY: 'YOUR_BING_SEARCH_API_KEY',
|
||||||
|
CUSTOM_CONFIG_ID : 'YOUR_CUSTOM_CONFIG_ID', //将您的Custom Configuration ID放在此处
|
||||||
|
HOST: 'localhost',
|
||||||
|
PORT: 3000,
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
2. 文生图功能需要调用 CogView API。修改 `src/tools/config.py`
|
2. 文生图功能需要调用 CogView API。修改 `src/tools/config.py`
|
||||||
,提供文生图功能需要使用的 [智谱 AI 开放平台](https://open.bigmodel.cn) API Key:
|
,提供文生图功能需要使用的 [智谱 AI 开放平台](https://open.bigmodel.cn) API Key:
|
||||||
|
|
|
@ -172,13 +172,20 @@ abstract class BaseBrowser {
|
||||||
logger.debug(`Searching for: ${query}`);
|
logger.debug(`Searching for: ${query}`);
|
||||||
const search = new URLSearchParams({ q: query });
|
const search = new URLSearchParams({ q: query });
|
||||||
recency_days > 0 && search.append('recency_days', recency_days.toString());
|
recency_days > 0 && search.append('recency_days', recency_days.toString());
|
||||||
|
if (config.CUSTOM_CONFIG_ID) {
|
||||||
|
search.append('customconfig', config.CUSTOM_CONFIG_ID.toString());
|
||||||
|
}
|
||||||
|
const url = `${config.BING_SEARCH_API_URL}/search?${search.toString()}`;
|
||||||
|
console.log('Full URL:', url); // 输出完整的 URL查看是否正确
|
||||||
|
|
||||||
return withTimeout(
|
return withTimeout(
|
||||||
config.BROWSER_TIMEOUT,
|
config.BROWSER_TIMEOUT,
|
||||||
fetch(`${config.BING_SEARCH_API_URL}/search?${search.toString()}`, {
|
fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Ocp-Apim-Subscription-Key': config.BING_SEARCH_API_KEY,
|
'Ocp-Apim-Subscription-Key': config.BING_SEARCH_API_KEY,
|
||||||
}
|
}
|
||||||
}).then(
|
})
|
||||||
|
.then(
|
||||||
res =>
|
res =>
|
||||||
res.json() as Promise<{
|
res.json() as Promise<{
|
||||||
queryContext: {
|
queryContext: {
|
||||||
|
@ -255,11 +262,11 @@ abstract class BaseBrowser {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error(err.message);
|
logger.error(`搜索请求失败:${query},错误信息:${err.message}`);
|
||||||
if (err.code === 'ECONNABORTED') {
|
if (err.code === 'ECONNABORTED') {
|
||||||
throw new Error(`Timeout while executing search for: ${query}`);
|
throw new Error(`Timeout while executing search for: ${query}`);
|
||||||
}
|
}
|
||||||
throw new Error(`Network or server error occurred`);
|
throw new Error(`网络或服务器发生错误,请检查URL: ${url}`);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
open_url: (url: string) => {
|
open_url: (url: string) => {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
export default {
|
export default {
|
||||||
LOG_LEVEL: 'debug',
|
LOG_LEVEL: 'debug',
|
||||||
|
|
||||||
BROWSER_TIMEOUT: 10000,
|
BROWSER_TIMEOUT: 10000,
|
||||||
BING_SEARCH_API_URL: 'https://api.bing.microsoft.com/',
|
BING_SEARCH_API_URL: 'https://api.bing.microsoft.com/v7.0/custom/',
|
||||||
BING_SEARCH_API_KEY: '',
|
BING_SEARCH_API_KEY: 'YOUR_BING_SEARCH_API_KEY',
|
||||||
|
CUSTOM_CONFIG_ID : 'YOUR_CUSTOM_CONFIG_ID', //将您的Custom Configuration ID放在此处
|
||||||
HOST: 'localhost',
|
HOST: 'localhost',
|
||||||
PORT: 3000,
|
PORT: 3000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue