Skip to content

Commit fec1e4f

Browse files
Votre NomVotre Nom
Votre Nom
authored and
Votre Nom
committed
merge master
2 parents 27276ce + 5e40b3e commit fec1e4f

File tree

7 files changed

+97
-14
lines changed

7 files changed

+97
-14
lines changed

examples/server/public/index.html.gz

-5.15 KB
Binary file not shown.

examples/server/webui/public/prompts.config.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@
2929
"top_p": 0.95,
3030
"typical_p": 1,
3131
"xtc_probability": 0,
32-
"xtc_threshold": 0.1
33-
}
32+
"xtc_threshold": 0.1,
33+
"questionIdeas": [
34+
"Who are you, what can you do?",
35+
"What to do, what to see, what to visit in Italy?",
36+
"Write a simple python function that\n1. Ask me for a number in mile\n2. It converts miles to kilometers"
37+
]
38+
},
39+
"for_devs": "TRUE"
3440
},
3541
{
3642
"name": "Ethereum Developer",

examples/server/webui/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const CONFIG_DEFAULT = {
3939
custom: '', // custom json-stringified object
4040
// experimental features
4141
pyIntepreterEnabled: false,
42+
questionIdeas: [],
4243
};
4344
export const CONFIG_INFO: Record<string, string> = {
4445
apiKey: 'Set the API Key if you are using --api-key option for the server.',
@@ -79,6 +80,7 @@ export const CONFIG_INFO: Record<string, string> = {
7980
'DRY sampling reduces repetition in generated text even across long contexts. This parameter sets DRY penalty for the last n tokens.',
8081
max_tokens: 'The maximum number of token per output.',
8182
custom: '', // custom json-stringified object
83+
questionIdeas: 'Ideas of prompt showed when you start a new conversation.',
8284
};
8385
// config keys having numeric value (i.e. temperature, top_k, top_p, etc)
8486
export const CONFIG_NUMERIC_KEYS = Object.entries(CONFIG_DEFAULT)

examples/server/webui/src/components/ChatScreen.tsx

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const scrollToBottom = throttle(
7070
},
7171
80
7272
);
73-
7473
export default function ChatScreen() {
7574
const {
7675
viewingChat,
@@ -82,7 +81,9 @@ export default function ChatScreen() {
8281
replaceMessageAndGenerate,
8382
} = useAppContext();
8483
const [inputMsg, setInputMsg] = useState('');
84+
const [automaticSend, setAutomaticSend] = useState(false);
8585
const inputRef = useRef<HTMLTextAreaElement>(null);
86+
const { config } = useAppContext();
8687

8788
const { extraContext, clearExtraContext } = useVSCodeContext(
8889
inputRef,
@@ -139,6 +140,40 @@ export default function ChatScreen() {
139140
// OK
140141
clearExtraContext();
141142
};
143+
useEffect(() => {
144+
const sendMsg = async () => {
145+
if (inputMsg.trim().length === 0) return;
146+
const lastInpMsg = inputMsg;
147+
setInputMsg('');
148+
scrollToBottom(false);
149+
setCurrNodeId(-1);
150+
// get the last message node
151+
const lastMsgNodeId = messages.at(-1)?.msg.id ?? null;
152+
if (
153+
!(await sendMessage(
154+
currConvId,
155+
lastMsgNodeId,
156+
inputMsg,
157+
undefined,
158+
onChunk
159+
))
160+
) {
161+
setInputMsg(lastInpMsg);
162+
}
163+
};
164+
if (automaticSend) {
165+
setAutomaticSend(false);
166+
sendMsg();
167+
}
168+
}, [
169+
automaticSend,
170+
clearExtraContext,
171+
currConvId,
172+
inputMsg,
173+
isGenerating,
174+
messages,
175+
sendMessage,
176+
]);
142177

143178
const handleEditMessage = async (msg: Message, content: string) => {
144179
if (!viewingChat) return;
@@ -202,10 +237,36 @@ export default function ChatScreen() {
202237
>
203238
{/* chat messages */}
204239
<div id="messages-list" className="grow">
205-
<div className="mt-auto flex justify-center">
206-
{/* placeholder to shift the message to the bottom */}
207-
{viewingChat ? '' : 'Send a message to start'}
208-
</div>
240+
{/* placeholder to shift the message to the bottom */}
241+
{viewingChat ? (
242+
''
243+
) : (
244+
<div className="flex items-center text-center sm:text-left align-middle h-full mx-auto">
245+
{config.questionIdeas.length > 0 ? (
246+
<div className="w-full text-center">
247+
<div className="">Here are some suggestions for you:</div>
248+
<div className="grid grid-cols-1 sm:grid-cols-3">
249+
{[...config.questionIdeas].map((idea: string, index) => (
250+
<button
251+
key={index}
252+
style={{ whiteSpace: 'pre-wrap' }}
253+
className="btn m-2 sd:m-4 sd:p-2"
254+
onClick={() => {
255+
setInputMsg(idea);
256+
setAutomaticSend(true);
257+
}}
258+
>
259+
{idea}
260+
</button>
261+
))}
262+
</div>
263+
<div className="">Send a message to start</div>
264+
</div>
265+
) : (
266+
<div className="">Send a message to start</div>
267+
)}
268+
</div>
269+
)}
209270
{[...messages, ...pendingMsgDisplay].map((msg) => (
210271
<ChatMessage
211272
key={msg.msg.id}

examples/server/webui/src/components/Header.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export default function Header() {
2121
const [selectedTheme, setSelectedTheme] = useState(StorageUtils.getTheme());
2222
const { setShowSettings } = useAppContext();
2323
const [selectedConfig, setSelectedConfig] = useState<number>(-1);
24+
const handleClick = () => {
25+
const elem = document.activeElement;
26+
if (elem) {
27+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
28+
// @ts-expect-error
29+
elem?.blur();
30+
}
31+
};
2432

2533
const setTheme = (theme: string) => {
2634
StorageUtils.setTheme(theme);
@@ -237,6 +245,16 @@ export default function Header() {
237245
tabIndex={0}
238246
className="dropdown-content bg-base-300 rounded-box z-[1] w-52 p-2 shadow-2xl h-80 overflow-y-auto"
239247
>
248+
<li>
249+
<input
250+
type="radio"
251+
name="settings"
252+
className="theme-controller btn btn-sm btn-block btn-ghost justify-start"
253+
aria-label="Manual settings"
254+
value="Manual settings"
255+
onChange={() => setShowSettings(true)}
256+
/>
257+
</li>
240258
{[...promptSelectOptions].map((opt) => (
241259
<li key={opt.key}>
242260
<input
@@ -249,6 +267,7 @@ export default function Header() {
249267
onChange={(e) =>
250268
e.target.checked && selectPrompt(opt.key)
251269
}
270+
onClick={handleClick}
252271
/>
253272
</li>
254273
))}

examples/server/webui/src/components/SettingDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface SettingFieldCustom {
6161
component:
6262
| string
6363
| React.FC<{
64-
value: string | boolean | number;
64+
value: string | boolean | number | never[] | string[];
6565
onChange: (value: string) => void;
6666
}>;
6767
}

examples/server/webui/src/components/Sidebar.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ export default function Sidebar() {
2828

2929
return (
3030
<>
31-
<input
32-
id="toggle-drawer"
33-
type="checkbox"
34-
className="drawer-toggle"
35-
defaultChecked
36-
/>
31+
<input id="toggle-drawer" type="checkbox" className="drawer-toggle" />
3732

3833
<div className="drawer-side h-screen lg:h-screen z-50 lg:max-w-64">
3934
<label

0 commit comments

Comments
 (0)