fix(web-search): polish Keenable provider integration after #1946
Expose optional API key in settings UI, map longer API snippets into Content for RAG, align maxResults fallback with other providers, sync Swagger enum, and add follow-up unit tests.
This commit is contained in:
+4
-2
@@ -18058,7 +18058,8 @@ const docTemplate = `{
|
|||||||
"tavily",
|
"tavily",
|
||||||
"ollama",
|
"ollama",
|
||||||
"baidu",
|
"baidu",
|
||||||
"searxng"
|
"searxng",
|
||||||
|
"keenable"
|
||||||
],
|
],
|
||||||
"x-enum-varnames": [
|
"x-enum-varnames": [
|
||||||
"WebSearchProviderTypeBing",
|
"WebSearchProviderTypeBing",
|
||||||
@@ -18067,7 +18068,8 @@ const docTemplate = `{
|
|||||||
"WebSearchProviderTypeTavily",
|
"WebSearchProviderTypeTavily",
|
||||||
"WebSearchProviderTypeOllama",
|
"WebSearchProviderTypeOllama",
|
||||||
"WebSearchProviderTypeBaidu",
|
"WebSearchProviderTypeBaidu",
|
||||||
"WebSearchProviderTypeSearxng"
|
"WebSearchProviderTypeSearxng",
|
||||||
|
"WebSearchProviderTypeKeenable"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"github_com_Tencent_WeKnora_internal_types.WikiConfig": {
|
"github_com_Tencent_WeKnora_internal_types.WikiConfig": {
|
||||||
|
|||||||
+4
-2
@@ -18051,7 +18051,8 @@
|
|||||||
"tavily",
|
"tavily",
|
||||||
"ollama",
|
"ollama",
|
||||||
"baidu",
|
"baidu",
|
||||||
"searxng"
|
"searxng",
|
||||||
|
"keenable"
|
||||||
],
|
],
|
||||||
"x-enum-varnames": [
|
"x-enum-varnames": [
|
||||||
"WebSearchProviderTypeBing",
|
"WebSearchProviderTypeBing",
|
||||||
@@ -18060,7 +18061,8 @@
|
|||||||
"WebSearchProviderTypeTavily",
|
"WebSearchProviderTypeTavily",
|
||||||
"WebSearchProviderTypeOllama",
|
"WebSearchProviderTypeOllama",
|
||||||
"WebSearchProviderTypeBaidu",
|
"WebSearchProviderTypeBaidu",
|
||||||
"WebSearchProviderTypeSearxng"
|
"WebSearchProviderTypeSearxng",
|
||||||
|
"WebSearchProviderTypeKeenable"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"github_com_Tencent_WeKnora_internal_types.WikiConfig": {
|
"github_com_Tencent_WeKnora_internal_types.WikiConfig": {
|
||||||
|
|||||||
@@ -3459,6 +3459,7 @@ definitions:
|
|||||||
- ollama
|
- ollama
|
||||||
- baidu
|
- baidu
|
||||||
- searxng
|
- searxng
|
||||||
|
- keenable
|
||||||
type: string
|
type: string
|
||||||
x-enum-varnames:
|
x-enum-varnames:
|
||||||
- WebSearchProviderTypeBing
|
- WebSearchProviderTypeBing
|
||||||
@@ -3468,6 +3469,7 @@ definitions:
|
|||||||
- WebSearchProviderTypeOllama
|
- WebSearchProviderTypeOllama
|
||||||
- WebSearchProviderTypeBaidu
|
- WebSearchProviderTypeBaidu
|
||||||
- WebSearchProviderTypeSearxng
|
- WebSearchProviderTypeSearxng
|
||||||
|
- WebSearchProviderTypeKeenable
|
||||||
github_com_Tencent_WeKnora_internal_types.WikiConfig:
|
github_com_Tencent_WeKnora_internal_types.WikiConfig:
|
||||||
properties:
|
properties:
|
||||||
extraction_granularity:
|
extraction_granularity:
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export interface WebSearchProviderTypeInfo {
|
|||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
requires_api_key: boolean
|
requires_api_key: boolean
|
||||||
|
// Keyless-by-default providers that still accept an optional key (e.g. Keenable).
|
||||||
|
supports_optional_api_key?: boolean
|
||||||
requires_engine_id?: boolean
|
requires_engine_id?: boolean
|
||||||
requires_base_url?: boolean
|
requires_base_url?: boolean
|
||||||
supports_proxy?: boolean
|
supports_proxy?: boolean
|
||||||
|
|||||||
@@ -1476,6 +1476,7 @@ export default {
|
|||||||
proxyUrlPlaceholder: 'e.g. http://proxy.example.com:3128 (optional; http/https only)',
|
proxyUrlPlaceholder: 'e.g. http://proxy.example.com:3128 (optional; http/https only)',
|
||||||
proxyUrlHelp: 'Use when outbound access to the search API requires a proxy; leave empty to rely on HTTP_PROXY/HTTPS_PROXY environment variables.',
|
proxyUrlHelp: 'Use when outbound access to the search API requires a proxy; leave empty to rely on HTTP_PROXY/HTTPS_PROXY environment variables.',
|
||||||
apiKeyLabel: 'API Key',
|
apiKeyLabel: 'API Key',
|
||||||
|
apiKeyOptionalLabel: 'API Key (optional)',
|
||||||
baseUrlLabel: 'Instance URL',
|
baseUrlLabel: 'Instance URL',
|
||||||
baseUrlPlaceholder: 'https://searxng.example.com',
|
baseUrlPlaceholder: 'https://searxng.example.com',
|
||||||
apiKeyDescription: 'Enter the API key for the selected search provider',
|
apiKeyDescription: 'Enter the API key for the selected search provider',
|
||||||
|
|||||||
@@ -1324,6 +1324,7 @@ export default {
|
|||||||
proxyUrlPlaceholder: "예: http://127.0.0.1:7890 (선택 사항)",
|
proxyUrlPlaceholder: "예: http://127.0.0.1:7890 (선택 사항)",
|
||||||
proxyUrlHelp: "검색 API 접근에 프록시가 필요한 경우 입력합니다. 비우면 HTTP_PROXY/HTTPS_PROXY를 사용합니다.",
|
proxyUrlHelp: "검색 API 접근에 프록시가 필요한 경우 입력합니다. 비우면 HTTP_PROXY/HTTPS_PROXY를 사용합니다.",
|
||||||
apiKeyLabel: "API 키",
|
apiKeyLabel: "API 키",
|
||||||
|
apiKeyOptionalLabel: "API 키 (선택 사항)",
|
||||||
baseUrlLabel: "인스턴스 URL",
|
baseUrlLabel: "인스턴스 URL",
|
||||||
baseUrlPlaceholder: "https://searxng.example.com",
|
baseUrlPlaceholder: "https://searxng.example.com",
|
||||||
apiKeyDescription: "선택한 검색 엔진의 API 키 입력",
|
apiKeyDescription: "선택한 검색 엔진의 API 키 입력",
|
||||||
|
|||||||
@@ -1383,6 +1383,7 @@ export default {
|
|||||||
proxyUrlPlaceholder: 'Напр. http://127.0.0.1:7890 (необязательно)',
|
proxyUrlPlaceholder: 'Напр. http://127.0.0.1:7890 (необязательно)',
|
||||||
proxyUrlHelp: 'Укажите, если доступ к API поиска нужен через прокси; иначе используются переменные HTTP_PROXY/HTTPS_PROXY.',
|
proxyUrlHelp: 'Укажите, если доступ к API поиска нужен через прокси; иначе используются переменные HTTP_PROXY/HTTPS_PROXY.',
|
||||||
apiKeyLabel: 'API-ключ',
|
apiKeyLabel: 'API-ключ',
|
||||||
|
apiKeyOptionalLabel: 'API-ключ (необязательно)',
|
||||||
baseUrlLabel: 'URL экземпляра',
|
baseUrlLabel: 'URL экземпляра',
|
||||||
baseUrlPlaceholder: 'https://searxng.example.com',
|
baseUrlPlaceholder: 'https://searxng.example.com',
|
||||||
apiKeyDescription: 'Введите API-ключ выбранного провайдера поиска',
|
apiKeyDescription: 'Введите API-ключ выбранного провайдера поиска',
|
||||||
|
|||||||
@@ -1334,6 +1334,7 @@ export default {
|
|||||||
proxyUrlPlaceholder: "例如 http://proxy.example.com:3128(可选,仅支持 http/https)",
|
proxyUrlPlaceholder: "例如 http://proxy.example.com:3128(可选,仅支持 http/https)",
|
||||||
proxyUrlHelp: "若环境访问搜索 API 需代理,在此填写;留空则使用系统环境变量 HTTP(S)_PROXY。",
|
proxyUrlHelp: "若环境访问搜索 API 需代理,在此填写;留空则使用系统环境变量 HTTP(S)_PROXY。",
|
||||||
apiKeyLabel: "API 密钥",
|
apiKeyLabel: "API 密钥",
|
||||||
|
apiKeyOptionalLabel: "API 密钥(可选)",
|
||||||
baseUrlLabel: "实例地址",
|
baseUrlLabel: "实例地址",
|
||||||
baseUrlPlaceholder: "https://searxng.example.com",
|
baseUrlPlaceholder: "https://searxng.example.com",
|
||||||
apiKeyDescription: "输入所选搜索引擎的 API 密钥",
|
apiKeyDescription: "输入所选搜索引擎的 API 密钥",
|
||||||
|
|||||||
@@ -206,7 +206,7 @@
|
|||||||
|
|
||||||
<!-- Section 2 — 连接配置(base url / api key / engine id),仅当任意字段需要时渲染 -->
|
<!-- Section 2 — 连接配置(base url / api key / engine id),仅当任意字段需要时渲染 -->
|
||||||
<section
|
<section
|
||||||
v-if="selectedProviderType?.requires_api_key || selectedProviderType?.requires_engine_id || selectedProviderType?.requires_base_url"
|
v-if="selectedProviderType?.requires_api_key || selectedProviderType?.supports_optional_api_key || selectedProviderType?.requires_engine_id || selectedProviderType?.requires_base_url"
|
||||||
class="setting-drawer__section"
|
class="setting-drawer__section"
|
||||||
>
|
>
|
||||||
<h4 class="setting-drawer__section-title">{{ t('webSearchSettings.credentialsSection', '连接配置') }}</h4>
|
<h4 class="setting-drawer__section-title">{{ t('webSearchSettings.credentialsSection', '连接配置') }}</h4>
|
||||||
@@ -224,8 +224,12 @@
|
|||||||
子资源调用),不与本表单 submit 耦合;Create 模式下用 plain
|
子资源调用),不与本表单 submit 耦合;Create 模式下用 plain
|
||||||
password input + lock prefix-icon,与 ModelEditorDialog 一致。
|
password input + lock prefix-icon,与 ModelEditorDialog 一致。
|
||||||
-->
|
-->
|
||||||
<div v-if="selectedProviderType?.requires_api_key" class="form-item">
|
<div v-if="selectedProviderType?.requires_api_key || selectedProviderType?.supports_optional_api_key" class="form-item">
|
||||||
<label class="form-label required">{{ t('webSearchSettings.apiKeyLabel') }}</label>
|
<label class="form-label" :class="{ required: selectedProviderType?.requires_api_key }">
|
||||||
|
{{ selectedProviderType?.supports_optional_api_key && !selectedProviderType?.requires_api_key
|
||||||
|
? t('webSearchSettings.apiKeyOptionalLabel', 'API Key(可选)')
|
||||||
|
: t('webSearchSettings.apiKeyLabel') }}
|
||||||
|
</label>
|
||||||
<CredentialResource
|
<CredentialResource
|
||||||
v-if="editingProvider?.id"
|
v-if="editingProvider?.id"
|
||||||
:api="credentialApi"
|
:api="credentialApi"
|
||||||
@@ -847,6 +851,10 @@ onMounted(async () => {
|
|||||||
background: rgba(70, 70, 70, 0.12);
|
background: rgba(70, 70, 70, 0.12);
|
||||||
color: #464646;
|
color: #464646;
|
||||||
}
|
}
|
||||||
|
.provider-card--keenable .provider-card__badge {
|
||||||
|
background: rgba(20, 158, 130, 0.12);
|
||||||
|
color: #149E82;
|
||||||
|
}
|
||||||
|
|
||||||
.provider-card__body {
|
.provider-card__body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@@ -1121,4 +1129,8 @@ onMounted(async () => {
|
|||||||
background: rgba(70, 70, 70, 0.12);
|
background: rgba(70, 70, 70, 0.12);
|
||||||
color: #464646;
|
color: #464646;
|
||||||
}
|
}
|
||||||
|
.websearch-drawer--keenable .setting-drawer__header-icon {
|
||||||
|
background: rgba(20, 158, 130, 0.12);
|
||||||
|
color: #149E82;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ const (
|
|||||||
defaultKeenableBaseURL = "https://api.keenable.ai"
|
defaultKeenableBaseURL = "https://api.keenable.ai"
|
||||||
// keenableTitle is the attribution tag Keenable segments integration traffic by.
|
// keenableTitle is the attribution tag Keenable segments integration traffic by.
|
||||||
keenableTitle = "WeKnora"
|
keenableTitle = "WeKnora"
|
||||||
|
// defaultKeenableResults matches the fallback other providers use when the
|
||||||
|
// caller does not specify a positive maxResults.
|
||||||
|
defaultKeenableResults = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -64,6 +67,9 @@ func (p *KeenableProvider) Search(
|
|||||||
if len(query) == 0 {
|
if len(query) == 0 {
|
||||||
return nil, fmt.Errorf("query is empty")
|
return nil, fmt.Errorf("query is empty")
|
||||||
}
|
}
|
||||||
|
if maxResults <= 0 {
|
||||||
|
maxResults = defaultKeenableResults
|
||||||
|
}
|
||||||
|
|
||||||
// Keyless by default; a configured key switches to the authenticated path.
|
// Keyless by default; a configured key switches to the authenticated path.
|
||||||
path := "/v1/search/public"
|
path := "/v1/search/public"
|
||||||
@@ -116,10 +122,19 @@ func (p *KeenableProvider) Search(
|
|||||||
if maxResults > 0 && len(results) >= maxResults {
|
if maxResults > 0 && len(results) >= maxResults {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// Keenable returns both a short "description" and a longer "snippet"
|
||||||
|
// excerpt. Prefer the short description as the summary snippet and keep
|
||||||
|
// the longer excerpt as Content (used by RAG compression). Fall back to
|
||||||
|
// whichever is present so we never drop the only available text.
|
||||||
|
snippet := item.Description
|
||||||
|
if snippet == "" {
|
||||||
|
snippet = item.Snippet
|
||||||
|
}
|
||||||
result := &types.WebSearchResult{
|
result := &types.WebSearchResult{
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
URL: item.URL,
|
URL: item.URL,
|
||||||
Snippet: item.Description,
|
Snippet: snippet,
|
||||||
|
Content: item.Snippet,
|
||||||
Source: "keenable",
|
Source: "keenable",
|
||||||
}
|
}
|
||||||
if includeDate && item.PublishedAt != "" {
|
if includeDate && item.PublishedAt != "" {
|
||||||
@@ -146,6 +161,7 @@ type keenableSearchResponse struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
Snippet string `json:"snippet,omitempty"`
|
||||||
PublishedAt string `json:"published_at,omitempty"`
|
PublishedAt string `json:"published_at,omitempty"`
|
||||||
AcquiredAt string `json:"acquired_at,omitempty"`
|
AcquiredAt string `json:"acquired_at,omitempty"`
|
||||||
} `json:"results"`
|
} `json:"results"`
|
||||||
|
|||||||
@@ -62,6 +62,38 @@ func TestKeenableProvider_Search_Keyless(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeenableProvider_Search_SnippetMapping(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||||
|
"results": []map[string]any{
|
||||||
|
// Has both: description is the short summary, snippet the longer excerpt.
|
||||||
|
{"title": "T1", "url": "https://e/1", "description": "short", "snippet": "long excerpt"},
|
||||||
|
// Only snippet present: it must fall back into Snippet so we don't drop text.
|
||||||
|
{"title": "T2", "url": "https://e/2", "snippet": "only long"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
p := &KeenableProvider{client: srv.Client(), baseURL: srv.URL}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
results, err := p.Search(ctx, "q", 5, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search: %v", err)
|
||||||
|
}
|
||||||
|
if len(results) != 2 {
|
||||||
|
t.Fatalf("expected 2 results, got %d", len(results))
|
||||||
|
}
|
||||||
|
if results[0].Snippet != "short" || results[0].Content != "long excerpt" {
|
||||||
|
t.Errorf("result[0] snippet/content mapping wrong: %+v", results[0])
|
||||||
|
}
|
||||||
|
if results[1].Snippet != "only long" {
|
||||||
|
t.Errorf("result[1] should fall back to snippet when description is empty: %+v", results[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestKeenableProvider_Search_Keyed(t *testing.T) {
|
func TestKeenableProvider_Search_Keyed(t *testing.T) {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// A configured key => authenticated endpoint + X-API-Key.
|
// A configured key => authenticated endpoint + X-API-Key.
|
||||||
|
|||||||
@@ -52,6 +52,20 @@ func TestEmptyTestResultsError_DuckDuckGo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyTestResultsError_Keenable(t *testing.T) {
|
||||||
|
err := EmptyTestResultsError(string(types.WebSearchProviderTypeKeenable), nil)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
msg := err.Error()
|
||||||
|
if !strings.Contains(msg, "keenable returned 0 results") {
|
||||||
|
t.Fatalf("unexpected message: %q", msg)
|
||||||
|
}
|
||||||
|
if !strings.Contains(msg, "rate-limited") {
|
||||||
|
t.Fatalf("keenable message should hint at the keyless rate limit: %q", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmptyTestResultsError_APIKeyProviders(t *testing.T) {
|
func TestEmptyTestResultsError_APIKeyProviders(t *testing.T) {
|
||||||
err := EmptyTestResultsError(string(types.WebSearchProviderTypeBing), nil)
|
err := EmptyTestResultsError(string(types.WebSearchProviderTypeBing), nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ type WebSearchProviderTypeInfo struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
// Whether the provider requires an API key
|
// Whether the provider requires an API key
|
||||||
RequiresAPIKey bool `json:"requires_api_key"`
|
RequiresAPIKey bool `json:"requires_api_key"`
|
||||||
|
// Whether the provider accepts an optional API key (keyless by default, but a
|
||||||
|
// key unlocks higher limits — e.g. Keenable). Mutually exclusive with RequiresAPIKey.
|
||||||
|
SupportsOptionalAPIKey bool `json:"supports_optional_api_key,omitempty"`
|
||||||
// Whether the provider requires an engine ID (e.g., Google CSE)
|
// Whether the provider requires an engine ID (e.g., Google CSE)
|
||||||
RequiresEngineID bool `json:"requires_engine_id"`
|
RequiresEngineID bool `json:"requires_engine_id"`
|
||||||
// Whether the provider requires a user-supplied base URL (e.g., self-hosted SearXNG instance)
|
// Whether the provider requires a user-supplied base URL (e.g., self-hosted SearXNG instance)
|
||||||
@@ -200,12 +203,13 @@ func GetWebSearchProviderTypes() []WebSearchProviderTypeInfo {
|
|||||||
DocsURL: "https://cloud.baidu.com/doc/AppBuilder/s/qlvEcai0p",
|
DocsURL: "https://cloud.baidu.com/doc/AppBuilder/s/qlvEcai0p",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "keenable",
|
ID: "keenable",
|
||||||
Name: "Keenable",
|
Name: "Keenable",
|
||||||
RequiresAPIKey: false,
|
RequiresAPIKey: false,
|
||||||
SupportsProxy: true,
|
SupportsOptionalAPIKey: true,
|
||||||
Description: "Keenable web search built for AI agents (keyless by default; an optional API key lifts the rate limit)",
|
SupportsProxy: true,
|
||||||
DocsURL: "https://keenable.ai/",
|
Description: "Keenable web search built for AI agents (keyless by default; an optional API key lifts the rate limit)",
|
||||||
|
DocsURL: "https://keenable.ai/",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user