feat: added advanced search and topic support for Tavily

This commit is contained in:
AnotiaWang
2025-02-20 14:53:42 +08:00
parent 599515e52e
commit 0ad5316249
5 changed files with 41 additions and 3 deletions

View File

@ -70,6 +70,7 @@
supportsCustomApiBase: true, supportsCustomApiBase: true,
}, },
]) ])
const tavilySearchTopicOptions = ['general', 'news', 'finance']
const selectedAiProvider = computed(() => const selectedAiProvider = computed(() =>
aiProviderOptions.value.find((o) => o.value === config.value.ai.provider), aiProviderOptions.value.find((o) => o.value === config.value.ai.provider),
) )
@ -323,6 +324,27 @@
:step="1" :step="1"
/> />
</UFormField> </UFormField>
<!-- Tavily-specific settings -->
<template v-if="config.webSearch.provider === 'tavily'">
<UFormField
:label="$t('settings.webSearch.providers.tavily.advancedSearch')"
:help="$t('settings.webSearch.providers.tavily.advancedSearchHelp')"
>
<USwitch v-model="config.webSearch.tavilyAdvancedSearch" />
</UFormField>
<UFormField
:label="$t('settings.webSearch.providers.tavily.searchTopic')"
:help="$t('settings.webSearch.providers.tavily.searchTopicHelp')"
>
<USelect
v-model="config.webSearch.tavilySearchTopic"
class="w-30"
:items="tavilySearchTopicOptions"
placeholder="general"
/>
</UFormField>
</template>
</div> </div>
</template> </template>
<template #footer> <template #footer>

View File

@ -47,7 +47,11 @@ export const useWebSearch = (): WebSearchFunction => {
apiKey: config.webSearch.apiKey, apiKey: config.webSearch.apiKey,
}) })
return async (q: string, o: WebSearchOptions) => { return async (q: string, o: WebSearchOptions) => {
const results = await tvly.search(q, o) const results = await tvly.search(q, {
...o,
searchDepth: config.webSearch.tavilyAdvancedSearch ? 'advanced' : 'basic',
topic: config.webSearch.tavilySearchTopic,
})
return results.results return results.results
.filter((x) => !!x?.content && !!x.url) .filter((x) => !!x?.content && !!x.url)
.map((r) => ({ .map((r) => ({

View File

@ -37,7 +37,11 @@
"queryLanguageHelp": "The language of the search query. Useful if you want to get search results in a different language.\nWhen writing conclusions, the AI model will still use the language same as the web UI.", "queryLanguageHelp": "The language of the search query. Useful if you want to get search results in a different language.\nWhen writing conclusions, the AI model will still use the language same as the web UI.",
"providers": { "providers": {
"tavily": { "tavily": {
"help": "Similar to Firecrawl, but provides 1000 free credits / month. Get one API key at {0}." "help": "Similar to Firecrawl, but provides 1000 free credits / month. Get one API key at {0}.",
"advancedSearch": "Advanced Search",
"advancedSearchHelp": "Get higher quality search results. Costs 1 extra credit each time.",
"searchTopic": "Search Topic",
"searchTopicHelp": "Optimize the search for the selected topic with tailored and curated information. Defaults to 'general'."
}, },
"firecrawl": { "firecrawl": {
"help": "Get one API key at {0} if you are using the official service." "help": "Get one API key at {0} if you are using the official service."

View File

@ -40,7 +40,11 @@
"help": "如果你使用的是官方服务,请在 {0} 获取 API key。" "help": "如果你使用的是官方服务,请在 {0} 获取 API key。"
}, },
"tavily": { "tavily": {
"help": "和 Firecrawl 类似,不过提供了每月 1000 次免费搜索。在 {0} 获取一个 API key。" "help": "和 Firecrawl 类似,不过提供了每月 1000 次免费搜索。在 {0} 获取一个 API key。",
"advancedSearchHelp": "获得更高质量的搜索结果。每次多消耗一个搜索点数 (credit)。",
"searchTopic": "搜索领域",
"advancedSearch": "高质量搜索",
"searchTopicHelp": "搜索特定领域的信息,获得更精确的结果。默认为“通用” (general)。"
} }
}, },
"concurrencyLimit": "并发数", "concurrencyLimit": "并发数",

View File

@ -26,6 +26,10 @@ export interface ConfigWebSearch {
searchLanguage?: Locale searchLanguage?: Locale
/** Limit the number of concurrent tasks globally */ /** Limit the number of concurrent tasks globally */
concurrencyLimit?: number concurrencyLimit?: number
/** Tavily: use advanced search to retrieve higher quality results */
tavilyAdvancedSearch?: boolean
/** Tavily: search topic. Defaults to `general` */
tavilySearchTopic?: 'general' | 'news' | 'finance'
} }
export interface Config { export interface Config {