This commit is contained in:
GH Action - Upstream Sync
2024-11-06 01:01:16 +00:00
8 changed files with 105 additions and 41 deletions

View File

@@ -433,6 +433,8 @@ class CombinedJson(Resource):
@api.doc(description="Provide JSON file with combined available indexes") @api.doc(description="Provide JSON file with combined available indexes")
def get(self): def get(self):
user = "local" user = "local"
sort_field = request.args.get('sort', 'date') # Default to 'date'
sort_order = request.args.get('order', "desc") # Default to 'desc'
data = [ data = [
{ {
"name": "default", "name": "default",
@@ -445,7 +447,7 @@ class CombinedJson(Resource):
] ]
try: try:
for index in sources_collection.find({"user": user}).sort("date", -1): for index in sources_collection.find({"user": user}).sort(sort_field, 1 if sort_order=="asc" else -1):
data.append( data.append(
{ {
"id": str(index["_id"]), "id": str(index["_id"]),

View File

@@ -9,6 +9,7 @@ import { ThemeProvider } from 'styled-components';
import Like from "../assets/like.svg" import Like from "../assets/like.svg"
import Dislike from "../assets/dislike.svg" import Dislike from "../assets/dislike.svg"
import MarkdownIt from 'markdown-it'; import MarkdownIt from 'markdown-it';
const themes = { const themes = {
dark: { dark: {
bg: '#222327', bg: '#222327',
@@ -35,6 +36,20 @@ const themes = {
} }
} }
} }
const sizesConfig = {
small: { size:'small', width: '400px', height: '320px' },
medium: { size:'medium', width: '28vw', height: '70vh'},
large: { size:'large', width: '60vw', height: '75vh'},
getCustom: (custom: { width: string; height: string; maxWidth?: string; maxHeight?: string }) => ({
size:'custom',
width: custom.width,
height: custom.height,
maxWidth: custom.maxWidth || '968px',
maxHeight: custom.maxHeight || '70vh',
}),
};
const GlobalStyles = createGlobalStyle` const GlobalStyles = createGlobalStyle`
.response pre { .response pre {
padding: 8px; padding: 8px;
@@ -80,7 +95,7 @@ const Overlay = styled.div`
z-index: 999; z-index: 999;
transition: opacity 0.5s; transition: opacity 0.5s;
` `
const WidgetContainer = styled.div<{ modal: boolean }>` const WidgetContainer = styled.div<{ modal?: boolean }>`
display: block; display: block;
position: fixed; position: fixed;
right: ${props => props.modal ? '50%' : '10px'}; right: ${props => props.modal ? '50%' : '10px'};
@@ -183,23 +198,29 @@ const Description = styled.p`
margin-top: 0; margin-top: 0;
`; `;
const Conversation = styled.div<{ size: string }>` const Conversation = styled.div`
min-height: 250px; min-height: 250px;
max-width: 968px; max-height: ${(props) => props.theme.dimensions.maxHeight};
height: ${props => props.size === 'large' ? '75vh' : props.size === 'medium' ? '70vh' : '320px'}; max-width: ${(props) => props.theme.dimensions.maxWidth};
width: ${props => props.size === 'large' ? '60vw' : props.size === 'medium' ? '28vw' : '400px'}; height: ${(props) => props.theme.dimensions.height};
padding-inline: 0.5rem; width: ${(props) => props.theme.dimensions.width};
border-radius: 0.375rem; padding-inline: 0.5rem;
text-align: left; border-radius: 0.375rem;
overflow-y: auto; text-align: left;
scrollbar-width: thin; overflow-y: auto;
scrollbar-color: #4a4a4a transparent; /* thumb color track color */ scrollbar-width: thin;
@media only screen and (max-width: 768px) { scrollbar-color: #4a4a4a transparent; /* thumb color track color */
@media only screen and (max-width: 768px) {
width: 90vw !important; width: 90vw !important;
} }
@media only screen and (min-width:768px ) and (max-width: 1280px) { @media only screen and (min-width: 768px) and (max-width: 1280px) {
width:${props => props.size === 'large' ? '90vw' : props.size === 'medium' ? '60vw' : '400px'} !important; width: ${(props) =>
} props.theme.dimensions.size === "large"
? "90vw"
: props.theme.dimensions.size === "medium"
? "60vw"
: "400px"} !important;
}
`; `;
const Feedback = styled.div` const Feedback = styled.div`
background-color: transparent; background-color: transparent;
@@ -265,9 +286,9 @@ const DotAnimation = styled.div`
const Delay = styled(DotAnimation) <{ delay: number }>` const Delay = styled(DotAnimation) <{ delay: number }>`
animation-delay: ${props => props.delay + 'ms'}; animation-delay: ${props => props.delay + 'ms'};
`; `;
const PromptContainer = styled.form<{ size: string }>` const PromptContainer = styled.form`
background-color: transparent; background-color: transparent;
height: ${props => props.size == 'large' ? '60px' : '40px'}; height: ${props => props.theme.dimensions.size == 'large' ? '60px' : '40px'};
margin: 16px; margin: 16px;
display: flex; display: flex;
justify-content: space-evenly; justify-content: space-evenly;
@@ -282,14 +303,14 @@ const StyledInput = styled.input`
color: ${props => props.theme.text}; color: ${props => props.theme.text};
outline: none; outline: none;
`; `;
const StyledButton = styled.button<{ size: string }>` const StyledButton = styled.button`
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-image: linear-gradient(to bottom right, #5AF0EC, #E80D9D); background-image: linear-gradient(to bottom right, #5AF0EC, #E80D9D);
border-radius: 6px; border-radius: 6px;
min-width: ${props => props.size === 'large' ? '60px' : '36px'}; min-width: ${props => props.theme.dimensions.size === 'large' ? '60px' : '36px'};
height: ${props => props.size === 'large' ? '60px' : '36px'}; height: ${props => props.theme.dimensions.size === 'large' ? '60px' : '36px'};
margin-left:8px; margin-left:8px;
padding: 0px; padding: 0px;
border: none; border: none;
@@ -366,13 +387,14 @@ export const DocsGPTWidget = ({
theme = 'dark', theme = 'dark',
buttonIcon = 'https://d3dg1063dc54p9.cloudfront.net/widget/message.svg', buttonIcon = 'https://d3dg1063dc54p9.cloudfront.net/widget/message.svg',
buttonBg = 'linear-gradient(to bottom right, #5AF0EC, #E80D9D)', buttonBg = 'linear-gradient(to bottom right, #5AF0EC, #E80D9D)',
collectFeedback = true collectFeedback = true,
deafultOpen = false
}: WidgetProps) => { }: WidgetProps) => {
const [prompt, setPrompt] = React.useState(''); const [prompt, setPrompt] = React.useState('');
const [status, setStatus] = React.useState<Status>('idle'); const [status, setStatus] = React.useState<Status>('idle');
const [queries, setQueries] = React.useState<Query[]>([]) const [queries, setQueries] = React.useState<Query[]>([])
const [conversationId, setConversationId] = React.useState<string | null>(null) const [conversationId, setConversationId] = React.useState<string | null>(null)
const [open, setOpen] = React.useState<boolean>(false) const [open, setOpen] = React.useState<boolean>(deafultOpen)
const [eventInterrupt, setEventInterrupt] = React.useState<boolean>(false); //click or scroll by user while autoScrolling const [eventInterrupt, setEventInterrupt] = React.useState<boolean>(false); //click or scroll by user while autoScrolling
const isBubbleHovered = useRef<boolean>(false) const isBubbleHovered = useRef<boolean>(false)
const endMessageRef = React.useRef<HTMLDivElement | null>(null); const endMessageRef = React.useRef<HTMLDivElement | null>(null);
@@ -486,8 +508,13 @@ export const DocsGPTWidget = ({
const handleImageError = (event: React.SyntheticEvent<HTMLImageElement, Event>) => { const handleImageError = (event: React.SyntheticEvent<HTMLImageElement, Event>) => {
event.currentTarget.src = "https://d3dg1063dc54p9.cloudfront.net/cute-docsgpt.png"; event.currentTarget.src = "https://d3dg1063dc54p9.cloudfront.net/cute-docsgpt.png";
}; };
const dimensions =
typeof size === 'object' && 'custom' in size
? sizesConfig.getCustom(size.custom)
: sizesConfig[size];
return ( return (
<ThemeProvider theme={themes[theme]}> <ThemeProvider theme={{...themes[theme], dimensions}}>
{open && size === 'large' && {open && size === 'large' &&
<Overlay onClick={() => { <Overlay onClick={() => {
setOpen(false) setOpen(false)
@@ -513,7 +540,7 @@ export const DocsGPTWidget = ({
</ContentWrapper> </ContentWrapper>
</Header> </Header>
</div> </div>
<Conversation size={size} onWheel={handleUserInterrupt} onTouchMove={handleUserInterrupt}> <Conversation onWheel={handleUserInterrupt} onTouchMove={handleUserInterrupt}>
{ {
queries.length > 0 ? queries?.map((query, index) => { queries.length > 0 ? queries?.map((query, index) => {
return ( return (
@@ -584,13 +611,11 @@ export const DocsGPTWidget = ({
} }
</Conversation> </Conversation>
<PromptContainer <PromptContainer
size={size}
onSubmit={handleSubmit}> onSubmit={handleSubmit}>
<StyledInput <StyledInput
value={prompt} onChange={(event) => setPrompt(event.target.value)} value={prompt} onChange={(event) => setPrompt(event.target.value)}
type='text' placeholder="What do you want to do?" /> type='text' placeholder="What do you want to do?" />
<StyledButton <StyledButton
size={size}
disabled={prompt.trim().length == 0 || status !== 'idle'}> disabled={prompt.trim().length == 0 || status !== 'idle'}>
<PaperPlaneIcon width={15} height={15} color='white' /> <PaperPlaneIcon width={15} height={15} color='white' />
</StyledButton> </StyledButton>

View File

@@ -19,9 +19,17 @@ export interface WidgetProps {
description?: string; description?: string;
heroTitle?: string; heroTitle?: string;
heroDescription?: string; heroDescription?: string;
size?: 'small' | 'medium' | 'large'; size?: 'small' | 'medium' | 'large' | {
custom: {
width: string;
height: string;
maxWidth?: string;
maxHeight?: string;
};
};
theme?:THEME, theme?:THEME,
buttonIcon?:string; buttonIcon?:string;
buttonBg?:string; buttonBg?:string;
collectFeedback?:boolean collectFeedback?:boolean;
deafultOpen?: boolean;
} }

View File

@@ -254,7 +254,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
ref={navRef} ref={navRef}
className={`${ className={`${
!navOpen && '-ml-96 md:-ml-[18rem]' !navOpen && '-ml-96 md:-ml-[18rem]'
} duration-20 fixed top-0 z-40 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`} } duration-20 fixed top-0 z-20 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`}
> >
<div <div
className={'visible mt-2 flex h-[6vh] w-full justify-between md:h-12'} className={'visible mt-2 flex h-[6vh] w-full justify-between md:h-12'}

View File

@@ -2,7 +2,8 @@ import apiClient from '../client';
import endpoints from '../endpoints'; import endpoints from '../endpoints';
const userService = { const userService = {
getDocs: (): Promise<any> => apiClient.get(endpoints.USER.DOCS), getDocs: (sort = 'date', order = 'desc'): Promise<any> =>
apiClient.get(`${endpoints.USER.DOCS}?sort=${sort}&order=${order}`),
checkDocs: (data: any): Promise<any> => checkDocs: (data: any): Promise<any> =>
apiClient.post(endpoints.USER.DOCS_CHECK, data), apiClient.post(endpoints.USER.DOCS_CHECK, data),
getAPIKeys: (): Promise<any> => apiClient.get(endpoints.USER.API_KEYS), getAPIKeys: (): Promise<any> => apiClient.get(endpoints.USER.API_KEYS),

View File

@@ -474,7 +474,7 @@ function AllSources(sources: AllSourcesProps) {
></img> ></img>
) : null} ) : null}
</span> </span>
<p className="mt-3 max-h-24 overflow-y-auto break-words rounded-md text-left text-xs text-black dark:text-chinese-silver"> <p className="mt-3 max-h-16 overflow-y-auto break-words rounded-md text-left text-xs text-black dark:text-chinese-silver">
{source.text} {source.text}
</p> </p>
</div> </div>

View File

@@ -3,9 +3,12 @@ import userService from '../api/services/userService';
import { Doc } from '../models/misc'; import { Doc } from '../models/misc';
//Fetches all JSON objects from the source. We only use the objects with the "model" property in SelectDocsModal.tsx. Hopefully can clean up the source file later. //Fetches all JSON objects from the source. We only use the objects with the "model" property in SelectDocsModal.tsx. Hopefully can clean up the source file later.
export async function getDocs(): Promise<Doc[] | null> { export async function getDocs(
sort = 'date',
order = 'desc',
): Promise<Doc[] | null> {
try { try {
const response = await userService.getDocs(); const response = await userService.getDocs(sort, order);
const data = await response.json(); const data = await response.json();
const docs: Doc[] = []; const docs: Doc[] = [];

View File

@@ -45,14 +45,30 @@ const Documents: React.FC<DocumentsProps> = ({
const [modalState, setModalState] = useState<ActiveState>('INACTIVE'); // Initialize with inactive state const [modalState, setModalState] = useState<ActiveState>('INACTIVE'); // Initialize with inactive state
const [isOnboarding, setIsOnboarding] = useState(false); // State for onboarding flag const [isOnboarding, setIsOnboarding] = useState(false); // State for onboarding flag
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [sortField, setSortField] = useState<'date' | 'tokens'>('date');
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
const syncOptions = [ const syncOptions = [
{ label: 'Never', value: 'never' }, { label: 'Never', value: 'never' },
{ label: 'Daily', value: 'daily' }, { label: 'Daily', value: 'daily' },
{ label: 'Weekly', value: 'weekly' }, { label: 'Weekly', value: 'weekly' },
{ label: 'Monthly', value: 'monthly' }, { label: 'Monthly', value: 'monthly' },
]; ];
const refreshDocs = (field: 'date' | 'tokens') => {
if (field === sortField) {
setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc');
} else {
setSortOrder('desc');
setSortField(field);
}
getDocs(sortField, sortOrder)
.then((data) => {
dispatch(setSourceDocs(data));
})
.catch((error) => console.error(error))
.finally(() => {
setLoading(false);
});
};
const handleManageSync = (doc: Doc, sync_frequency: string) => { const handleManageSync = (doc: Doc, sync_frequency: string) => {
setLoading(true); setLoading(true);
userService userService
@@ -110,19 +126,28 @@ const Documents: React.FC<DocumentsProps> = ({
<th> <th>
<div className="flex justify-center items-center"> <div className="flex justify-center items-center">
{t('settings.documents.date')} {t('settings.documents.date')}
<img src={caretSort} alt="" /> <img
className="cursor-pointer"
onClick={() => refreshDocs('date')}
src={caretSort}
alt="sort"
/>
</div> </div>
</th> </th>
<th> <th>
<div className="flex justify-center items-center"> <div className="flex justify-center items-center">
{t('settings.documents.tokenUsage')} {t('settings.documents.tokenUsage')}
<img src={caretSort} alt="" /> <img
className="cursor-pointer"
onClick={() => refreshDocs('tokens')}
src={caretSort}
alt="sort"
/>
</div> </div>
</th> </th>
<th> <th>
<div className="flex justify-center items-center"> <div className="flex justify-center items-center">
{t('settings.documents.type')} {t('settings.documents.type')}
<img src={caretSort} alt="" />
</div> </div>
</th> </th>
<th></th> <th></th>