
    Ng?                         d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ  G d de
          Z G d d	e
          Zd
S )zTool for the Bing search API.    )DictListLiteralOptionalTuple)CallbackManagerForToolRun)BaseTool)BingSearchAPIWrapperc                   ^    e Zd ZU dZdZeed<   dZeed<   eed<   	 dded	e	e
         d
efdZdS )BingSearchRunz&Tool that queries the Bing search API.bing_searchnamezA wrapper around Bing Search. Useful for when you need to answer questions about current events. Input should be a search query.descriptionapi_wrapperNqueryrun_managerreturnc                 6    | j                             |          S )Use the tool.)r   run)selfr   r   s      f/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/bing_search/tool.py_runzBingSearchRun._run   s     ##E***    N)__name__
__module____qualname____doc__r   str__annotations__r   r
   r   r   r    r   r   r   r      s         00D#	*    
 &%%%
 <@+ ++ 78+ 
	+ + + + + +r   r   c            
           e Zd ZU dZdZeed<   dZeed<   dZe	ed<   	 e
ed<   d	Zed	         ed
<   	 ddedee         deeee         f         fdZdS )BingSearchResultsuO  Bing Search tool.

    Setup:
        Install ``langchain-community`` and set environment variable ``BING_SUBSCRIPTION_KEY``.

        .. code-block:: bash

            pip install -U langchain-community
            export BING_SUBSCRIPTION_KEY="your-api-key"

    Instantiation:
        .. code-block:: python

            from langchain_community.tools.bing_search import BingSearchResults
            from langchain_community.utilities import BingSearchAPIWrapper

            api_wrapper = BingSearchAPIWrapper()
            tool = BingSearchResults(api_wrapper=api_wrapper)

    Invocation with args:
        .. code-block:: python

            tool.invoke({"query": "what is the weather in SF?"})

        .. code-block:: python

            "[{'snippet': '<b>San Francisco, CA</b> <b>Weather</b> Forecast, with current conditions, wind, air quality, and what to expect for the next 3 days.', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}, {'snippet': 'Everything you need to know about today&#39;s <b>weather</b> <b>in San Francisco, CA</b>. High/Low, Precipitation Chances, Sunrise/Sunset, and today&#39;s Temperature History.', 'title': 'Weather Today for San Francisco, CA | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-today/347629'}]"

    Invocation with ToolCall:

        .. code-block:: python

            tool.invoke({"args": {"query":"what is the weather in SF?"}, "id": "1", "name": tool.name, "type": "tool_call"})

        .. code-block:: python

            ToolMessage(
                content="[{'snippet': 'Get the latest <b>weather</b> forecast for <b>San Francisco, CA</b>, including temperature, RealFeel, and chance of precipitation. Find out how the <b>weather</b> will affect your plans and activities in the city of ...', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Radar. Be prepared with the most accurate 10-day forecast for <b>San Francisco, CA</b> with highs, lows, chance of precipitation from The <b>Weather</b> Channel and <b>Weather</b>.com.', 'title': '10-Day Weather Forecast for San Francisco, CA - The Weather Channel', 'link': 'https://weather.com/weather/tenday/l/San+Francisco+CA+USCA0987:1:US'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}]",
                artifact=[{'snippet': 'Get the latest <b>weather</b> forecast for <b>San Francisco, CA</b>, including temperature, RealFeel, and chance of precipitation. Find out how the <b>weather</b> will affect your plans and activities in the city of ...', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Radar. Be prepared with the most accurate 10-day forecast for <b>San Francisco, CA</b> with highs, lows, chance of precipitation from The <b>Weather</b> Channel and <b>Weather</b>.com.', 'title': '10-Day Weather Forecast for San Francisco, CA - The Weather Channel', 'link': 'https://weather.com/weather/tenday/l/San+Francisco+CA+USCA0987:1:US'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}],
                name='bing_search_results_json',
                tool_call_id='1'
            )

    bing_search_results_jsonr   zA wrapper around Bing Search. Useful for when you need to answer questions about current events. Input should be a search query. Output is an array of the query results.r      num_resultsr   content_and_artifactresponse_formatNr   r   r   c                     	 | j                             || j                  }t          |          |fS # t          $ r}t          |          g fcY d}~S d}~ww xY w)r   N)r   resultsr'   r    	Exceptionrepr)r   r   r   r+   es        r   r   zBingSearchResults._runX   sq    	&..ud6FGGGw<<(( 	 	 	77B;	s   03 
AAAAr   )r   r   r   r   r   r    r!   r   r'   intr
   r)   r   r   r   r   r   r   r   r"   r   r   r$   r$      s         + +Z +D#***	S    
 K5%%%%7MOW34MMM
 <@
 

 78
 
sDJ		
 
 
 
 
 
r   r$   N)r   typingr   r   r   r   r   langchain_core.callbacksr   langchain_core.toolsr	   )langchain_community.utilities.bing_searchr
   r   r$   r"   r   r   <module>r4      s    # # 7 7 7 7 7 7 7 7 7 7 7 7 7 7 > > > > > > ) ) ) ) ) ) J J J J J J+ + + + +H + + +(C C C C C C C C C Cr   