Skip to content

Commit

Permalink
Improve chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Aug 27, 2024
1 parent 1dadf20 commit 89d3cee
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/ChatBlock/ChatBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import withDanswerData from './withDanswerData';
const SearchBlockEdit = (props) => {
const { onChangeBlock, block, assistants } = props;

const schema = React.useMemo(
() => ChatBlockSchema({ assistants }),
[assistants],
);
const schema = React.useMemo(() => ChatBlockSchema({ assistants }), [
assistants,
]);

console.log('data', props.data);

return (
<div>
Expand Down
11 changes: 5 additions & 6 deletions src/ChatBlock/ChatBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import ChatWindow from './ChatWindow';
import superagent from 'superagent';

function ChatBlockView(props) {
const { assistantData } = props;
const { assistantData, data } = props;

return assistantData ? (
<div>
<div>
<ChatWindow persona={assistantData} />
</div>
</div>
<ChatWindow
persona={assistantData}
placeholderPrompt={data.placeholderPrompt}
/>
) : (
<div>Chatbot</div>
);
Expand Down
9 changes: 7 additions & 2 deletions src/ChatBlock/ChatWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import SendIcon from './../icons/send.svg';

import './style.less';

function ChatWindow({ persona, rehypePrism, remarkGfm }) {
function ChatWindow({
persona,
rehypePrism,
remarkGfm,
placeholderPrompt = 'Ask a question',
}) {
const libs = { rehypePrism, remarkGfm }; // rehypePrism, remarkGfm
const { onSubmit, messages, isStreaming, clearChat } = useBackendChat({
persona,
Expand Down Expand Up @@ -91,7 +96,7 @@ function ChatWindow({ persona, rehypePrism, remarkGfm }) {
ref={textareaRef}
value={input}
placeholder={
messages.length > 0 ? 'Ask follow-up...' : 'Placeholder text'
messages.length > 0 ? 'Ask follow-up...' : placeholderPrompt
}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => {
Expand Down
6 changes: 5 additions & 1 deletion src/ChatBlock/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ export function ChatBlockSchema({ assistants }) {
{
id: 'default',
title: 'Defalt',
fields: ['assistant'],
fields: ['assistant', 'placeholderPrompt'],
},
],
properties: {
assistant: {
title: 'Assistant',
choices: assistants?.map(({ id, name }) => [id.toString(), name]),
},
placeholderPrompt: {
default: 'Ask a question',
title: 'Prompt',
},
},
required: [],
};
Expand Down
19 changes: 18 additions & 1 deletion src/ChatBlock/withDanswerData.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import React from 'react';
import {
PlaceholderParagraph,
PlaceholderLine,
PlaceholderHeader,
Placeholder,
} from 'semantic-ui-react';

const Loader = () => (
<Placeholder>
<PlaceholderParagraph>
<PlaceholderLine />
<PlaceholderLine />
<PlaceholderLine />
<PlaceholderLine />
</PlaceholderParagraph>
</Placeholder>
);

export default function withDanswerData(callback) {
function wrapper(Component) {
Expand All @@ -21,7 +38,7 @@ export default function withDanswerData(callback) {
return state ? (
<Component {...props} {...state} />
) : (
<div>Fetching external data...</div>
<Loader active={true} />
);
}
return WrappedComponent;
Expand Down

0 comments on commit 89d3cee

Please sign in to comment.