Skip to content

Commit ea90941

Browse files
committed
add helper buttons for rag instructioning
1 parent e6b9488 commit ea90941

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

src/client/components/Prompt/PromptEditor.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const PromptEditor = ({ prompt, ragIndices, type, chatInstanceId, setEdit
4141
const [name, setName] = useState<string>(prompt?.name ?? '')
4242
const [systemMessage, setSystemMessage] = useState<string>(prompt?.systemMessage ?? '')
4343
const [ragSystemMessage, setRagSystemMessage] = useState<string>(() =>
44-
prompt ? prompt.messages?.find((m) => m.role === 'system')?.content || '' : DEFAULT_RAG_SYSTEM_MESSAGE,
44+
prompt ? prompt.messages?.find((m) => m.role === 'system')?.content || '' : t(DEFAULT_RAG_SYSTEM_MESSAGE),
4545
)
4646
const [hidden, setHidden] = useState<boolean>(prompt?.hidden ?? false)
4747
const [mandatory, setMandatory] = useState<boolean>(prompt?.mandatory ?? false)
@@ -194,19 +194,18 @@ export const PromptEditor = ({ prompt, ragIndices, type, chatInstanceId, setEdit
194194
</FormControl>
195195
<Collapse in={!!ragIndexId}>
196196
<OpenableTextfield
197+
value={ragSystemMessage}
198+
onChange={(e) => setRagSystemMessage(e.target.value)}
199+
onAppend={(text) => setRagSystemMessage(prev => prev + (prev.trim().length ? ' ' : '') + text)}
197200
slotProps={{
198-
htmlInput: {
199-
'data-testid': 'rag-system-message-input',
200-
},
201+
htmlInput: { 'data-testid': 'rag-system-message-input' },
201202
}}
202203
label={t('prompt:ragSystemMessage')}
203-
value={ragSystemMessage}
204-
onChange={(e) => setRagSystemMessage(e.target.value)}
205204
fullWidth
206205
margin="normal"
207206
multiline
208-
minRows={3}
209-
maxRows={18}
207+
minRows={2}
208+
maxRows={12}
210209
/>
211210
</Collapse>
212211
<TextField
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
import { Accordion, AccordionDetails, AccordionSummary, Button, TextField, TextFieldProps } from '@mui/material'
1+
import { Accordion, AccordionDetails, AccordionSummary, Box, TextField, TextFieldProps } from '@mui/material'
2+
import { DEFAULT_RAG_SYSTEM_MESSAGE, ENFORCE_RAG_SYSTEM_MESSAGE, UNKNOWN_RAG_SYSTEM_MESSAGE } from '@config'
3+
import { GrayButton } from '../ChatV2/general/Buttons'
4+
import AddIcon from '@mui/icons-material/Add';
5+
import { t } from 'i18next';
6+
7+
type OpenableTextfieldProps = TextFieldProps & {
8+
onAppend: (text: string) => void
9+
}
10+
11+
const OpenableTextfield = ({ onAppend, ...props }: OpenableTextfieldProps) => {
212

3-
const OpenableTextfield = (props: TextFieldProps) => {
413
return (
5-
<Accordion>
6-
<AccordionSummary>{props.label}</AccordionSummary>
7-
<AccordionDetails>
8-
<TextField {...props} />
9-
</AccordionDetails>
10-
</Accordion>
14+
<Box sx={{ mb: 2 }}>
15+
<TextField sx={{ mb: 0 }} {...props} fullWidth />
16+
<Box sx={{ display: 'flex', gap: 1, mt: 1, width: '100%' }}>
17+
<GrayButton size="small" endIcon={<AddIcon />} onClick={() => onAppend(t(DEFAULT_RAG_SYSTEM_MESSAGE))}>
18+
{t("prompt:defaultRagLabel")}
19+
</GrayButton>
20+
<GrayButton size="small" endIcon={<AddIcon />} onClick={() => onAppend(t(ENFORCE_RAG_SYSTEM_MESSAGE))}>
21+
{t("prompt:enforceRagLabel")}
22+
</GrayButton>
23+
<GrayButton size="small" endIcon={<AddIcon />} onClick={() => onAppend(t(UNKNOWN_RAG_SYSTEM_MESSAGE))}>
24+
{t("prompt:unknownRagLabel")}
25+
</GrayButton>
26+
</Box>
27+
</Box>
1128
)
1229
}
1330

14-
export default OpenableTextfield
31+
32+
export default OpenableTextfield

src/client/locales/en.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,19 @@
309309
"createdPrompt": "Prompt \"{{name}}\" created",
310310
"updatedPrompt": "Prompt \"{{name}}\" updated",
311311
"modelFreeToChoose": "Model free to choose",
312-
"systemMessage": "Instructions",
312+
"systemMessage": "Instructions for the language model",
313313
"hidePrompt": "Hide prompt text from students",
314314
"editMandatoryPrompt": "Make prompt mandatory",
315315
"noSourceMaterials": "No source materials",
316316
"ragSystemMessage": "Source material instructions",
317317
"basicInformation": "Basic information",
318-
"context": "Context"
318+
"context": "Context",
319+
"defaultRagLabel": "use sources",
320+
"enforceRagLabel": "must use sources",
321+
"unknownRagLabel": "say if not found",
322+
"defaultRagMessage": "You now have source materials available. Use them when the user asks a question.",
323+
"enforceRagMessage": "You must use the sources to answer. Do not invent information.",
324+
"unknownRagMessage": "If the answer is not in the sources, say so."
319325
},
320326
"tooltip": {
321327
"copied": "Copied!"

src/client/locales/fi.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,19 @@
311311
"createdPrompt": "Alustus \"{{name}}\" luotu",
312312
"updatedPrompt": "Alustus \"{{name}}\" muokattu",
313313
"modelFreeToChoose": "Malli vapaasti valittavissa",
314-
"systemMessage": "Ohjeistus",
314+
"systemMessage": "Kielimallin ohjeistus",
315315
"hidePrompt": "Piilota alustuksen sisältö opiskelijoilta",
316316
"editMandatoryPrompt": "Tee alustuksesta pakollinen",
317317
"noSourceMaterials": "Ei lähdemateriaaleja",
318318
"ragSystemMessage": "Lähdemateriaaliohjeistus",
319319
"basicInformation": "Perustiedot",
320-
"context": "Konteksti"
320+
"context": "Konteksti",
321+
"defaultRagLabel": "käytä lähteitä",
322+
"enforceRagLabel": "pakko käyttää lähteitä",
323+
"unknownRagLabel": "kerro jos ei löydy",
324+
"defaultRagMessage": "Sinulla on nyt lähdemateriaalit käytössä. Hyödynnä niitä, kun käyttäjä kysyy jotain.",
325+
"enforceRagMessage": "Sinun täytyy käyttää lähteitä vastauksessa. Älä keksi tietoa.",
326+
"unknownRagMessage": "Jos vastausta ei löydy lähteistä, kerro se."
321327
},
322328
"tooltip": {
323329
"copied": "Kopioitu!"

src/client/locales/sv.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,19 @@
291291
"createdPrompt": "Prompt \"{{name}}\" skapad",
292292
"updatedPrompt": "Prompt \"{{name}}\" uppdaterad",
293293
"modelFreeToChoose": "Modell fri att välja",
294-
"systemMessage": "Instruktioner",
294+
"systemMessage": "Instruktioner för språkmodellen",
295295
"hidePrompt": "Dölj prompttext för studenter",
296296
"editMandatoryPrompt": "Gör prompt obligatorisk",
297297
"noSourceMaterials": "Inga källmaterial",
298298
"ragSystemMessage": "Instruktioner för källmaterial",
299299
"basicInformation": "Grundläggande information",
300-
"context": "Sammanhang"
300+
"context": "Sammanhang",
301+
"defaultRagLabel": "använd källor",
302+
"enforceRagLabel": "måste använda källor",
303+
"unknownRagLabel": "säg om inte hittas",
304+
"defaultRagMessage": "Du har nu källmaterial tillgängligt. Använd det när användaren ställer en fråga.",
305+
"enforceRagMessage": "Du måste använda källorna för att svara. Hitta inte på information.",
306+
"unknownRagMessage": "Om svaret inte finns i källorna, säg det."
301307
},
302308
"tooltip": {
303309
"copied": "Kopierad!"

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ Put math in $$ ... $$ for LaTeX rendering.
2828
Wrap code in triple backticks with the correct language tag (js, ts, py, etc.) so syntax highlighting and rendering work.
2929
`
3030

31-
export const DEFAULT_RAG_SYSTEM_MESSAGE = `Use the document_search tool to find information in the provided source materials to answer the user's question.`
31+
// EXAMPLE: with localize translation -> t(DEFAULT_RAG_SYSTEM_MESSAGE)
32+
export const DEFAULT_RAG_SYSTEM_MESSAGE = 'prompt:defaultRagMessage'
33+
export const ENFORCE_RAG_SYSTEM_MESSAGE = 'prompt:enforceRagMessage'
34+
export const UNKNOWN_RAG_SYSTEM_MESSAGE = 'prompt:unknownRagMessage'
3235

3336
/**
3437
* name: the acual model name, which is shown to users, configures the model to be used and is also the azure deployment name.

0 commit comments

Comments
 (0)