@smarter.sh/ui-chat 0.0.1
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/LICENSE +671 -0
- package/README.md +143 -0
- package/dist/smarter-chat-library.es.js +28850 -0
- package/dist/smarter-chat-library.es.js.map +1 -0
- package/dist/smarter-chat-library.umd.js +807 -0
- package/dist/smarter-chat-library.umd.js.map +1 -0
- package/dist/ui-chat.css +1 -0
- package/package.json +91 -0
- package/src/components/ErrorModal/ErrorModal.css +35 -0
- package/src/components/ErrorModal/ErrorModal.jsx +56 -0
- package/src/components/ErrorModal/index.js +3 -0
- package/src/components/SmarterChat/ErrorBoundary.jsx +32 -0
- package/src/components/SmarterChat/SmarterChat.jsx +419 -0
- package/src/components/SmarterChat/api.js +233 -0
- package/src/components/SmarterChat/enums.js +17 -0
- package/src/components/SmarterChat/index.js +3 -0
- package/src/components/SmarterChat/styles.css +148 -0
- package/src/components/SmarterChat/utils.jsx +158 -0
- package/src/components/enums.js +1 -0
- package/src/components/index.js +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
[](https://github.com/smarter-sh/smarter-chat/)
|
|
2
|
+
[](https://github.com/smarter-sh/smarter-chat/)
|
|
3
|
+
<a href="https://smarter.sh">
|
|
4
|
+
<img src="https://img.shields.io/badge/Smarter.sh-orange?style=flat&logo=appveyor&logoColor=white" height="32">
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
# SmarterChat React.js component for smarter.sh
|
|
8
|
+
|
|
9
|
+
This project contains the source code for the interactive chatbot found in the Smarter web console [developer workbench](https://platform.smarter.sh/chatbots/example/). It integrates natively with Smarter Saas and on-premise installations. You can optionally enable the meta data output behavior found in the Smarter sandbox. See [Smarter Technical Overview](./doc/README.md)
|
|
10
|
+
|
|
11
|
+
This project is also suitable for all front-end cross-platform projects. For example, use this code base to create a react.js run-time for use inside of Wordpress plugins, salesforce.com apps, .net components and Sharepoint add-ins.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```console
|
|
18
|
+
npm install @smarter.sh/ui-chat
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
import React from "react";
|
|
23
|
+
import ReactDOM from "react-dom/client";
|
|
24
|
+
import { SmarterChat } from "@smarter.sh/ui-chat";
|
|
25
|
+
|
|
26
|
+
const DEFAULT_COOKIE_EXPIRATION = 1000 * 60 * 60 * 24 * 1; // 1 day
|
|
27
|
+
const rootElement = document.getElementById("root");
|
|
28
|
+
const root = ReactDOM.createRoot(rootElement);
|
|
29
|
+
root.render(
|
|
30
|
+
<SmarterChat
|
|
31
|
+
apiUrl={"https://smarter.3141-5926-5359.api.smarter.sh/"}
|
|
32
|
+
toggleMetadata={false}
|
|
33
|
+
csrfCookieName={"csrftoken"}
|
|
34
|
+
debugCookieName={"debug"}
|
|
35
|
+
debugCookieExpiration={DEFAULT_COOKIE_EXPIRATION}
|
|
36
|
+
sessionCookieName={"session_key"}
|
|
37
|
+
sessionCookieExpiration={DEFAULT_COOKIE_EXPIRATION}
|
|
38
|
+
/>,
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Developers
|
|
43
|
+
|
|
44
|
+
SmarterChat is created with [React](https://react.dev/) leveraging [@chatscope/chat-ui-kit-react](https://www.npmjs.com/package/@chatscope/chat-ui-kit-react)
|
|
45
|
+
|
|
46
|
+
### Backend integration
|
|
47
|
+
|
|
48
|
+
See [Getting Started with the Smarter Chatbot Api](./doc/CHATBOT_API.md)
|
|
49
|
+
This app interacts with two endpoints from the [smarter.sh/v1](https://platform.smarter.sh/docs/api/) chatbot api:
|
|
50
|
+
|
|
51
|
+
- GET `/config/`: retrieves a json dict, structured in 4 major sections, with all information required by the react app.
|
|
52
|
+
- POST `/chat/`: send a text completion prompt to the Smarter Api.
|
|
53
|
+
|
|
54
|
+
Smarter chatbot urls use either of these two naming conventions:
|
|
55
|
+
|
|
56
|
+
- public: `https://<name>.<account_number>.example.com/`
|
|
57
|
+
- authenticated: `https://platform.smarter.sh/chatbots/<name>/`. This react component looks for and adds the Smarter platform sessionid cookie value to request headers, if it exists.
|
|
58
|
+
|
|
59
|
+
Public api url example for a deployed chatbot:
|
|
60
|
+
|
|
61
|
+
- `https://my-chatbot.3141-5926-5359.api.smarter.sh/config/`
|
|
62
|
+
- `https://my-chatbot.3141-5926-5359.api.smarter.sh/chat/`
|
|
63
|
+
|
|
64
|
+
Authenticated api url example for any chatbot in your Smarter account:
|
|
65
|
+
|
|
66
|
+
- `https://platform.smarter.sh/chatbots/my-chatbot/config/`
|
|
67
|
+
- `https://platform.smarter.sh/chatbots/my-chatbot/chat/`
|
|
68
|
+
|
|
69
|
+
#### Config
|
|
70
|
+
|
|
71
|
+
A Json dict containing all configuration data for the chatbot. This is downloaded at run-time when the reactapp is initializing.
|
|
72
|
+
Example: [/chatbots/example/config/?session_key=YOUR-SESSION-KEY](http://localhost:8000/chatbots/example/config/)
|
|
73
|
+
|
|
74
|
+
See: [sample config](./data/sample-config.json)
|
|
75
|
+
|
|
76
|
+
#### Api
|
|
77
|
+
|
|
78
|
+
A REST Api for sending and receiving chat prompt requests. The url comes from the config dict (above): data.chatbot.url_chatbot.
|
|
79
|
+
example: `http://api.smarter.sh/v1/chatbots/smarter/example/`
|
|
80
|
+
|
|
81
|
+
example http request:
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"method": "POST",
|
|
86
|
+
"credentials": "include",
|
|
87
|
+
"mode": "cors",
|
|
88
|
+
"headers": {
|
|
89
|
+
"Accept": "application/json",
|
|
90
|
+
"Content-Type": "application/json",
|
|
91
|
+
"X-CSRFToken": "q9WXqqIhYJMI3ZSBIOE18JMORBMqAHri",
|
|
92
|
+
"Origin": "http://localhost:8000",
|
|
93
|
+
"Cookie": "session_key=a07593ecfaecd24008ca4251096732663ac0213b8cc6bdcce4f4c043276ab0b5; debug=true;"
|
|
94
|
+
},
|
|
95
|
+
"body": "{\"session_key\":\"a07593ecfaecd24008ca4251096732663ac0213b8cc6bdcce4f4c043276ab0b5\",\"messages\":[{\"role\":\"system\",\"content\":\"You are a helpful chatbot."},{\"role\":\"assistant\",\"content\":\"Welcome to the Smarter demo!\"}]}"
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
example http response:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"data": {
|
|
104
|
+
"isBase64Encoded": false,
|
|
105
|
+
"statusCode": 200,
|
|
106
|
+
"headers": {
|
|
107
|
+
"Content-Type": "application/json"
|
|
108
|
+
},
|
|
109
|
+
"body": "{\"id\": \"chatcmpl-AoDpMvoAhf8iSJuEm6pMqkX62HK4G\", \"choices\": [{\"finish_reason\": \"stop\", \"index\": 0, \"logprobs\": null, \"message\": {\"content\": \"Hello! While I'm not your mom, I'm here to help you with any questions or tasks you have. What can I assist you with today?\", \"refusal\": null, \"role\": \"assistant\", \"audio\": null, \"function_call\": null, \"tool_calls\": null}}], \"created\": 1736532916, \"model\": \"gpt-4-turbo-2024-04-09\", \"object\": \"chat.completion\", \"service_tier\": \"default\", \"system_fingerprint\": \"fp_f17929ee92\", \"usage\": {\"completion_tokens\": 33, \"prompt_tokens\": 1122, \"total_tokens\": 1155, \"completion_tokens_details\": {\"accepted_prediction_tokens\": 0, \"audio_tokens\": 0, \"reasoning_tokens\": 0, \"rejected_prediction_tokens\": 0}, \"prompt_tokens_details\": {\"audio_tokens\": 0, \"cached_tokens\": 0}}, \"metadata\": {\"tool_calls\": null, \"model\": \"gpt-4-turbo\", \"temperature\": 0.5, \"max_tokens\": 256, \"input_text\": \"hi mom\"}}"
|
|
110
|
+
},
|
|
111
|
+
"api": "smarter.sh/v1",
|
|
112
|
+
"thing": "Chatbot",
|
|
113
|
+
"metadata": {
|
|
114
|
+
"command": "chat"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Contributor Reference
|
|
120
|
+
|
|
121
|
+
### Getting Started
|
|
122
|
+
|
|
123
|
+
- `make`: prints a full menu of commands to the console.
|
|
124
|
+
- `make init`: Setup your environment for first time use. sets up your Node environment for you. initializes pre-commit, which you need to run prior to creating pull requests.
|
|
125
|
+
- `make run`: Run the dev server locally
|
|
126
|
+
- `make build`: Build the react.js project. saves vite.js output to `./build` in the root of this project.
|
|
127
|
+
- `make release`: Deploy the react.js project. **REQUIRES awscli + keypair with sufficient permissions**. Publishes the contents of the `./build` folder to an AWS S3 bucket served by the host defined by the value of `CDN_HOST_BASE_URL` located in shared/constant.js. For example, the react app for the Smarter workbench is initialized and served from these endpoints: a. [index.html](https://cdn.platform.smarter.sh/ui-chat/index.html): the react app build artifacts, and b. [app-loader.js](https://cdn.platform.smarter.sh/ui-chat/app-loader.js): a script to insert the react app build artifacts into the DOM.
|
|
128
|
+
|
|
129
|
+
### Hello world app
|
|
130
|
+
|
|
131
|
+
Note that `make build` also generates a simple '[hello-world.html](https://cdn.platform.smarter.sh/ui-chat/hello-world.html)' app that demonstrates how to integrate Smarter Chat to an existing web page.
|
|
132
|
+
|
|
133
|
+
### Architecture
|
|
134
|
+
|
|
135
|
+
- [Vite](https://vitejs.dev/)
|
|
136
|
+
- [React](https://react.dev/)
|
|
137
|
+
- [Chat UI Kit React](https://www.npmjs.com/package/@chatscope/chat-ui-kit-react)
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
We welcome contributions! There are a variety of ways for you to get involved, regardless of your background. In addition to Pull requests, this project would benefit from contributors focused on documentation and how-to video content creation, testing, community engagement, and stewards to help us to ensure that we comply with evolving standards for the ethical use of AI.
|
|
142
|
+
|
|
143
|
+
You can also contact [Lawrence McDaniel](https://lawrencemcdaniel.com/contact) directly.
|