Skip to content

Commit

Permalink
feat: Add Tavily dark mode logo and improve web search settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Feb 23, 2025
1 parent fb6b0b0 commit c354537
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
14 changes: 14 additions & 0 deletions src/renderer/src/assets/images/search/tavily-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/src/i18n/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@
"tray.title": "启用系统托盘图标",
"websearch": {
"title": "网络搜索",
"get_api_key": "点击这里获取 API 密钥",
"get_api_key": "点击这里获取密钥",
"tavily": {
"title": "Tavily",
"description": "Tavily 是一个集成了多个搜索引擎的网络搜索工具,支持多种语言和多种搜索引擎。",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/i18n/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@
"tray.title": "啟用系統托盤圖標",
"websearch": {
"title": "網路搜索",
"get_api_key": "點擊這裡獲取 API 密鑰",
"get_api_key": "點擊這裡獲取密鑰",
"tavily": {
"title": "Tavily",
"description": "Tavily 是一個集成了多個搜索引擎的網路搜索工具,支持多種語言和多種搜索引擎。",
Expand Down
32 changes: 20 additions & 12 deletions src/renderer/src/pages/home/Inputbar/Inputbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@ant-design/icons'
import { PicCenterOutlined } from '@ant-design/icons'
import TranslateButton from '@renderer/components/TranslateButton'
import { isVisionModel } from '@renderer/config/models'
import { isVisionModel, isWebSearchModel } from '@renderer/config/models'
import db from '@renderer/databases'
import { useAssistant } from '@renderer/hooks/useAssistant'
import { modelGenerating, useRuntime } from '@renderer/hooks/useRuntime'
Expand Down Expand Up @@ -501,22 +501,30 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
}

const onEnableWebSearch = () => {
if (!WebSearchService.isWebSearchEnabled()) {
window.modal.confirm({
title: t('chat.input.web_search.enable'),
content: t('chat.input.web_search.enable_content'),
centered: true,
okText: t('chat.input.web_search.button.ok'),
onOk: () => {
navigate('/settings/web-search')
}
})
return
if (!isWebSearchModel(model)) {
if (!WebSearchService.isWebSearchEnabled()) {
window.modal.confirm({
title: t('chat.input.web_search.enable'),
content: t('chat.input.web_search.enable_content'),
centered: true,
okText: t('chat.input.web_search.button.ok'),
onOk: () => {
navigate('/settings/web-search')
}
})
return
}
}

updateAssistant({ ...assistant, enableWebSearch: !assistant.enableWebSearch })
}

useEffect(() => {
if (!isWebSearchModel(model) && !WebSearchService.isWebSearchEnabled() && assistant.enableWebSearch) {
updateAssistant({ ...assistant, enableWebSearch: false })
}
}, [assistant, model, updateAssistant])

return (
<Container onDragOver={handleDragOver} onDrop={handleDrop} className="inputbar">
<NarrowLayout style={{ width: '100%' }}>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/pages/home/Messages/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const Favicon = styled.img`
width: 16px;
height: 16px;
border-radius: 4px;
background-color: var(--color-background-mute);
`

export default React.memo(MessageContent)
1 change: 1 addition & 0 deletions src/renderer/src/pages/settings/ProviderSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const Container = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 2px 0;
`

const ProviderListContainer = styled.div`
Expand Down
18 changes: 10 additions & 8 deletions src/renderer/src/pages/settings/WebSearchSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tavilyLogo from '@renderer/assets/images/search/tavily.svg'
import tavilyLogoDark from '@renderer/assets/images/search/tavily-dark.svg'
import { HStack } from '@renderer/components/Layout'
import { useTheme } from '@renderer/context/ThemeProvider'
import { useWebSearchProvider } from '@renderer/hooks/useWebSearchProviders'
Expand All @@ -7,7 +8,7 @@ import { FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'

import { SettingContainer, SettingGroup, SettingHelpLink, SettingHelpTextRow } from '.'
import { SettingContainer, SettingDivider, SettingGroup, SettingHelpLink, SettingHelpTextRow } from '.'

const WebSearchSettings: FC = () => {
const { t } = useTranslation()
Expand All @@ -16,6 +17,8 @@ const WebSearchSettings: FC = () => {
const { provider, updateProvider } = useWebSearchProvider('tavily')
const [apiKey, setApiKey] = useState(provider.apiKey)

const logo = theme === 'dark' ? tavilyLogoDark : tavilyLogo

useEffect(() => {
return () => {
console.log('apiKey', apiKey, provider.apiKey)
Expand All @@ -29,8 +32,9 @@ const WebSearchSettings: FC = () => {
<SettingContainer theme={theme}>
<SettingGroup theme={theme}>
<HStack alignItems="center" gap={10}>
<TavilyLogo src={tavilyLogo} alt="web-search" style={{ width: '60px' }} />
<TavilyLogo src={logo} alt="web-search" style={{ width: '60px' }} />
</HStack>
<SettingDivider />
<Paragraph type="secondary" style={{ margin: '10px 0' }}>
{t('settings.websearch.tavily.description')}
</Paragraph>
Expand All @@ -41,12 +45,10 @@ const WebSearchSettings: FC = () => {
onChange={(e) => setApiKey(e.target.value)}
onBlur={() => updateProvider({ ...provider, apiKey })}
/>
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
<HStack gap={5}>
<SettingHelpLink target="_blank" href="https://app.tavily.com/home">
{t('settings.websearch.get_api_key')}
</SettingHelpLink>
</HStack>
<SettingHelpTextRow style={{ justifyContent: 'space-between', marginTop: 5 }}>
<SettingHelpLink target="_blank" href="https://app.tavily.com/home">
{t('settings.websearch.get_api_key')}
</SettingHelpLink>
</SettingHelpTextRow>
</SettingGroup>
</SettingContainer>
Expand Down

0 comments on commit c354537

Please sign in to comment.