超级自定义回放聊天包
一个高度自定义, 表演, 和智能反应聊天器组件。 丢入任何项目,以添加一个强大的对话AI接口,由 谷歌双子座,OpenAI,Anthropic(克洛德)和格罗克。 。 。 .
QQ 演示预览
此聊天机在您的 React app 中
此演示演示 :
- 反应中的无缝集成
- 清洁模式和部件视图
- 用自定义主题打入动画
- 使用OpenAI/Gemini/克洛德/格洛克API
* 特性
- 🤖 多API 支持:与谷歌双子座,OpenAI,Anthropic(克洛德)和Groq直接融合.
- 🧠 自定义指令:提供一种系统提示来定义机器人的个性a,角色和规则.
- 🚀 模式选择: 从任何支持的提供者中选择您想要使用的精确的AI模型(例如,
gemini-1.5-flash, (中文(简体) ),gpt-4o-mini, (中文(简体) ),claude-3-haiku, (中文(简体) ),llama3-8b-8192) (中文(简体) ). - 🎨 深度自定义: 使用一个全面
theme对象以控制每个颜色、字体、边框和大小. - 🎬 打字动画:让用户以平滑,逐个字符的打字动画进行博特响应.
- 🗣️ 语音文本( 可选) ——使用浏览器的"Web Speech API"构建语音输入,用于无手互动.
- 📎 文件上传( 可选): 允许用户上传图像和文件,以便用相容模型进行多模式对话(Gemini, GBT-4o, Claude 3).
- 🧩 灵活安置: 显示为经典的角部件或大型、有重点的模式.
- 💅 标记下渲染:自动制作列表,粗体/斜体文本,页眉等.
- 💪 受控模式( U):将其用作简单的插件和游戏组件或完全控制其状态.
- ♿ 可访问:设计时考虑到无障碍性,包括焦点管理和ARIA属性.
* 安装
安装来自国家预防机制的软件包及其核心同行依赖.
npm install @gauravrathod674/super-customizable-chatbot @fortawesome/react-fontawesome @fortawesome/free-solid-svg-icons @fortawesome/fontawesome-svg-core framer-motion react-markdown
AI 供应商 SDKs
您还需要为您想要使用的特定AI提供者安装 SDK 。 你只需要安装你打算使用的.
# For Google Gemini
npm install @google/generative-ai
# For OpenAI
npm install openai
# For Anthropic (Claude)
npm install @anthropic-ai/sdk
# For Groq
npm install groq-sdk
使用量
导入组件及其样式表,然后用适当的 API 密钥将其制成 .
示例:谷歌双子座
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function App() {
const GEMINI_API_KEY = "YOUR_GEMINI_API_KEY";
return (
<ChatBot
botName="Gemini Bot"
geminiApiKey={GEMINI_API_KEY}
geminiModelName="gemini-1.5-flash"
welcomeMessage="I am powered by Gemini. How can I help?"
/>
);
}
示例: OpenAI
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function App() {
const OPENAI_API_KEY = "YOUR_OPENAI_API_KEY";
return (
<ChatBot
botName="OpenAI Bot"
openaiApiKey={OPENAI_API_KEY}
openaiModelName="gpt-4o-mini"
welcomeMessage="I am powered by OpenAI. How can I help?"
/>
);
}
示例: Athropic (克洛德语)
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function App() {
const ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY";
return (
<ChatBot
botName="Claude Bot"
anthropicApiKey={ANTHROPIC_API_KEY}
anthropicModelName="claude-3-haiku-20240307"
welcomeMessage="I am powered by Claude. How can I help?"
/>
);
}
示例:格罗克
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function App() {
const GROQ_API_KEY = "YOUR_GROQ_API_KEY";
return (
<ChatBot
botName="Groq Bot"
grokApiKey={GROQ_API_KEY}
grokModelName="llama3-8b-8192"
welcomeMessage="I am powered by Groq. I am very fast. How can I help?"
/>
);
}
示例:对文本和文件上传的语音
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function App() {
const GEMINI_API_KEY = "YOUR_GEMINI_API_KEY";
return (
<ChatBot
botName="Gemini Bot"
geminiApiKey={GEMINI_API_KEY}
geminiModelName="gemini-1.5-flash"
enableMicrophone="enabled"
enableFileUpload={true}
fileUploadAccept="image/*,.pdf,.doc,.docx"
welcomeMessage="I am powered by Gemini. How can I help?"
/>
);
}
QQ 自定义指令( 系统提示)
为大赦国际界定一人或一套规则,使用: customInstruction 道具 (英语). 聊天人会在整个谈话中遵守这个指示.
<ChatBot
botName="Pirate Bot"
openaiApiKey="YOUR_OPENAI_API_KEY"
customInstruction="You are a helpful assistant who speaks like a pirate. Keep your answers brief and witty."
welcomeMessage="Ahoy there, matey! What be yer question?"
/>
QQ 主题和自定义
该组件的最大力量是它的自定义性. 您可以通过通过 : theme 对象.
示例: 打入动画自定义( C) 主题
这个例子创造了一个大型的,以为中心,背景模糊的聊天员,独特的色彩方案,以及新的打字动画.
import React from 'react';
import ChatBot from '@gauravrathod674/super-customizable-chatbot';
import '@gauravrathod674/super-customizable-chatbot/dist/style.css';
function ChatPage() {
const corporateTheme = {
header: { backgroundColor: '#1e3a8a' },
messages: {
userBackgroundColor: '#2563eb',
botBackgroundColor: '#eef2ff',
botTextColor: '#1e3a8a',
animation: 'typing', // <-- Enable the typing animation
},
window: {
placement: 'center',
backdrop: true,
backdropBlur: '3px',
},
input: { focusRingColor: '#2563eb' },
launcher: { backgroundColor: '#1e3a8a' },
};
return (
<ChatBot
botName="CorpBot"
openaiApiKey="YOUR_OPENAI_API_KEY"
theme={corporateTheme}
/>
);
}
API 参考
可通过两种主要途径: props 对行为和a theme 显示对象.
组件道具
这些道具控制了聊天器的功能,身份,和AI的集成.
| Prop | 类型 | 默认 | 说明 |
|---|---|---|---|
geminiApiKey | string | undefined | 您的谷歌双子座 API 密钥 . |
openaiApiKey | string | undefined | 您的 OpenAI API 密钥 . |
anthropicApiKey | string | undefined | 您的 Anthropic (Claude) API 密钥 . |
grokApiKey | string | undefined | 你的Groq API钥匙. |
geminiModelName | string | 'gemini-1.5-flash' | 要使用的双子座模型. |
openaiModelName | string | 'gpt-4o-mini' | 要使用的OpenAI模型. |
anthropicModelName | string | 'claude-3-haiku-20240307' | 要使用的Anthropic模型. |
grokModelName | string | 'llama3-8b-8192' | 要使用的格罗克模型. |
customInstruction | string | '' | 一个系统提示来定义机器人的个性或行为. |
enableMicrophone | string | undefined | 任何启用 Speech-to-Text 麦克风的真伪字符串 。 不需要实际全权证书. |
enableFileUpload | boolean | false | 启用文件附件按钮. |
fileUploadAccept | string | * | 用于上传对话框(例如, "image/*, .pdf") (中文(简体) ). |
onFileUpload | (file: File) => void | () => {} | ** 回击当用户选择文件时点火. |
botName | string | 'ChatBot' | 标题中显示的名称 . |
welcomeMessage | string | 'Hello! How can I help?' | 机器人显示的初始消息 . |
placeholderText | string | 'Type a message...' | 输入字段中的占位符文本. |
botAvatar | React.ReactNode | <DefaultBotIcon /> | 机器人外观的图标或图像 URL . |
userAvatar | React.ReactNode | <DefaultUserIcon /> | 用户外观的图标或图像 URL . |
isOpen | boolean | false | 控制聊天窗口是否初始打开 . |
disabled | boolean | false | 禁用输入字段并发送按钮. |
onSend | (message: string) => void | () => {} | 用户发送消息时回电 . |
theme | object | {} | 自定义 UI 的主题对象 。 见下表. |
messages | Array<{id, text, sender}> | undefined | 高级 : 受控信件对象数组 . |
isTyping | boolean | false | 高级 : 手动控制了机器人的打字指示器. |
主题选项( E)theme 对象)
传出 a theme 对象为自定义聊天人的外观。 不提供的任何财产都将回落到其默认值.
启动按钮
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
launcher.backgroundColor | string | '#4f46e5' | 发射器按钮的背景颜色 . |
launcher.iconColor | string | '#ffffff' | 发射器内部图标的颜色. |
launcher.size | string | '3.5rem' | 发射装置按钮的宽度和高度. |
聊天窗口
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
window.placement | string | 'bottom-right' | 显示屏幕位置 。 选项 : 'bottom-right', (中文(简体) ), 'bottom-left', (中文(简体) ), 'center'。 。 。 . |
window.width | string | '22rem' | 聊天窗口的宽度 。 (违约情况) '80vw' 如果放置是 'center') (中文(简体) ). |
window.height | string | '30rem' | 聊天窗口的高度。 (违约情况) '80vh' 如果放置是 'center') (中文(简体) ). |
window.backgroundColor | string | '#ffffff' | 主聊天窗口的背景颜色 . |
window.borderColor | string | '#e5e7eb' | 主聊天窗口的边框颜色 . |
window.borderRadius | string | '0.75rem' | 主聊天窗口的边框半径 . |
window.backdrop | boolean | false | 显示模糊的背景( 仅用于 'center' . 安置问题). |
window.backdropColor | string | 'rgba(0,0,0,0.4)' | 颜色覆盖背景 . |
window.backdropBlur | string | '4px' | CSS 模糊背景值 . |
window.scrollbarThumbColor | string | '#a1a1aa' | 信件列表滚动条缩略图的颜色 . |
window.scrollbarTrackColor | string | '#f1f5f9' | 信件列表滚动栏音轨的颜色 . |
页眉
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
header.backgroundColor | string | '#4f46e5' | 页眉的背景颜色 . |
header.textColor | string | '#ffffff' | 头部为机器人名的文字颜色. |
header.fontFamily | string | 'inherit' | 标题文本的字体家族 . |
header.fontWeight | string | '600' | 头文本的字体重量 . |
信件
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
messages.userBackgroundColor | string | '#4f46e5' | 用户信息泡的背景颜色 . |
messages.userTextColor | string | '#ffffff' | 用户信件的文本颜色 . |
messages.botBackgroundColor | string | '#f3f4f6' | 机器人信息泡的背景颜色 . |
messages.botTextColor | string | '#1f2937' | 机器人消息的文本颜色 . |
messages.fontFamily | string | 'inherit' | 所有信件文本的字体家族 . |
messages.fontSize | string | '0.9rem' | 所有信件文本的字体大小 . |
messages.showAvatars | boolean | true | 是否在信件旁边显示相机 . |
messages.bubbleShape | string | 'rounded' | 发相相相相相相相相. 选项 : 'rounded', (中文(简体) ), 'square'。 。 。 . |
messages.bubblePointer | boolean | true | 在信息泡上显示一个小指针. |
messages.animation | string | 'fade-in' | 瓶子反应动画. 选项 : 'fade-in', (中文(简体) ), 'typing', (中文(简体) ), 'slide-up', (中文(简体) ), 'zoom-in', (中文(简体) ), 'flip', (中文(简体) ), 'none'。 。 。 . |
标记下自定义( M)messages.markdownStyles(中文(简体) )
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
markdownStyles.boldColor | string | inherit | 颜色 **bold** 语句. |
markdownStyles.italicColor | string | inherit | 颜色 *italic* 语句. |
markdownStyles.linkColor | string | '#3b82f6' | 颜色 [links](...)。 。 。 . |
markdownStyles.codeColor | string | inherit | 文字颜色 inline code。 。 。 . |
markdownStyles.codeBackgroundColor | string | rgba(0,0,0,0.1) | 背景颜色 inline code。 。 。 . |
输入区域
| 路径 | 类型 | 默认 | 说明 |
|---|---|---|---|
input.backgroundColor | string | '#ffffff' | 输入页脚区域的背景颜色. |
input.textColor | string | '#1f2937' | 用户输入的文本颜色 . |
input.placeholderTextColor | string | '#9ca3af' | 占位符文本的颜色 . |
input.borderColor | string | '#e5e7eb' | 文本输入字段的边框颜色 . |
input.focusRingColor | string | '#4f46e5' | 选择输入时焦点环的颜色. |
许可证
这个项目根据麻省理工学院的许可证获得许可.
