{"id":20440,"date":"2025-02-06T18:33:44","date_gmt":"2025-02-06T10:33:44","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=20440"},"modified":"2025-02-06T18:33:44","modified_gmt":"2025-02-06T10:33:44","slug":"upstash-rag-chat-component","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/upstash-rag-chat-component\/","title":{"rendered":"\u4e3aNext.js\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0RAG\u9a71\u52a8\u7684\u5728\u7ebf\u804a\u5929\u5de5\u5177"},"content":{"rendered":"<p>Upstash <a href=\"https:\/\/www.kdjingpai.com\/en\/rag\/\">RAG<\/a> Chat Component\u662f\u4e00\u4e2a\u4e13\u4e3aNext.js\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u7684React\u7ec4\u4ef6\uff0c\u65e8\u5728\u63d0\u4f9b\u57fa\u4e8eRAG\uff08\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff09\u6280\u672f\u7684AI\u804a\u5929\u754c\u9762\u3002\u8be5\u7ec4\u4ef6\u7ed3\u5408\u4e86Upstash Vector\u7528\u4e8e\u76f8\u4f3c\u6027\u641c\u7d22\u3001Together AI\u7528\u4e8e\u5927\u8bed\u8a00\u6a21\u578b\uff08LLM\uff09\u3001\u4ee5\u53caVercel AI SDK\u7528\u4e8e\u6d41\u5f0f\u54cd\u5e94\u3002\u901a\u8fc7\u8fd9\u4e00\u7ec4\u4ef6\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4ed6\u4eec\u7684\u5e94\u7528\u4e2d\u96c6\u6210\u5f3a\u5927\u7684\u804a\u5929\u529f\u80fd\uff0c\u652f\u6301\u5b9e\u65f6\u4e0a\u4e0b\u6587\u68c0\u7d22\u548c\u6301\u4e45\u804a\u5929\u8bb0\u5f55\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20441\" title=\"\u4e3aNext.js\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0RAG\u9a71\u52a8\u7684\u804a\u5929\u754c\u9762-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/fe5246749fd6a2c.jpg\" alt=\"\u4e3aNext.js\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0RAG\u9a71\u52a8\u7684\u804a\u5929\u754c\u9762-1\" width=\"376\" height=\"485\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/fe5246749fd6a2c.jpg 376w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/fe5246749fd6a2c-9x12.jpg 9w\" sizes=\"auto, (max-width: 376px) 100vw, 376px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li><strong>\u6d41\u5f0f\u54cd\u5e94\u652f\u6301<\/strong>\uff1a\u63d0\u4f9b\u5373\u65f6\u7684\u804a\u5929\u54cd\u5e94\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li><strong>\u670d\u52a1\u5668\u64cd\u4f5c<\/strong>\uff1a\u652f\u6301\u5728\u670d\u52a1\u5668\u7aef\u6267\u884c\u64cd\u4f5c\uff0c\u786e\u4fdd\u6570\u636e\u5b89\u5168\u548c\u6027\u80fd\u3002<\/li>\n<li><strong>\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/strong>\uff1a\u9002\u914d\u5404\u79cd\u8bbe\u5907\uff0c\u63d0\u4f9b\u4e00\u81f4\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li><strong>\u5b9e\u65f6\u4e0a\u4e0b\u6587\u68c0\u7d22<\/strong>\uff1a\u6839\u636e\u7528\u6237\u8f93\u5165\u5b9e\u65f6\u68c0\u7d22\u76f8\u5173\u4fe1\u606f\uff0c\u63d0\u4f9b\u7cbe\u51c6\u56de\u7b54\u3002<\/li>\n<li><strong>\u6301\u4e45\u804a\u5929\u8bb0\u5f55<\/strong>\uff1a\u652f\u6301\u804a\u5929\u8bb0\u5f55\u7684\u6301\u4e45\u5316\u5b58\u50a8\uff0c\u65b9\u4fbf\u7528\u6237\u67e5\u770b\u5386\u53f2\u5bf9\u8bdd\u3002<\/li>\n<li><strong>\u5b8c\u5168\u81ea\u5b9a\u4e49UI\u7ec4\u4ef6<\/strong>\uff1a\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u81ea\u5b9a\u4e49\u804a\u5929\u754c\u9762\u7684\u5916\u89c2\u548c\u529f\u80fd\u3002<\/li>\n<li><strong>\u6697\/\u4eae\u6a21\u5f0f\u652f\u6301<\/strong>\uff1a\u9002\u5e94\u7528\u6237\u7684\u89c6\u89c9\u504f\u597d\uff0c\u63d0\u4f9b\u8212\u9002\u7684\u4f7f\u7528\u4f53\u9a8c\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u6d41\u7a0b<\/h3>\n<ol>\n<li><strong>\u4f7f\u7528npm\u5b89\u88c5<\/strong>\uff1a<\/li>\n<\/ol>\n<pre><code>   npm install @upstash\/rag-chat-component\r\n<\/code><\/pre>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528pnpm\u5b89\u88c5<\/strong>\uff1a<\/li>\n<\/ol>\n<pre><code>   pnpm add @upstash\/rag-chat-component\r\n<\/code><\/pre>\n<ol start=\"3\">\n<li><strong>\u4f7f\u7528yarn\u5b89\u88c5<\/strong>\uff1a<\/li>\n<\/ol>\n<pre><code>   yarn add @upstash\/rag-chat-component\r\n<\/code><\/pre>\n<h3>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<p>\u5728\u4f7f\u7528\u7ec4\u4ef6\u524d\uff0c\u9700\u8981\u914d\u7f6e\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre><code>UPSTASH_VECTOR_REST_URL=\r\nUPSTASH_VECTOR_REST_TOKEN=\r\nOPENAI_API_KEY=\r\nTOGETHER_API_KEY=\r\n<\/code><\/pre>\n<p>\u5982\u679c\u9700\u8981\u6301\u4e45\u5316\u804a\u5929\u8bb0\u5f55\uff0c\u8fd8\u9700\u914d\u7f6e\uff1a<\/p>\n<pre><code>UPSTASH_REDIS_REST_URL=\r\nUPSTASH_REDIS_REST_TOKEN=\r\n<\/code><\/pre>\n<h3>\u914d\u7f6e\u6837\u5f0f<\/h3>\n<p>\u5728<code>tailwind.config.ts<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>import type { Config } from \"tailwindcss\";\r\nexport default {\r\ncontent: [\".\/node_modules\/@upstash\/rag-chat-component\/**\/*.{js,mjs}\"],\r\n} satisfies Config;\r\n<\/code><\/pre>\n<h3>\u5b9e\u73b0\u804a\u5929\u7ec4\u4ef6<\/h3>\n<p>\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5c06RAG Chat Component\u96c6\u6210\u5230\u60a8\u7684\u5e94\u7528\u4e2d\uff1a<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u72ec\u7acb\u7ec4\u4ef6\u6587\u4ef6\uff08\u63a8\u8350\uff09<\/strong>\uff1a \u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684\u7ec4\u4ef6\u6587\u4ef6\uff0c\u5e76\u5728\u5e94\u7528\u4e2d\u4f7f\u7528\uff1a<\/li>\n<\/ol>\n<pre><code>   \/\/ components\/chat.tsx\r\n\"use client\";\r\nimport { ChatComponent } from \"@upstash\/rag-chat-component\";\r\nexport const Chat = () =&gt; {\r\nreturn &lt;ChatComponent \/&gt;;\r\n};\r\n\/\/ page.tsx\r\nimport { Chat } from \".\/components\/chat\";\r\nexport default function Home() {\r\nreturn (\r\n&lt;&gt;\r\n&lt;Chat \/&gt;\r\n&lt;p&gt;Home&lt;\/p&gt;\r\n&lt;\/&gt;\r\n);\r\n}\r\n<\/code><\/pre>\n<ol start=\"2\">\n<li><strong>\u76f4\u63a5\u5728\u5ba2\u6237\u7aef\u7ec4\u4ef6\u4e2d\u96c6\u6210<\/strong>\uff1a \u76f4\u63a5\u5728\u5ba2\u6237\u7aef\u9875\u9762\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528ChatComponent\uff1a<\/li>\n<\/ol>\n<pre><code>   \/\/ page.tsx\r\n\"use client\";\r\nimport { ChatComponent } from \"@upstash\/rag-chat-component\";\r\nexport default function Home() {\r\nreturn (\r\n&lt;&gt;\r\n&lt;ChatComponent \/&gt;\r\n&lt;p&gt;Home&lt;\/p&gt;\r\n&lt;\/&gt;\r\n);\r\n}\r\n<\/code><\/pre>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<pre><code>import { ChatComponent } from \"@upstash\/rag-chat-component\";\r\nexport default function App() {\r\nreturn (\r\n&lt;div&gt;\r\n&lt;h1&gt;Welcome to RAG Chat&lt;\/h1&gt;\r\n&lt;ChatComponent \/&gt;\r\n&lt;\/div&gt;\r\n);\r\n}\r\n<\/code><\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Next.js\u5e94\u7528\u4e2d\u96c6\u6210\u5e76\u4f7f\u7528Upstash RAG Chat Component\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684AI\u804a\u5929\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Upstash RAG Chat Component\u662f\u4e00\u4e2a\u4e13\u4e3aNext.js\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u7684React\u7ec4\u4ef6\uff0c\u65e8\u5728\u63d0\u4f9b\u57fa\u4e8eRAG\uff08\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff09\u6280\u672f\u7684AI\u804a\u5929\u754c\u9762\u3002\u8be5\u7ec4\u4ef6\u7ed3\u5408\u4e86Upstash Vector\u7528\u4e8e\u76f8\u4f3c\u6027\u641c\u7d22\u3001Together AI\u7528&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61787,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230],"class_list":["post-20440","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/20440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/comments?post=20440"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/20440\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media\/61787"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=20440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=20440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=20440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}