@lobehub/chat 0.13.0 → 0.14.0
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.
- package/CHANGELOG.md +50 -0
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/locales/default/common.ts +2 -0
- package/src/pages/api/plugins.api.ts +3 -1
- package/src/pages/chat/[id]/Conversation/MessageExtra.tsx +1 -1
- package/src/plugins/index.ts +2 -1
- package/src/plugins/searchEngine/runner.ts +2 -1
- package/src/plugins/webCrawler/index.ts +20 -0
- package/src/plugins/webCrawler/runner.ts +75 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 0.14.0](https://github.com/lobehub/lobe-chat/compare/v0.13.1...v0.14.0)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-07-24**</sup>
|
|
8
|
+
|
|
9
|
+
#### ✨ Features
|
|
10
|
+
|
|
11
|
+
- **misc**: 支持网页抓取.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's improved
|
|
19
|
+
|
|
20
|
+
- **misc**: 支持网页抓取, closes [#14](https://github.com/lobehub/lobe-chat/issues/14) ([9e933b0](https://github.com/lobehub/lobe-chat/commit/9e933b0))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.13.1](https://github.com/lobehub/lobe-chat/compare/v0.13.0...v0.13.1)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-07-23**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: 修正搜索引擎插件的实现问题.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: 修正搜索引擎插件的实现问题 ([d19a805](https://github.com/lobehub/lobe-chat/commit/d19a805))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
## [Version 0.13.0](https://github.com/lobehub/lobe-chat/compare/v0.12.1...v0.13.0)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-07-23**</sup>
|
package/README.md
CHANGED
|
@@ -66,12 +66,12 @@ $ pnpm start
|
|
|
66
66
|
|
|
67
67
|
> 📊 Total: <kbd>**4**</kbd>
|
|
68
68
|
|
|
69
|
-
<a href="https://github.com/canisminor1990" title="canisminor1990">
|
|
70
|
-
<img src="https://avatars.githubusercontent.com/u/17870709?v=4" width="50" />
|
|
71
|
-
</a>
|
|
72
69
|
<a href="https://github.com/arvinxx" title="arvinxx">
|
|
73
70
|
<img src="https://avatars.githubusercontent.com/u/28616219?v=4" width="50" />
|
|
74
71
|
</a>
|
|
72
|
+
<a href="https://github.com/canisminor1990" title="canisminor1990">
|
|
73
|
+
<img src="https://avatars.githubusercontent.com/u/17870709?v=4" width="50" />
|
|
74
|
+
</a>
|
|
75
75
|
<a href="https://github.com/apps/dependabot" title="dependabot[bot]">
|
|
76
76
|
<img src="https://avatars.githubusercontent.com/in/29110?v=4" width="50" />
|
|
77
77
|
</a>
|
package/package.json
CHANGED
|
@@ -13,13 +13,15 @@ export default async function handler(req: Request) {
|
|
|
13
13
|
|
|
14
14
|
const stream = await createChatCompletion(payload, (payload) => ({
|
|
15
15
|
experimental_onFunctionCall: async ({ name, arguments: args }, createFunctionCallMessages) => {
|
|
16
|
-
console.log(
|
|
16
|
+
console.log(`检测到 functionCall: ${name}`);
|
|
17
17
|
|
|
18
18
|
const func = pluginList.find((f) => f.name === name);
|
|
19
19
|
|
|
20
20
|
if (func) {
|
|
21
21
|
const result = await func.runner(args as any);
|
|
22
22
|
|
|
23
|
+
console.log(`[${name}]`, args, `result:`, JSON.stringify(result, null, 2));
|
|
24
|
+
|
|
23
25
|
const newMessages = createFunctionCallMessages(result) as ChatCompletionRequestMessage[];
|
|
24
26
|
|
|
25
27
|
return openai.createChatCompletion({
|
|
@@ -69,7 +69,7 @@ const MessageExtra = ({ role, extra, function_call }: ChatMessage): ReactNode =>
|
|
|
69
69
|
if (!(hasModelTag || hasFuncTag)) return;
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
|
-
<Flexbox className={styles.container}>
|
|
72
|
+
<Flexbox className={styles.container} horizontal>
|
|
73
73
|
{hasFuncTag && funcTag}
|
|
74
74
|
{hasModelTag && modelTag}
|
|
75
75
|
</Flexbox>
|
package/src/plugins/index.ts
CHANGED
|
@@ -76,9 +76,10 @@ export interface DetectedExtensions {
|
|
|
76
76
|
month_ago: number;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const fetchResult = async (keywords: string) => {
|
|
79
|
+
const fetchResult = async ({ keywords }: { keywords: string }) => {
|
|
80
80
|
const params = {
|
|
81
81
|
api_key: API_KEY,
|
|
82
|
+
engine: 'google',
|
|
82
83
|
gl: 'cn',
|
|
83
84
|
google_domain: 'google.com',
|
|
84
85
|
hl: 'zh-cn',
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import runner from './runner';
|
|
2
|
+
|
|
3
|
+
const schema = {
|
|
4
|
+
description: '提取网页内容并总结',
|
|
5
|
+
name: 'websiteCrawler',
|
|
6
|
+
parameters: {
|
|
7
|
+
properties: {
|
|
8
|
+
url: {
|
|
9
|
+
description: '网页内容',
|
|
10
|
+
type: 'string',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
required: ['url'],
|
|
14
|
+
type: 'object',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getWeather = { avatar: '🕸', name: 'websiteCrawler', runner, schema };
|
|
19
|
+
|
|
20
|
+
export default getWeather;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type DataResults = DataItem[];
|
|
2
|
+
|
|
3
|
+
export interface DataItem {
|
|
4
|
+
crawl: Crawl;
|
|
5
|
+
markdown: string;
|
|
6
|
+
metadata: Metadata;
|
|
7
|
+
screenshotUrl: any;
|
|
8
|
+
text: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Crawl {
|
|
13
|
+
depth: number;
|
|
14
|
+
httpStatusCode: number;
|
|
15
|
+
loadedTime: string;
|
|
16
|
+
loadedUrl: string;
|
|
17
|
+
referrerUrl: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Metadata {
|
|
21
|
+
author: any;
|
|
22
|
+
canonicalUrl: string;
|
|
23
|
+
description: string;
|
|
24
|
+
keywords: string;
|
|
25
|
+
languageCode: string;
|
|
26
|
+
title: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const BASE_URL =
|
|
30
|
+
'https://api.apify.com/v2/acts/apify~website-content-crawler/run-sync-get-dataset-items';
|
|
31
|
+
const token = process.env.APIFY_API_KEY;
|
|
32
|
+
|
|
33
|
+
const runner = async ({ url }: { url: string }) => {
|
|
34
|
+
// Prepare Actor input
|
|
35
|
+
const input = {
|
|
36
|
+
aggressivePrune: false,
|
|
37
|
+
clickElementsCssSelector: '[aria-expanded="false"]',
|
|
38
|
+
debugMode: false,
|
|
39
|
+
dynamicContentWaitSecs: 3,
|
|
40
|
+
proxyConfiguration: {
|
|
41
|
+
useApifyProxy: true,
|
|
42
|
+
},
|
|
43
|
+
removeCookieWarnings: true,
|
|
44
|
+
removeElementsCssSelector:
|
|
45
|
+
'nav, footer, script, style, noscript, svg,\n[role="alert"],\n[role="banner"],\n[role="dialog"],\n[role="alertdialog"],\n[role="region"][aria-label*="skip" i],\n[aria-modal="true"]',
|
|
46
|
+
saveFiles: false,
|
|
47
|
+
saveHtml: false,
|
|
48
|
+
saveMarkdown: true,
|
|
49
|
+
saveScreenshots: false,
|
|
50
|
+
startUrls: [{ url }],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const data = await fetch(`${BASE_URL}?token=${token}`, {
|
|
55
|
+
body: JSON.stringify(input),
|
|
56
|
+
headers: {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
},
|
|
59
|
+
method: 'POST',
|
|
60
|
+
});
|
|
61
|
+
const result = (await data.json()) as DataResults;
|
|
62
|
+
|
|
63
|
+
const item = result[0];
|
|
64
|
+
return {
|
|
65
|
+
content: item.markdown,
|
|
66
|
+
title: item.metadata.title,
|
|
67
|
+
url: item.url,
|
|
68
|
+
};
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error);
|
|
71
|
+
return { content: '抓取失败', errorMessage: (error as any).message };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default runner;
|