langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
44.34k stars 6.21k forks source link

Bing search tool always add entities to responseFilter #5922

Closed qkxie closed 2 weeks ago

qkxie commented 2 months ago

Self Checks

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Use Bing search tool

✔️ Expected Behavior

answer search result.

❌ Actual Behavior

image image

In Bing search tool, I only choose webpage to search, but the api request always add entities to responseFilter, this make my api call error. Because my Bing API subscribtion doesn't include entities search, so responseFilter should not include entities

dosubot[bot] commented 2 months ago

@qkxie Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you.

To resolve the issue with the Bing search tool in Dify version 0.6.11, you need to ensure that the enable_entities parameter is set to false in the tool parameters. This will prevent the inclusion of "Entities" in the responseFilter parameter, avoiding the 403 error due to insufficient authorization for entity search.

Here is how you can configure the tool parameters:

tool_parameters:
  enable_entities: false
  enable_computation: true
  enable_news: true
  enable_related_search: true
  enable_webpages: true

In the bing_web_search.py file, the validate_credentials and _invoke methods check the enable_entities parameter and include "Entities" in the responseFilter only if it is set to true. By setting enable_entities to false, you ensure that "Entities" is not included in the responseFilter.

Here is the relevant section of the bing_web_search.py file:

def validate_credentials(self, credentials: dict[str, Any], tool_parameters: dict[str, Any]) -> None:
    # ... other code ...
    filter = []

    if tool_parameters.get('enable_computation', False):
        filter.append('Computation')
    if tool_parameters.get('enable_entities', False):
        filter.append('Entities')
    if tool_parameters.get('enable_news', False):
        filter.append('News')
    if tool_parameters.get('enable_related_search', False):
        filter.append('RelatedSearches')
    if tool_parameters.get('enable_webpages', False):
        filter.append('WebPages')

    if not filter:
        raise Exception('At least one filter is required')

    self._invoke_bing(
        user_id='test',
        server_url=server_url,
        subscription_key=key,
        query=query,
        limit=limit,
        result_type=result_type,
        market=market,
        lang=lang,
        filters=filter
    )

Make sure to update your tool parameters accordingly to disable entity search and avoid the 403 error [1][2].

To continue talking to Dosu, mention @dosu.

qkxie commented 2 months ago

I have already make sure that enable_entities ui false

image

qkxie commented 2 months ago

Now I have to fix the code of dify/api/core/tools/provider/builtin/bing/tools/tools/bing_web_search.py

keita69 commented 2 months ago

In 0.6.12-fix, it is expected to work properly only if the FEATURES of the Bing Search API v7 Pricing Details include "Bing Entity Search".

In other words, it is expected to work properly if the INSTANCE of the Bing Search API v7 Pricing Details is as follows: