diff --git a/actions/dashboard/ExamPreparationActions.tsx b/actions/dashboard/ExamPreparationActions.tsx index 76af85bc..bc56cf65 100644 --- a/actions/dashboard/ExamPreparationActions.tsx +++ b/actions/dashboard/ExamPreparationActions.tsx @@ -72,12 +72,12 @@ export async function continueConversation ( You and the user can discuss the exam and the student's performance Messages inside [] means that it's a UI element or a user event. For example: - - [showExamnForm] means that the user will see an exam form and fill it out - - [showExamnResult] means that the user will see the result of the exam he took - - [examnsSuggestions] means that the user will see suggestions for exams he can take + - [showExamForm] means that the user will see an exam form and fill it out + - [showExamResult] means that the user will see the result of the exam he took + - [examsSuggestions] means that the user will see suggestions for exams he can take - If the user requests a exam or quiz, call \`showExamnForm\` to show the exam form. after an exan is taken, call \`showExamnResult\` to show the result of the exam. - As a teacher, if the user ask for an exam but is vague, you can suggest exams to the user by calling \`examnsSuggestions\` or if the user is asking for suggestions. + If the user requests a exam or quiz, call \`showExamForm\` to show the exam form. after an exan is taken, call \`showExamResult\` to show the result of the exam. + As a teacher, if the user ask for an exam but is vague, you can suggest exams to the user by calling \`examsSuggestions\` or if the user is asking for suggestions. Besides that, you can also chat with users about possible topics for exams, or any other topic you want to discuss with the user that goes along with the exam preparation as this is a exam preparation chat. `, @@ -118,7 +118,7 @@ export async function continueConversation ( ) }, tools: { - showExamnForm: { + showExamForm: { description: 'Show the user an exam form to fill out for an exam preparationn, this form will be sent to the user and he will anwser it', parameters: z.object({ singleSelectQuestion: z.array(z.object({ @@ -182,7 +182,7 @@ export async function continueConversation ( content: [ { type: 'tool-call', - toolName: 'showExamnForm', + toolName: 'showExamForm', toolCallId, args: { singleSelectQuestion, @@ -199,7 +199,7 @@ export async function continueConversation ( content: [ { type: 'tool-result', - toolName: 'showExamnForm', + toolName: 'showExamForm', toolCallId, result: { singleSelectQuestion, @@ -230,7 +230,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-call', - toolName: 'showExamnForm', + toolName: 'showExamForm', toolCallId, result: { singleSelectQuestion, @@ -248,7 +248,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-result', - toolName: 'showExamnForm', + toolName: 'showExamForm', toolCallId, result: { singleSelectQuestion, @@ -284,7 +284,7 @@ export async function continueConversation ( ) } }, - showExamnResult: { + showExamResult: { description: 'Show the user the result of the exam he took', parameters: z.object({ score: z.number().int().describe('The grade of the student in the exam with a scale from 0 to 20'), @@ -313,7 +313,7 @@ export async function continueConversation ( content: [ { type: 'tool-call', - toolName: 'showExamnResult', + toolName: 'showExamResult', toolCallId, args: { score, @@ -329,7 +329,7 @@ export async function continueConversation ( content: [ { type: 'tool-result', - toolName: 'showExamnResult', + toolName: 'showExamResult', toolCallId, result: { score, @@ -361,7 +361,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-call', - toolName: 'showExamnResult', + toolName: 'showExamResult', toolCallId, result: { score, @@ -378,7 +378,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-result', - toolName: 'showExamnResult', + toolName: 'showExamResult', toolCallId, result: { score, @@ -408,14 +408,14 @@ export async function continueConversation ( ) } }, - examnsSuggestions: { - description: 'Show the user suggestions for exams he can take', + examsSuggestions: { + description: 'Show the user suggestions for exams forms he can take', parameters: z.object({ suggestions: z.array(z.object({ - title: z.string().describe('The title of the suggestion'), - description: z.string().describe('The description of the suggestion'), - content: z.string().describe('The content of the suggestion'), - difficulty: z.string().describe('The difficulty of the examn') + title: z.string().describe('The title of the suggestion for the exam'), + description: z.string().describe('The description of the suggestion for the exam'), + content: z.string().describe('The content of the suggestion for the exam'), + difficulty: z.string().describe('The difficulty of the exam') })) }), generate: async function * ({ @@ -435,7 +435,7 @@ export async function continueConversation ( content: [ { type: 'tool-call', - toolName: 'examnsSuggestions', + toolName: 'examsSuggestions', toolCallId, args: { suggestions @@ -449,7 +449,7 @@ export async function continueConversation ( content: [ { type: 'tool-result', - toolName: 'examnsSuggestions', + toolName: 'examsSuggestions', toolCallId, result: { suggestions @@ -468,7 +468,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-call', - toolName: 'examnsSuggestions', + toolName: 'examsSuggestions', toolCallId, result: { suggestions @@ -483,7 +483,7 @@ export async function continueConversation ( message: JSON.stringify([ { type: 'tool-result', - toolName: 'examnsSuggestions', + toolName: 'examsSuggestions', toolCallId, result: { suggestions @@ -600,10 +600,10 @@ export const getUIStateFromAIState = (aiState: Chat) => { message.role === 'tool' ? ( message.content.map(tool => { - // find if the next message is a showExamnResult + // find if the next message is a showExamResult // @ts-expect-error - const isNextMessageAShowExamnResult = aiState?.messages[index + 1] ? aiState?.messages[index + 1].content[0]?.toolName === 'showExamnResult' : false - return tool.toolName === 'showExamnForm' ? ( + const isNextMessageAShowExamnResult = aiState?.messages[index + 1] ? aiState?.messages[index + 1].content[0]?.toolName === 'showExamResult' : false + return tool.toolName === 'showExamForm' ? ( { hideSubmit={isNextMessageAShowExamnResult} /> - ) : tool.toolName === 'showExamnResult' ? ( + ) : tool.toolName === 'showExamResult' ? ( { questionAndAnswerFeedback={tool.result.questionAndAnswerFeedback} /> - ) : tool.toolName === 'examnsSuggestions' ? ( + ) : tool.toolName === 'examsSuggestions' ? ( -
- +
-

- {chatData.data.title} -

+
{children}
) diff --git a/components/dashboards/Common/CommentsSections.tsx b/components/dashboards/Common/CommentsSections.tsx index 74e8bc6f..c2af9e2b 100644 --- a/components/dashboards/Common/CommentsSections.tsx +++ b/components/dashboards/Common/CommentsSections.tsx @@ -36,7 +36,7 @@ export default async function CommentsSections ({ .filter(comment => comment.parent_comment_id === null) .map((comment) => { const user = profiles.data.find((profile) => profile.id === comment.user_id) - const isReactionPresent = comment.comment_reactions.find( + const isReactionPresent = comment?.comment_reactions?.find( (reaction) => reaction.user_id === currentUser.data.user.id ) diff --git a/components/dashboards/Common/chat/chat.tsx b/components/dashboards/Common/chat/chat.tsx index 6e1ce1e3..ac9795c7 100644 --- a/components/dashboards/Common/chat/chat.tsx +++ b/components/dashboards/Common/chat/chat.tsx @@ -113,11 +113,12 @@ const ChatWindow = ({ isLoading: boolean }) => { return ( -
+
{messages.map((msg, index) => { if (msg.role === 'system') { return null } + if (index === 0) return null return ( void callbackFunction: (MessageType: MessageType) => void + isTemplatePresent?: boolean }) => { const [message, setMessage] = useState('') const ref = useRef(null) return ( -
{ - e.preventDefault() - callbackFunction({ - content: message, - role: 'user', - createdAt: new Date(), - id: generateId() - }) - setMessage('') - ref.current?.setMarkdown('') - }} - className="py-4 flex gap-2 flex-col w-full" - > - setMessage(value)} - ref={ref} - /> - - {isLoading ? ( - - ) : ( - + <> + {isTemplatePresent && ( + <> + + + )} - - +
{ + e.preventDefault() + callbackFunction({ + content: message, + role: 'user', + createdAt: new Date(), + id: generateId() + }) + setMessage('') + ref.current?.setMarkdown('') + }} + className="py-4 flex gap-2 flex-col w-full" + > + setMessage(value)} + ref={ref} + /> + + {isLoading ? ( + + ) : ( + + )} + + + ) } diff --git a/components/dashboards/Common/comments/CommentsCard.tsx b/components/dashboards/Common/comments/CommentsCard.tsx index ccc94478..77172129 100644 --- a/components/dashboards/Common/comments/CommentsCard.tsx +++ b/components/dashboards/Common/comments/CommentsCard.tsx @@ -45,7 +45,7 @@ const CommentCard = ({ avatar: string date: string isAuthor: boolean - comment_reactions: Array> + comment_reactions?: Array> isReactionPresent?: Tables<'comment_reactions'> allComments: any[] profiles: Array> @@ -81,13 +81,15 @@ const CommentCard = ({ } } - const reactionsForEachType = comment_reactions.reduce((acc, reaction) => { + const reactionsForEachType = comment_reactions?.reduce((acc, reaction) => { acc[reaction.reaction_type] = acc[reaction.reaction_type] + 1 || 1 return acc }, {}) const replies = allComments.filter(reply => reply.parent_comment_id === comment.id) + console.log(reactionsForEachType) + return ( @@ -146,7 +148,7 @@ const CommentCard = ({ - )} -
- ))} -
-
- {question.rightColumn.map((item) => ( -
!isItemDisabled(item, 'right') && handleRightClick(item)} - > - {item.text} - {Object.keys(matchedPairs).map((leftId) => ( - isMatched(leftId, item.id) && ( - {' (Matched)'} - ) - ))} -
- ))} -
-
- {selectedLeft && ( -
-

Selected: {selectedLeft.text}

+ + )} +
+ ))} +
+
+ {question.rightColumn.map((item) => ( +
!isItemDisabled(item, 'right') && handleRightClick(item)} + > + {item.text} + {Object.keys(matchedPairs).map((leftId) => ( + isMatched(leftId, item.id) && ( + {' (Matched)'} + ) + ))} +
+ ))} +
- )} - + + + + {selectedLeft && ( +
+

Selected: {selectedLeft.text}

+
+ )} +
+ ) } diff --git a/components/dashboards/student/chat/ExamPrepChat.tsx b/components/dashboards/student/chat/ExamPrepChat.tsx index 035924bd..cee55602 100644 --- a/components/dashboards/student/chat/ExamPrepChat.tsx +++ b/components/dashboards/student/chat/ExamPrepChat.tsx @@ -31,7 +31,7 @@ export default function ExamPrepChat ({ if (!lastMessage) return if (lastMessage.role === 'tool') { const [toolCalled] = lastMessage.content - const isShowExamnForm = toolCalled.toolName === 'showExamnForm' + const isShowExamnForm = toolCalled.toolName === 'showExamForm' setHideInput(isShowExamnForm) } } @@ -52,17 +52,17 @@ export default function ExamPrepChat ({ {conversation.length ? ( ) : (

- Please write a message with the examn you want, like "help me creating a basic + Please write a message with the exam you want, like "help me creating a basic [Exam Subject] - examn form for me please" + exam form for me please"

)} @@ -128,6 +128,7 @@ export default function ExamPrepChat ({ setStop(true)} + isTemplatePresent={true} callbackFunction={async (input) => { if (stop) return diff --git a/components/dashboards/student/chat/ExamnSuggestions.tsx b/components/dashboards/student/chat/ExamnSuggestions.tsx index 5a645b34..e8d4d895 100644 --- a/components/dashboards/student/chat/ExamnSuggestions.tsx +++ b/components/dashboards/student/chat/ExamnSuggestions.tsx @@ -10,7 +10,7 @@ import { cn } from '@/utils' import ChatLoadingSkeleton from './ChatLoadingSkeleton' -interface ExamnSuggestion { +interface ExamSuggestion { title: string description: string content: string @@ -22,20 +22,20 @@ export default function ExamnSuggestions ({ suggestions, disabled }: { - suggestions: ExamnSuggestion[] + suggestions: ExamSuggestion[] disabled?: boolean }) { const [isLoading, setIsLoading] = useState(false) const { continueConversation } = useActions() const [_, setMessages] = useUIState() - const [selectedSuggestion, setSelectedSuggestion] = useState(null) + const [selectedSuggestion, setSelectedSuggestion] = useState(null) - async function onSuggestionClick (suggestion: ExamnSuggestion) { + async function onSuggestionClick (suggestion: ExamSuggestion) { setIsLoading(true) try { - const message = `Help me creating an examn form for ${suggestion.title} + const message = `Help me creating an exam form for ${suggestion.title} --- - # Examn Form + # Exam Form title: ${suggestion.title} description: ${suggestion.description} content: ${suggestion.content} diff --git a/components/dashboards/student/course/lessons/TaksMessages.tsx b/components/dashboards/student/course/lessons/TaksMessages.tsx index 93ddeea2..6280d7e5 100644 --- a/components/dashboards/student/course/lessons/TaksMessages.tsx +++ b/components/dashboards/student/course/lessons/TaksMessages.tsx @@ -23,7 +23,7 @@ function useChatLogic ( maxAutomaticRoundtrips: 5, body: { lessonId }, initialMessages: [ - { role: 'system', content: systemPrompt, id: generateId() }, + { role: 'assistant', content: systemPrompt, id: generateId() }, ...initialMessages.map((msg) => ({ role: msg.sender, content: msg.message,