-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support translating the search question when web search
- Loading branch information
Showing
21 changed files
with
337 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as React from 'react'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; | ||
import { Languages } from 'lucide-react'; | ||
import { useConfigStore } from '@/lib/store/local-store'; | ||
|
||
type Language = { | ||
name: string; | ||
value: string; | ||
}; | ||
|
||
type LanguageSelectionProps = { | ||
type: 'question' | 'answer'; | ||
className?: string; | ||
}; | ||
|
||
const LanguageItem: React.FC<{ language: Language }> = ({ language }) => ( | ||
<SelectItem key={language.value} value={language.value} className="w-full p-2 block"> | ||
<div className="flex w-full justify-between"> | ||
<span className="text-md mr-2">{language.name}</span> | ||
</div> | ||
</SelectItem> | ||
); | ||
|
||
export function LanguageSelection({ type, className }: LanguageSelectionProps) { | ||
const languageMap: Record<string, Language> = { | ||
auto: { | ||
name: type === 'question' ? 'Default' : 'Auto', | ||
value: 'auto', | ||
}, | ||
en: { | ||
name: 'English', | ||
value: 'en', | ||
}, | ||
zh: { | ||
name: '中文', | ||
value: 'zh', | ||
}, | ||
de: { | ||
name: 'Deutsch', | ||
value: 'de', | ||
}, | ||
fr: { | ||
name: 'Français', | ||
value: 'fr', | ||
}, | ||
es: { | ||
name: 'Español', | ||
value: 'es', | ||
}, | ||
ja: { | ||
name: '日本語', | ||
value: 'ja', | ||
}, | ||
ar: { | ||
name: 'العربية', | ||
value: 'ar', | ||
}, | ||
}; | ||
|
||
const { questionLanguage, answerLanguage, setQuestionLanguage, setAnswerLanguage } = useConfigStore(); | ||
|
||
const currentLanguage = type === 'question' ? questionLanguage : answerLanguage; | ||
const setLanguage = type === 'question' ? setQuestionLanguage : setAnswerLanguage; | ||
const selectedLanguage = languageMap[currentLanguage] ?? languageMap['auto']; | ||
const label = type === 'question' ? 'Translate the Question to' : 'Answer Language'; | ||
|
||
return ( | ||
<Select | ||
key={currentLanguage} | ||
value={currentLanguage} | ||
onValueChange={(value) => { | ||
if (value && value !== currentLanguage) { | ||
setLanguage(value); | ||
} | ||
}} | ||
> | ||
<SelectTrigger aria-label={label} className={`focus:ring-0 border-none outline-none ${className}`}> | ||
<SelectValue> | ||
<div className="flex items-center space-x-1"> | ||
<Languages className="h-4 w-4" /> | ||
<span className="font-semibold">{selectedLanguage.name}</span> | ||
</div> | ||
</SelectValue> | ||
</SelectTrigger> | ||
<SelectContent className="w-full"> | ||
{Object.values(languageMap).map((item) => ( | ||
<LanguageItem key={item.value} language={item} /> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
); | ||
} | ||
|
||
export function QuestionLanguageSelection({ className }: { className?: string }) { | ||
return <LanguageSelection type="question" className={className} />; | ||
} | ||
|
||
export function AnswerLanguageSelection({ className }: { className?: string }) { | ||
return <LanguageSelection type="answer" className={className} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from 'react'; | ||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; | ||
import { Label } from '@/components/ui/label'; | ||
import { Switch } from '@/components/ui/switch'; | ||
import { AnswerLanguageSelection, QuestionLanguageSelection } from '@/components/search/language-selection'; | ||
import { useUIStore } from '@/lib/store/local-store'; | ||
import { BookA, BookKey, Map } from 'lucide-react'; | ||
|
||
interface SearchSettingsProps { | ||
open: boolean; | ||
onOpenChange: (open: boolean) => void; | ||
} | ||
|
||
export function SearchSettingsDialog({ open, onOpenChange }: SearchSettingsProps) { | ||
const { showMindMap, setShowMindMap } = useUIStore(); | ||
return ( | ||
<Dialog open={open} onOpenChange={onOpenChange}> | ||
<DialogContent className="max-w-xl mx-auto"> | ||
<DialogHeader> | ||
<DialogTitle>MemFree Search Settings</DialogTitle> | ||
</DialogHeader> | ||
<div className="space-y-8 py-4"> | ||
<div className="flex flex-col space-y-2"> | ||
<div className="flex items-center gap-2"> | ||
<BookA className="h-4 w-4" /> | ||
<Label className="text-sm font-bold">Translate question to target language when web search </Label> | ||
</div> | ||
<QuestionLanguageSelection className="w-1/3" /> | ||
</div> | ||
|
||
<div className="flex flex-col space-y-2"> | ||
<div className="flex items-center gap-2"> | ||
<BookKey className="h-4 w-4" /> | ||
<Label className="text-sm font-bold">Answer Language</Label> | ||
</div> | ||
<AnswerLanguageSelection className="w-1/3" /> | ||
</div> | ||
|
||
<div className="flex flex-col space-y-4"> | ||
<div className="flex items-center gap-2"> | ||
<Map className="h-4 w-4" /> | ||
<Label className="text-sm font-bold">Mind Map</Label> | ||
</div> | ||
<div className="flex items-center space-x-2"> | ||
<Switch id="mindmap" checked={showMindMap} onCheckedChange={setShowMindMap} /> | ||
<Label htmlFor="mindmap">Show Mind Map</Label> | ||
</div> | ||
</div> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.