-
Notifications
You must be signed in to change notification settings - Fork 2
Misc Changes from Async Question Images PR, Clear Profile Cache, PFP Upload Protections #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2cb730a
9d36deb
da73711
3f48948
59f8237
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,15 @@ interface FormValues { | |
| content: string | ||
| source: string | ||
| pageNumber: string | ||
| name: string | ||
| } | ||
|
|
||
| interface ChatbotDocumentsProps { | ||
| interface ChatbotKnowledgeBaseProps { | ||
| params: Promise<{ cid: string }> | ||
| } | ||
|
|
||
| export default function ChatbotDocuments( | ||
| props: ChatbotDocumentsProps, | ||
| export default function ChatbotKnowledgeBase( | ||
| props: ChatbotKnowledgeBaseProps, | ||
| ): ReactElement { | ||
| const params = use(props.params) | ||
| const courseId = Number(params.cid) | ||
|
|
@@ -46,14 +47,15 @@ export default function ChatbotDocuments( | |
| const [editRecordModalOpen, setEditRecordModalOpen] = useState(false) | ||
| const [form] = Form.useForm() | ||
| const [addDocChunkPopupVisible, setAddDocChunkPopupVisible] = useState(false) | ||
| const [dataLoading, setDataLoading] = useState(false) | ||
|
|
||
| const addDocument = async (values: FormValues) => { | ||
| const body: AddDocumentChunkParams = { | ||
| documentText: values.content, | ||
| metadata: { | ||
| name: 'Manually Inserted Information', | ||
| name: values.name || 'Manually Inserted Information', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm anticipating merge conflicts with my vector store refactor... sigh... that's what i get for having a PR that is old |
||
| type: 'inserted_document', | ||
| source: values.source ?? undefined, | ||
| source: values.source || undefined, | ||
| loc: values.pageNumber | ||
| ? { pageNumber: parseInt(values.pageNumber) } | ||
| : undefined, | ||
|
|
@@ -91,6 +93,7 @@ export default function ChatbotDocuments( | |
|
|
||
| const fetchDocuments = useCallback(async () => { | ||
| if (courseId) { | ||
| setDataLoading(true) | ||
| await API.chatbot.staffOnly | ||
| .getAllDocumentChunks(courseId) | ||
| .then((response) => { | ||
|
|
@@ -106,6 +109,7 @@ export default function ChatbotDocuments( | |
| message.error('Failed to load documents: ' + errorMessage) | ||
| }) | ||
| } | ||
| setDataLoading(false) | ||
| }, [courseId, setDocuments, setFilteredDocuments, search]) | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -270,25 +274,33 @@ export default function ChatbotDocuments( | |
| > | ||
| <Input.TextArea /> | ||
| </Form.Item> | ||
| <Form.Item | ||
| label="Name" | ||
| name="name" | ||
| tooltip={`When this chunk is cited, it will show this name. Defaults to "Manually Inserted Info" if not specified.`} | ||
| > | ||
| <Input placeholder="Manually Inserted Info" /> | ||
| </Form.Item> | ||
| {/* <Form.Item label="Edited Chunk" name="editedChunk"> | ||
| <Input.TextArea /> | ||
| </Form.Item> */} | ||
| <Form.Item | ||
| label="Source" | ||
| label="Source URL" | ||
| name="source" | ||
| rules={[ | ||
| { | ||
| type: 'url', | ||
| message: 'Please enter a valid URL', | ||
| }, | ||
| ]} | ||
| tooltip="When a student clicks on the citation, they will be redirected to this link" | ||
| tooltip="When a student clicks on the citation, they will be redirected to this link. Can be a link to anything." | ||
| > | ||
| <Input /> | ||
| <Input placeholder="https://canvas.ubc.ca/courses/.../pages/..." /> | ||
| </Form.Item> | ||
| <Form.Item | ||
| label="Page Number" | ||
| name="pageNumber" | ||
| tooltip="If the document in the Source URL is multi-page (e.g. a PDF), the content of the chunk should be found on this page. This is only for display purposes so that the citation says 'My doc p.3' for example. Feel free to leave this as 0 or blank." | ||
| rules={[ | ||
| { | ||
| type: 'number', | ||
|
|
@@ -335,6 +347,8 @@ export default function ChatbotDocuments( | |
| dataSource={filteredDocuments} | ||
| size="small" | ||
| className="w-full" | ||
| bordered | ||
| loading={documents.length === 0 && dataLoading} | ||
| locale={{ | ||
| emptyText: ( | ||
| <Empty | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import UserAccessTokens from './UserAccessTokens' | ||
| import ClearProfileCache from './ClearProfileCache' | ||
|
|
||
| const AdvancedSettings: React.FC = () => { | ||
| return ( | ||
| <div className="flex w-full flex-col gap-2"> | ||
| <h2 className="text-2xl font-bold">Advanced Settings</h2> | ||
| <UserAccessTokens /> | ||
| <ClearProfileCache /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default AdvancedSettings |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THANK. YOU.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be abusable though depending on your route |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { API } from '@/app/api' | ||
| import { useUserInfo } from '@/app/contexts/userContext' | ||
| import { getErrorMessage } from '@/app/utils/generalUtils' | ||
| import { DeleteOutlined, QuestionCircleOutlined } from '@ant-design/icons' | ||
| import { Button, Card, message, Tooltip } from 'antd' | ||
| import { useState } from 'react' | ||
|
|
||
| const ClearProfileCache: React.FC = () => { | ||
| const { userInfo, setUserInfo } = useUserInfo() | ||
| const [isLoading, setIsLoading] = useState(false) | ||
|
|
||
| return ( | ||
| <> | ||
| {userInfo && ( | ||
| <Card title={<h3> Profile Cache</h3>} classNames={{ body: 'py-2' }}> | ||
| <Tooltip | ||
| title={`Notice some weird behavior where the server is giving you errors but the client looks fine on your end? The profile caching may have become unsynced. Click this button to clear the cache (there are no consequences of doing so).`} | ||
| > | ||
| Clear Backend Profile Cache | ||
| <QuestionCircleOutlined className="ml-0.5 text-gray-500" /> | ||
| </Tooltip> | ||
| <Button | ||
| icon={<DeleteOutlined />} | ||
| loading={isLoading} | ||
| onClick={async () => { | ||
| setIsLoading(true) | ||
| await API.profile | ||
| .clearCache() | ||
| .then(async () => { | ||
| await API.profile | ||
| .getUser() | ||
| .then((userDetails) => { | ||
| setUserInfo(userDetails) | ||
| message.success( | ||
| 'Profile cache cleared successfully. You may want to refresh your page.', | ||
| ) | ||
| }) | ||
| .catch((error) => { | ||
| message.error( | ||
| 'Cache cleared but error getting new user details: ' + | ||
| getErrorMessage(error), | ||
| ) | ||
| }) | ||
| }) | ||
| .catch((error) => { | ||
| message.error( | ||
| 'Error clearing profile cache: ' + getErrorMessage(error), | ||
| ) | ||
| }) | ||
| setIsLoading(false) | ||
| }} | ||
| className="ml-2" | ||
| > | ||
| Clear | ||
| </Button> | ||
| </Card> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default ClearProfileCache |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import CoursePreference from './CoursePreference' | |
| import { useMediaQuery } from '@/app/hooks/useMediaQuery' | ||
| import EmailNotifications from './EmailNotifications' | ||
| import UserChatbotHistory from './UserChatbotHistory' | ||
| import AdvancedSettings from './AdvancedSettings' | ||
|
|
||
| interface SettingsMenuProps { | ||
| currentSettings: SettingsOptions | ||
|
|
@@ -59,6 +60,11 @@ const SettingsMenu: React.FC<SettingsMenuProps> = ({ | |
| label: 'Chatbot History', | ||
| children: <UserChatbotHistory />, | ||
| }, | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought having it as a family of options might've been useful, the dropdown also prevented it from being shown by default (comparable to other advanced settings in similar webapps)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's about the same UX either way (plus it's a rare usecase), but I could change it back if you'd prefer. Also I'm not entirely sure I know what you mean by the dropdown preventing it from being shown by default?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, the advanced options would only show when highlighted or selected. ants is weird tho and i cant remember exactly
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I believe before it was a submenu, where you click Advanced -> submenu with [Access Tokens, Clear Cache] -> Click on item and taken to dedicated page for that item. What I did here was just make one "Advanced" page with both Access Tokens and Clear Cache on the same page, which I guess is shown on the screenshots in the PR description. It's basically the same, maybe just a little more consistent with our profile settings pages but it's kinda subjective. |
||
| key: SettingsOptions.ADVANCED, | ||
| label: 'Advanced', | ||
| children: <AdvancedSettings />, | ||
| }, | ||
| ]} | ||
| /> | ||
| ) : ( | ||
|
|
@@ -88,16 +94,9 @@ const SettingsMenu: React.FC<SettingsMenuProps> = ({ | |
| icon: <HistoryOutlined />, | ||
| }, | ||
| { | ||
| key: 'Advanced', | ||
| key: SettingsOptions.ADVANCED, | ||
| label: 'Advanced', | ||
| icon: <SettingOutlined />, | ||
| children: [ | ||
| { | ||
| key: SettingsOptions.ACCESS_TOKENS, | ||
| label: 'Access Tokens', | ||
| icon: <KeyOutlined />, | ||
| }, | ||
| ], | ||
| }, | ||
| ]} | ||
| /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i love these random flavor text changes in every PR