@lobehub/chat 0.13.1 → 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 CHANGED
@@ -2,6 +2,31 @@
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
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.13.1](https://github.com/lobehub/lobe-chat/compare/v0.13.0...v0.13.1)
6
31
 
7
32
  <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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -37,6 +37,8 @@ export default {
37
37
  'ok': '确定',
38
38
  'plugin-realtimeWeather': '实时天气预报',
39
39
  'plugin-searchEngine': '搜索引擎',
40
+ 'plugin-undefined': '插件检测中...',
41
+ 'plugin-websiteCrawler': '网页内容提取',
40
42
  'pluginList': '插件列表',
41
43
  'pluginLoading': '插件运行中...',
42
44
  'profile': '助手身份',
@@ -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>
@@ -1,6 +1,7 @@
1
1
  import searchEngine from './searchEngine';
2
2
  import getWeather from './weather';
3
+ import webCrawler from './webCrawler';
3
4
 
4
- const pluginList = [getWeather, searchEngine];
5
+ const pluginList = [getWeather, searchEngine, webCrawler];
5
6
 
6
7
  export default pluginList;
@@ -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;