自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Pro-Chat:一款面向未來的開源智能聊天組件

開發(fā) 前端
最近在 Github? 上看到一款非常有意思的開源項目, 定位是開箱即用的大模型對話前端解決方案, 我們使用它可以輕松構(gòu)建聊天組件, 并且可以一鍵集成主流 AI? 大模型, 比如 通義千問?, ChatGpt 等。 (讓前端再也不用從零寫聊天組件了~)

hi, 大家好, 我是徐小夕, 最近在 Github 上看到一款非常有意思的開源項目, 定位是開箱即用的大模型對話前端解決方案, 我們使用它可以輕松構(gòu)建聊天組件, 并且可以一鍵集成主流 AI 大模型, 比如 通義千問, ChatGpt 等。(讓前端再也不用從零寫聊天組件了~)

組件Demo演示

功能亮點

我根據(jù)自己的使用和實踐, 總結(jié)一下這款開源聊天組件的亮點:

  • 簡單易用, 設(shè)計語言統(tǒng)一

它是基于 antd 組件庫進行的二次封裝, 所以我們可以輕松的在 antd 項目中使用, 保持 UI 視覺的統(tǒng)一。

使用啊安裝方式如下:

# @ant-design/pro-editor 基于 antd 和 antd-style,需要在項目中安裝
$ npm install antd antd-style -S
$ npm install @ant-design/pro-chat -S

使用:

import { ProChat } from '@ant-design/pro-chat';

import { useTheme } from 'antd-style';

export default () => {
  const theme = useTheme();
  return (
    <div style={{ background: theme.colorBgLayout }}>
      <ProChat
        helloMessage={
          '歡迎使用 ProChat ,我是你的專屬機器人,這是我們的 Github:[ProChat](https://github.com/ant-design/pro-chat)'
        }
        request={async (messages) => {
          const mockedData: string = `這是一段模擬的對話數(shù)據(jù)。本次會話傳入了${messages.length}條消息`;
          return new Response(mockedData);
        }}
      />
    </div>
  );
};

是不是使用非常簡單~

  • 大模型對話能力集成

它內(nèi)置了對話模型常用的:數(shù)據(jù)編輯、重新發(fā)送、刪除對話等這些默認的基本操作。

  • 對AI模型友好的數(shù)據(jù)結(jié)構(gòu)
const dataArray = [
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "蘋"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "果"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "公司"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "是"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "一"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "家"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "科技"}, "index": 0, "finish_reason": null}]}`,
  `data: {"id": "chatcmpl-6w****KZb6hx****RzIghUz****Qy", "object": "chat.completion.chunk", "created": 1703582861554, "model": "gpt-3.5-turbo-0301", "choices": [{"delta": {"content": "公司"}, "index": 0, "finish_reason": "complete"}]}`,
];

參照 ChatGPT、GLM、通義千問等市面上主流的大模型入?yún)⒊鰠?,減少前端開發(fā)者對這些入?yún)⒑统鰠⒌奶幚怼?/p>

  • 支持豐富的聊天場景, 并且可以根據(jù)業(yè)務(wù)靈活擴展

  • 組件化 & 完善的ts類型定義

圖片圖片

我們可以通過組件暴露的屬性輕松自定義, 并且代碼質(zhì)量和代碼規(guī)范非常優(yōu)質(zhì)。

集成ChatGPT的簡單案例

  1. 安裝依賴
npm install ai --save
npm install openai --save

# or use yarn 、bun、pnpm any else
bun add ai
bun add openai
  1. 業(yè)務(wù)代碼
import OpenAI from 'openai';
import { OpenAIStream, StreamingTextResponse } from 'ai';

export const POST = async (request: Request) => {
  const { messages = [] }: Partial<{ messages: Array<any> }> = await request.json();

  const openai = new OpenAI({
    apiKey: 'OpenAI Key',
    baseURL: 'base url',
  });

  const response = await openai.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages: [...messages],
    stream: true,
  });

  const stream = OpenAIStream(response);
  return new StreamingTextResponse(stream);
};
  1. 設(shè)計界面
"use client";

import { ProChat } from "@ant-design/pro-chat";
import { useTheme } from "antd-style";

export default function Home() {
  const theme = useTheme();
  return (
    <div
      style={{
        backgroundColor: theme.colorBgLayout,
      }}
    >
      <ProChat
        style={{
          height: "100vh",
          width: "100vw",
        }}
        request={async (messages: Array<any>) => {
          const response = await fetch("/api/openai", {
            method: "POST",
            body: JSON.stringify({ messages: messages }),
          });

          return response;
        }}
      />
    </div>
  );
}

是不是很簡單, 3步就能幫你搭建一個AI聊天應(yīng)用, 大家感興趣的可以嘗試使用一下。

Github 地址:https://github.com/ant-design/pro-chat

文檔地址:https://pro-chat.antdigital.dev/

責任編輯:武曉燕 來源: 趣談前端
相關(guān)推薦

2014-05-19 10:55:12

Web組件Web Compone

2023-12-04 16:22:38

2010-05-22 11:21:51

綠色智能城市信息化建設(shè)華為

2010-11-09 12:10:20

瞻博網(wǎng)絡(luò)網(wǎng)絡(luò)構(gòu)架Juniper

2013-05-21 10:26:47

存儲網(wǎng)絡(luò)以太網(wǎng)虛擬化

2016-03-28 15:23:07

網(wǎng)絡(luò)服務(wù)器虛擬化

2022-08-24 16:29:10

物聯(lián)網(wǎng)

2020-11-24 10:21:14

人工智能機器學(xué)習(xí)技術(shù)

2023-05-05 14:08:48

物聯(lián)網(wǎng)IOT

2015-06-30 14:41:24

平安校園華為

2021-03-09 16:32:12

人工智能科學(xué)教育

2022-09-28 09:21:15

PingCAPTiDBHTAP

2017-12-19 08:48:06

企業(yè)儲存預(yù)測

2022-02-12 12:18:59

Delta Chat聊天應(yīng)用開源

2018-09-19 09:05:54

Linux桌面開源

2024-08-16 08:31:05

2021-07-23 16:50:19

httpJava框架

2014-03-07 14:35:49

網(wǎng)絡(luò)基礎(chǔ)設(shè)施Open Fabric

2025-01-08 09:01:47

2020-09-30 18:00:48

JavaSpring BootIM
點贊
收藏

51CTO技術(shù)棧公眾號