@nualang/nualang-ui-components 0.1.1157 → 0.1.1159
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/dist/Dialogs/GeneratePhrases/GeneratePhrases.js +34 -5
- package/dist/Dialogs/GenerateRoleplay/GenerateRoleplay.js +44 -6
- package/dist/Editors/Phrases/Phrases.js +4 -2
- package/dist/Editors/Roleplay/Roleplay.js +3 -1
- package/dist/Screens/Classrooms/ViewClassroom/ViewClassroom.js +4 -1
- package/dist/Screens/Courses/ViewCourse/ViewTopic/ViewTopic.js +6 -2
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ var _ResponsiveDialog = _interopRequireDefault(require("../ResponsiveDialog/Resp
|
|
|
9
9
|
var _iconsMaterial = require("@mui/icons-material");
|
|
10
10
|
var _material = require("@mui/material");
|
|
11
11
|
var _reactRouterDom = require("react-router-dom");
|
|
12
|
+
var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
|
|
12
13
|
var _nualas = _interopRequireDefault(require("../../img/nualas.svg"));
|
|
13
14
|
var _InputHelper = _interopRequireDefault(require("../../Forms/InputHelper/InputHelper"));
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -111,7 +112,9 @@ function GeneratePhrases({
|
|
|
111
112
|
try {
|
|
112
113
|
setIsGenerating(true);
|
|
113
114
|
setErrorMessage(null);
|
|
114
|
-
const
|
|
115
|
+
const goalPrompt = `The generated phrases must specifically target the following linguistic goal: '${values.topicGoal}'. Avoid generating phrases that do not align with this goal. `;
|
|
116
|
+
const prompt = phraseType === "sentences" ? isPhrases ? `The context is a language learning application. Here is a list of phrases or sentences in ${learnLang} and their translations in ${forLang}:\n\n${JSON.stringify(phrases)}\n\nNow, generate ${values.phraseAmount} more uniques sentences in ${learnLang} and their translations in ${forLang} on the topic of '${values.phrasesTopic}' in the same JSON format as the ones that I have passed to you. The 'idx' field should contain an index integer which follows on incrementally from the existing phrases. The 'image' field should contain an empty string. Do not include a 'voices' field. ${values.topicGoal.trim() ? goalPrompt : ""}The sentences should be unique and not already in the list. The sentences should be appropriate for ${["en-US"].includes(siteLanguage) ? "ACTFL" : "CEFR"} ${difficulty} level. Ensure the formatting of the JSON response is correct and follows this structure.` : `The context is a language learning application. Generate ${values.phraseAmount} unique phrases or sentences in ${learnLang} and their translations in ${forLang} on the topic of '${values.phrasesTopic}'. Return the sentences inside a JSON array of ${values.phraseAmount} objects, each with the following fields: 'phrase', 'translations', 'idx', and 'image'. Each field is required and cannot be omitted. The 'idx' field represents the index of the phrases, starting from 0 and going up by 1 up until the last phrase. The 'image' field should contain an empty string. The 'translations' field should be an array of at least one translation of the sentence in ${forLang}, but it can contain more translations as long as they are grammatically correct. ${values.topicGoal.trim() ? goalPrompt : ""}The sentences should be appropriate for the ${["en-US"].includes(siteLanguage) ? "ACTFL" : "CEFR"} ${difficulty} level. The sentences should be unique. Ensure the formatting of the JSON response is correct and follows this structure.` : isPhrases ? `The context is a language learning application. Here is a list of words or short lexical phrases in ${learnLang} and their translations in ${forLang}:\n\n${JSON.stringify(phrases)}\n\nNow, generate ${values.phraseAmount} more words or lexical phrases and their translations in ${learnLang} on the topic of '${values.phrasesTopic}' in the same JSON format as the ones that I have passed to you. The 'idx' field should contain an index integer which follows on incrementally from the existing phrases. The 'image' field should contain an empty string. Do not include a 'voices' field. ${values.topicGoal.trim() ? goalPrompt : ""}The words or lexical phrases should be unique and not already in the list. The words or lexical phrases should be ${["en-US"].includes(siteLanguage) ? "ACTFL" : "CEFR"} ${difficulty}. Ensure the formatting of the JSON response is correct and follows this structure.` : `The context is a language learning application. Generate ${values.phraseAmount} unique words or short lexical phrases in ${learnLang} and their translations in ${forLang} on the topic of '${values.phrasesTopic}'. Return the words or short lexical phrases inside a JSON array of ${values.phraseAmount} objects, each with the following fields: 'phrase', 'translations', 'idx', and 'image'. Each field is required and cannot be omitted. The 'idx' field represents the index of the phrases, starting from 0 and going up by 1 up until the last phrase. The 'image' field should contain an empty string. The 'translations' field should be an array of at least one translation of the phrase in ${forLang}, but it can contain more translations as long as they are grammatically correct. ${values.topicGoal.trim() ? goalPrompt : ""}The words or short lexical phrases should be appropriate for the ${["en-US"].includes(siteLanguage) ? "ACTFL" : "CEFR"} ${difficulty} level. The words or short lexical phrases should be unique. Ensure the formatting of the JSON response is correct and follows this structure.`;
|
|
117
|
+
console.log("prompt: ", prompt);
|
|
115
118
|
const chatGptResponse = await makeChatGptApiRequest({
|
|
116
119
|
model: "gpt-3.5-turbo",
|
|
117
120
|
prompt
|
|
@@ -172,16 +175,14 @@ function GeneratePhrases({
|
|
|
172
175
|
}
|
|
173
176
|
}, t("required_field")), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
174
177
|
item: true,
|
|
175
|
-
xs: 12
|
|
176
|
-
mb: 2
|
|
178
|
+
xs: 12
|
|
177
179
|
}, /*#__PURE__*/_react.default.createElement(_material.Alert, {
|
|
178
180
|
severity: "info"
|
|
179
181
|
}, t("experimental_feature_desc_phrases"), " -", " ", /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
|
|
180
182
|
to: "/contact"
|
|
181
183
|
}, t("contact_form"), "."))), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
182
184
|
item: true,
|
|
183
|
-
xs: 12
|
|
184
|
-
mb: 2
|
|
185
|
+
xs: 12
|
|
185
186
|
}, /*#__PURE__*/_react.default.createElement(_InputHelper.default, {
|
|
186
187
|
t: t,
|
|
187
188
|
id: "phrasesTopic",
|
|
@@ -201,6 +202,34 @@ function GeneratePhrases({
|
|
|
201
202
|
item: true,
|
|
202
203
|
xs: 12,
|
|
203
204
|
mb: 2
|
|
205
|
+
}, /*#__PURE__*/_react.default.createElement(_material.TextField, {
|
|
206
|
+
id: "topicGoal",
|
|
207
|
+
name: "topicGoal",
|
|
208
|
+
"data-cy": "topicGoal",
|
|
209
|
+
label: t("enter_a_topic_goal"),
|
|
210
|
+
value: values.topicGoal,
|
|
211
|
+
type: "text",
|
|
212
|
+
margin: "normal",
|
|
213
|
+
variant: "outlined",
|
|
214
|
+
fullWidth: true,
|
|
215
|
+
onChange: handleChange,
|
|
216
|
+
InputProps: {
|
|
217
|
+
endAdornment: /*#__PURE__*/_react.default.createElement(_material.InputAdornment, {
|
|
218
|
+
position: "end"
|
|
219
|
+
}, /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
|
|
220
|
+
title: t("topic_goal_info_text"),
|
|
221
|
+
placement: "top"
|
|
222
|
+
}, /*#__PURE__*/_react.default.createElement(_Info.default, {
|
|
223
|
+
fontSize: "small",
|
|
224
|
+
style: {
|
|
225
|
+
color: "lightgrey"
|
|
226
|
+
}
|
|
227
|
+
})))
|
|
228
|
+
}
|
|
229
|
+
})), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
230
|
+
item: true,
|
|
231
|
+
xs: 12,
|
|
232
|
+
mb: 2
|
|
204
233
|
}, /*#__PURE__*/_react.default.createElement(_material.TextField, {
|
|
205
234
|
select: true,
|
|
206
235
|
label: t("phrase_type"),
|
|
@@ -43,17 +43,24 @@ function GenerateRoleplayDialog({
|
|
|
43
43
|
makeCandooAIQuery,
|
|
44
44
|
pdfVectorStoreCreationStatus,
|
|
45
45
|
phrases,
|
|
46
|
-
topicId
|
|
46
|
+
topicId,
|
|
47
|
+
initialTopicGoal
|
|
47
48
|
}) {
|
|
48
49
|
const [isPreviewDialogOpen, setIsPreviewDialogOpen] = (0, _react.useState)(false);
|
|
49
50
|
const [usePdfContext, setUsePdfContext] = (0, _react.useState)(false);
|
|
50
51
|
const [usePhrasesContext, setUsePhrasesContext] = (0, _react.useState)(phrases && phrases.length > 0);
|
|
52
|
+
const [topicGoal, setTopicGoal] = (0, _react.useState)("");
|
|
51
53
|
const [isRoleplayGenerating, setIsRoleplayGenerating] = (0, _react.useState)(false);
|
|
52
54
|
const [generatedRoleplay, setGeneratedRoleplay] = (0, _react.useState)([]);
|
|
53
55
|
const [previewMessages, setPreviewMessages] = (0, _react.useState)([]);
|
|
54
56
|
const [values, setValues] = (0, _react.useState)(initialValues);
|
|
55
57
|
const [errorMessage, setErrorMessage] = (0, _react.useState)(null);
|
|
56
58
|
const [generateQuestions, setGenerateQuestions] = (0, _react.useState)(false);
|
|
59
|
+
(0, _react.useEffect)(() => {
|
|
60
|
+
if (initialTopicGoal && initialTopicGoal.trim() !== "") {
|
|
61
|
+
setTopicGoal(initialTopicGoal);
|
|
62
|
+
}
|
|
63
|
+
}, [initialTopicGoal]);
|
|
57
64
|
const roleplayLengthOptionsArray = ["short", "medium", "long"];
|
|
58
65
|
const roleplayLengthOptions = roleplayLengthOptionsArray.map((d, idx) => /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
59
66
|
key: idx,
|
|
@@ -157,13 +164,14 @@ function GenerateRoleplayDialog({
|
|
|
157
164
|
const roleplayDifficulty = values.roleplayDifficulty;
|
|
158
165
|
console.log("Roleplay Difficulty:", roleplayDifficulty);
|
|
159
166
|
const basePrompt = usePdfContext ? `Create an informative conversation between 2 people ${values?.actor1?.name && values?.actor2?.name ? `'${values.actor1.name}' and '${values.actor2.name}' ` : ""} about the topic '${values.roleplayTopic}' in the language ${learnLang}. The conversation should be ${i18nLanguage === "en-US" ? "ACTFL" : "CEFR"} level '${t(roleplayDifficulty)}.'` : `Create a conversation between 2 people ${values?.actor1?.name && values?.actor2?.name ? `'${values.actor1.name}' and '${values.actor2?.name}' ` : ""} about the topic '${values.roleplayTopic}' in the language ${learnLang}. The conversation should be ${i18nLanguage === "en-US" ? "ACTFL" : "CEFR"} level '${t(roleplayDifficulty)}.'`;
|
|
160
|
-
const
|
|
167
|
+
const topicGoalPrompt = topicGoal ? ` The conversation should be guided by the following goal: '${topicGoal}'.` : "";
|
|
168
|
+
const promptWithPhrases = usePhrasesContext ? ` Additionally, use the following phrases as part of the conversation, where appropriate to the topic '${values.roleplayTopic}': ${phrases.map(phrase => phrase.phrase).join(", ")}. Only use these phrases if they fit naturally into the conversation.` : "";
|
|
169
|
+
const finalPrompt = `${basePrompt}${topicGoalPrompt}${promptWithPhrases}`;
|
|
161
170
|
|
|
162
171
|
// Add explicit JSON formatting instructions with roleplay length
|
|
163
|
-
const promptWithoutQuestions = usePdfContext ? `${
|
|
164
|
-
const promptWithQuestions = usePdfContext ? `${
|
|
165
|
-
const activePrompt = generateQuestions ? promptWithQuestions : promptWithoutQuestions;
|
|
166
|
-
|
|
172
|
+
const promptWithoutQuestions = usePdfContext ? `${finalPrompt} The conversation should be returned as a JSON array. The conversation must contain exactly ${values.roleplayLengthNumber} exchanges (lines). Each piece of dialogue should be represented as an object with the keys 'actor' and 'text'. The 'actor' key should be set to 1 if the dialogue is spoken by the first actor, and 2 if it is spoken by the second actor. The 'text' key should be set to the dialogue text spoken by that actor. Please ensure the entire output follows this structure and is returned in a single JSON array.` : `${finalPrompt} The conversation should be returned as a JSON array. The conversation must contain exactly ${values.roleplayLengthNumber} exchanges (lines). Each piece of dialogue should be represented as an object with the keys 'actor' and 'text'. The 'actor' key should be set to 1 if the dialogue is spoken by the first actor, and 2 if it is spoken by the second actor. The 'text' key should be set to the dialogue text spoken by that actor. Please ensure the entire output follows this structure and is returned in a single JSON array.`;
|
|
173
|
+
const promptWithQuestions = usePdfContext ? `${finalPrompt} The conversation should be returned as a JSON array, including ${values?.questionsAmount} comprehension questions related to the conversation. The conversation must contain exactly ${values.roleplayLengthNumber} exchanges (lines). Each piece of dialogue should be represented as an object with the keys 'actor' and 'text'. The 'actor' key should be set to 1 if the dialogue is spoken by the first actor, and 2 if it is spoken by the second actor. The 'text' key should be set to the dialogue text spoken by that actor. Each comprehension question should also be represented as an object in the same array, with the keys 'question' and 'answers'. The 'answers' key should be an array of 3 objects, each containing 'text', 'correct' (true or false), and 'type' ('correct' or 'incorrect'). Please ensure the entire output follows this structure and is returned in a single JSON array.` : `${finalPrompt} The conversation should be returned as a JSON array, including ${values?.questionsAmount} comprehension questions related to the conversation. The conversation must contain exactly ${values.roleplayLengthNumber} exchanges (lines). Each piece of dialogue should be represented as an object with the keys 'actor' and 'text'. The 'actor' key should be set to 1 if the dialogue is spoken by the first actor, and 2 if it is spoken by the second actor. The 'text' key should be set to the dialogue text spoken by that actor. Each comprehension question should also be represented as an object in the same array, with the keys 'question' and 'answers'. The 'answers' key should be an array of 3 objects, each containing 'text', 'correct' (true or false), and 'type' ('correct' or 'incorrect'). Please ensure the entire output follows this structure and is returned in a single JSON array.`;
|
|
174
|
+
const activePrompt = generateQuestions ? promptWithQuestions : promptWithoutQuestions;
|
|
167
175
|
console.log("Final Prompt Sent to API:", activePrompt);
|
|
168
176
|
|
|
169
177
|
// Call the API and handle the response as before
|
|
@@ -344,6 +352,36 @@ function GenerateRoleplayDialog({
|
|
|
344
352
|
onChange: handleChange,
|
|
345
353
|
multiline: true,
|
|
346
354
|
rows: 3
|
|
355
|
+
})), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
356
|
+
item: true,
|
|
357
|
+
xs: 12
|
|
358
|
+
}, /*#__PURE__*/_react.default.createElement(_material.TextField, {
|
|
359
|
+
id: "topicGoal",
|
|
360
|
+
name: "topicGoal",
|
|
361
|
+
label: t("enter_a_topic_goal"),
|
|
362
|
+
value: topicGoal,
|
|
363
|
+
type: "text",
|
|
364
|
+
margin: "normal",
|
|
365
|
+
variant: "outlined",
|
|
366
|
+
multiline: true,
|
|
367
|
+
fullWidth: true,
|
|
368
|
+
sx: {
|
|
369
|
+
marginBottom: 5
|
|
370
|
+
},
|
|
371
|
+
onChange: e => setTopicGoal(e.target.value),
|
|
372
|
+
InputProps: {
|
|
373
|
+
endAdornment: /*#__PURE__*/_react.default.createElement(_material.InputAdornment, {
|
|
374
|
+
position: "end"
|
|
375
|
+
}, /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
|
|
376
|
+
title: t("topic_goal_info_text"),
|
|
377
|
+
placement: "top"
|
|
378
|
+
}, /*#__PURE__*/_react.default.createElement(_Info.default, {
|
|
379
|
+
fontSize: "small",
|
|
380
|
+
style: {
|
|
381
|
+
color: "lightgrey"
|
|
382
|
+
}
|
|
383
|
+
})))
|
|
384
|
+
}
|
|
347
385
|
}))), !hideRoleplayLengthOptions && !isRoleplayGenerating && /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
348
386
|
item: true,
|
|
349
387
|
xs: 12
|
|
@@ -227,7 +227,8 @@ function PhrasesEditor(props) {
|
|
|
227
227
|
siteLanguage,
|
|
228
228
|
makeChatGptApiRequest,
|
|
229
229
|
difficulty,
|
|
230
|
-
subscription
|
|
230
|
+
subscription,
|
|
231
|
+
topicGoal
|
|
231
232
|
} = props;
|
|
232
233
|
const [mode, setMode] = _react.default.useState(Modes.NORMAL);
|
|
233
234
|
const [errors, setErrors] = (0, _react.useState)([]);
|
|
@@ -569,7 +570,8 @@ function PhrasesEditor(props) {
|
|
|
569
570
|
makeChatGptApiRequest: makeChatGptApiRequest,
|
|
570
571
|
initialValues: {
|
|
571
572
|
phrasesTopic: topicName,
|
|
572
|
-
phraseAmount: 8
|
|
573
|
+
phraseAmount: 8,
|
|
574
|
+
topicGoal: topicGoal
|
|
573
575
|
},
|
|
574
576
|
siteLanguage: siteLanguage,
|
|
575
577
|
difficulty: difficulty
|
|
@@ -269,7 +269,8 @@ function Roleplay({
|
|
|
269
269
|
makeCandooAIQuery,
|
|
270
270
|
siteLanguage,
|
|
271
271
|
phrases,
|
|
272
|
-
topicId
|
|
272
|
+
topicId,
|
|
273
|
+
initialTopicGoal
|
|
273
274
|
}) {
|
|
274
275
|
console.log("Edit Roleplay -> phrases", phrases);
|
|
275
276
|
const [isGenerateRoleplayDialogOpen, setIsGenerateRoleplayDialogOpen] = (0, _react.useState)(false);
|
|
@@ -848,6 +849,7 @@ function Roleplay({
|
|
|
848
849
|
},
|
|
849
850
|
phrases: phrases,
|
|
850
851
|
topicId: topicId,
|
|
852
|
+
initialTopicGoal: initialTopicGoal,
|
|
851
853
|
autoSelect: true
|
|
852
854
|
}), /*#__PURE__*/_react.default.createElement(_reactJoyride.default, {
|
|
853
855
|
callback: handleJoyrideCallback,
|
|
@@ -51,6 +51,7 @@ var _AvatarDialog = _interopRequireDefault(require("../../../Dialogs/AvatarDialo
|
|
|
51
51
|
var _Styles = require("../../../utils/Styles");
|
|
52
52
|
var _teacherCreate = _interopRequireDefault(require("../../../img/teacher-create-2.svg"));
|
|
53
53
|
var _Unarchive = _interopRequireDefault(require("@mui/icons-material/Unarchive"));
|
|
54
|
+
var _Archive = _interopRequireDefault(require("@mui/icons-material/Archive"));
|
|
54
55
|
var _Share = _interopRequireDefault(require("@mui/icons-material/Share"));
|
|
55
56
|
var _RateReview = _interopRequireDefault(require("@mui/icons-material/RateReview"));
|
|
56
57
|
var _Edit = _interopRequireDefault(require("@mui/icons-material/Edit"));
|
|
@@ -240,7 +241,9 @@ function OverflowMenu({
|
|
|
240
241
|
})), /*#__PURE__*/_react.default.createElement(_material.Typography, null, t("delete_classroom"))), isCreator && !isArchived && /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
241
242
|
"data-cy": "archive-classroom",
|
|
242
243
|
onClick: archiveClassroom
|
|
243
|
-
},
|
|
244
|
+
}, /*#__PURE__*/_react.default.createElement(_CardElements.CardMenuIcon, null, /*#__PURE__*/_react.default.createElement(_Archive.default, {
|
|
245
|
+
fontSize: "small"
|
|
246
|
+
})), /*#__PURE__*/_react.default.createElement(_material.Typography, null, t("archive_classroom"))), isMediumScreen && isCreator && subscription.isPaidUser && !isArchived && /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
244
247
|
onClick: handleOpenInviteDialog
|
|
245
248
|
}, t("invite")), isMediumScreen && isCreator && !subscription.isPaidUser && !isArchived && /*#__PURE__*/_react.default.createElement(_material.MenuItem, {
|
|
246
249
|
onClick: handleOpenUpgradeSubscriptionModal
|
|
@@ -528,6 +528,7 @@ function Topic({
|
|
|
528
528
|
verificationStatus,
|
|
529
529
|
makeChatGptApiRequest,
|
|
530
530
|
parentClassroom,
|
|
531
|
+
topicGoal,
|
|
531
532
|
...otherProps
|
|
532
533
|
}) {
|
|
533
534
|
const {
|
|
@@ -1112,7 +1113,8 @@ function Topic({
|
|
|
1112
1113
|
siteLanguage: siteLanguage,
|
|
1113
1114
|
makeChatGptApiRequest: makeChatGptApiRequest,
|
|
1114
1115
|
difficulty: difficulty,
|
|
1115
|
-
subscription: subscription
|
|
1116
|
+
subscription: subscription,
|
|
1117
|
+
topicGoal: topicGoal
|
|
1116
1118
|
})))), /*#__PURE__*/_react.default.createElement(_material.Box, {
|
|
1117
1119
|
py: 1
|
|
1118
1120
|
}, /*#__PURE__*/_react.default.createElement(_Notes.default, {
|
|
@@ -1260,6 +1262,7 @@ function ViewTopic({
|
|
|
1260
1262
|
trackRecommendedEvent,
|
|
1261
1263
|
makeChatGptApiRequest,
|
|
1262
1264
|
parentClassroom,
|
|
1265
|
+
topicGoal,
|
|
1263
1266
|
...otherProps
|
|
1264
1267
|
}) {
|
|
1265
1268
|
const {
|
|
@@ -1288,7 +1291,8 @@ function ViewTopic({
|
|
|
1288
1291
|
verificationStatus: verificationStatus,
|
|
1289
1292
|
trackRecommendedEvent: trackRecommendedEvent,
|
|
1290
1293
|
makeChatGptApiRequest: makeChatGptApiRequest,
|
|
1291
|
-
parentClassroom: parentClassroom
|
|
1294
|
+
parentClassroom: parentClassroom,
|
|
1295
|
+
topicGoal: topicGoal
|
|
1292
1296
|
}, otherProps))), !isLoading && !topic && /*#__PURE__*/_react.default.createElement(_Topic.default, {
|
|
1293
1297
|
t: t,
|
|
1294
1298
|
isLoading: isLoading,
|