|
1 | 1 | "use client"
|
2 |
| -import React, { useMemo } from "react" |
3 |
| -import { makeSend } from "./send" |
4 | 2 |
|
5 |
| -import { FeatureFlags } from "@/common/feature_flags" |
6 |
| -import { useFeatureFlagEnabled } from "posthog-js/react" |
7 |
| -import StyledContainer from "@/page-components/StyledContainer/StyledContainer" |
| 3 | +import React from "react" |
8 | 4 | import { styled } from "ol-components"
|
9 |
| -import { NluxAiChat } from "@/page-components/Nlux-AiChat/AiChat" |
| 5 | +import { getCsrfToken } from "@/common/utils" |
| 6 | +import { AiChat, AiChatProps } from "@mitodl/smoot-design/ai" |
10 | 7 |
|
11 |
| -const StyledChat = styled(NluxAiChat)({ |
12 |
| - maxHeight: "60vh", |
13 |
| - flex: 1, |
| 8 | +const Container = styled.div({ |
| 9 | + margin: "40px auto", |
| 10 | + width: "60%", |
14 | 11 | })
|
15 | 12 |
|
16 |
| -const CONVERSATION_OPTIONS = { |
17 |
| - conversationStarters: [ |
18 |
| - { |
19 |
| - prompt: |
20 |
| - "I'm interested in courses on quantum computing that offer certificates.", |
21 |
| - }, |
22 |
| - { |
23 |
| - prompt: |
24 |
| - "I want to learn about global warming, can you recommend any videos?", |
25 |
| - }, |
26 |
| - { |
27 |
| - prompt: |
28 |
| - "I am curious about AI applications for business. Do you have any free courses about that?", |
29 |
| - }, |
30 |
| - { |
31 |
| - prompt: |
32 |
| - "I would like to learn about linear regression, preferably at no cost.", |
33 |
| - }, |
34 |
| - ], |
35 |
| -} |
| 13 | +const INITIAL_MESSAGES: AiChatProps["initialMessages"] = [ |
| 14 | + { |
| 15 | + content: "What do you want to learn about today?", |
| 16 | + role: "assistant", |
| 17 | + }, |
| 18 | +] |
| 19 | + |
| 20 | +export const STARTERS = [ |
| 21 | + { |
| 22 | + content: |
| 23 | + "I'm interested in courses on quantum computing that offer certificates.", |
| 24 | + }, |
| 25 | + { |
| 26 | + content: |
| 27 | + "I want to learn about global warming, can you recommend any videos?", |
| 28 | + }, |
| 29 | + { |
| 30 | + content: |
| 31 | + "I am curious about AI applications for business. Do you have any free courses about that?", |
| 32 | + }, |
| 33 | + { |
| 34 | + content: |
| 35 | + "I would like to learn about linear regression, preferably at no cost.", |
| 36 | + }, |
| 37 | +] |
36 | 38 |
|
37 | 39 | const ChatPage = () => {
|
38 |
| - const recommendationBotEnabled = useFeatureFlagEnabled( |
39 |
| - FeatureFlags.RecommendationBot, |
40 |
| - ) |
41 |
| - const send = useMemo(() => { |
42 |
| - return makeSend({ url: "/api/v0/chat_agent/" }) |
43 |
| - }, []) |
44 | 40 | return (
|
45 |
| - <StyledContainer> |
46 |
| - { |
47 |
| - // eslint-disable-next-line no-constant-condition |
48 |
| - recommendationBotEnabled ? ( |
49 |
| - <StyledChat |
50 |
| - key={"agent"} |
51 |
| - send={send} |
52 |
| - conversationOptions={CONVERSATION_OPTIONS} |
53 |
| - /> |
54 |
| - ) : ( |
55 |
| - <></> |
56 |
| - ) |
57 |
| - } |
58 |
| - </StyledContainer> |
| 41 | + <Container> |
| 42 | + <AiChat |
| 43 | + askTimTitle="to recommend a course" |
| 44 | + initialMessages={INITIAL_MESSAGES} |
| 45 | + conversationStarters={STARTERS} |
| 46 | + requestOpts={{ |
| 47 | + apiUrl: `${process.env.NEXT_PUBLIC_MITOL_API_BASE_URL}/api/v0/chat_agent/`, |
| 48 | + fetchOpts: { |
| 49 | + headers: { |
| 50 | + "X-CSRFToken": getCsrfToken(), |
| 51 | + }, |
| 52 | + }, |
| 53 | + transformBody: (messages) => ({ |
| 54 | + message: messages[messages.length - 1].content, |
| 55 | + }), |
| 56 | + }} |
| 57 | + /> |
| 58 | + </Container> |
59 | 59 | )
|
60 | 60 | }
|
61 | 61 |
|
|
0 commit comments