š« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
Update weather function API by using pyowm (#334)
Ziyi Yanga8639ac96cc1
diff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.ymlindex 883fe859c..2ae343a74 100644--- a/.github/workflows/pytest_package.yml+++ b/.github/workflows/pytest_package.yml@@ -27,6 +27,7 @@ jobs:OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"GOOGLE_API_KEY: "${{ secrets.GOOGLE_API_KEY }}"SEARCH_ENGINE_ID: "${{ secrets.SEARCH_ENGINE_ID }}"+ OPENWEATHERMAP_API_KEY: "${{ secrets.OPENWEATHERMAP_API_KEY }}"run: poetry run pytest --fast-test-mode test/pytest_package_llm_test:@@ -42,6 +43,7 @@ jobs:OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"GOOGLE_API_KEY: "${{ secrets.GOOGLE_API_KEY }}"SEARCH_ENGINE_ID: "${{ secrets.SEARCH_ENGINE_ID }}"+ OPENWEATHERMAP_API_KEY: "${{ secrets.OPENWEATHERMAP_API_KEY }}"run: poetry run pytest --llm-test-only test/pytest_package_very_slow_test:@@ -57,4 +59,5 @@ jobs:OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"GOOGLE_API_KEY: "${{ secrets.GOOGLE_API_KEY }}"SEARCH_ENGINE_ID: "${{ secrets.SEARCH_ENGINE_ID }}"+ OPENWEATHERMAP_API_KEY: "${{ secrets.OPENWEATHERMAP_API_KEY }}"run: poetry run pytest --very-slow-test-only test/diff --git a/camel/functions/__init__.py b/camel/functions/__init__.pyindex be6c8830e..32ec64c61 100644--- a/camel/functions/__init__.py+++ b/camel/functions/__init__.py@@ -12,12 +12,14 @@# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-from .openai_function import OpenAIFunctionfrom .math_functions import MATH_FUNCS+from .openai_function import OpenAIFunctionfrom .search_functions import SEARCH_FUNCS+from .weather_functions import WEATHER_FUNCS__all__ = ['OpenAIFunction','MATH_FUNCS','SEARCH_FUNCS',+ 'WEATHER_FUNCS',]diff --git a/camel/functions/data_io_functions.py b/camel/functions/data_io_functions.pyindex 59db784fe..dbe599489 100644--- a/camel/functions/data_io_functions.py+++ b/camel/functions/data_io_functions.py@@ -19,10 +19,6 @@ from hashlib import md5from io import BytesIOfrom typing import Any, Dict, List, Optional-import docx2txt-import fitz-from bs4 import BeautifulSoup-class File(ABC):r"""Represents an uploaded file comprised of Documents"""@@ -107,6 +103,12 @@ class DocxFile(File):DocxFile: A DocxFile object."""# Use docx2txt to extract text from docx files+ try:+ import docx2txt+ except ImportError:+ raise ImportError("Please install `docx2txt` first. "+ "You can install it by running "+ "`pip install docx2txt`.")text = docx2txt.process(file)text = strip_consecutive_newlines(text)# Create a dictionary with the extracted text@@ -132,6 +134,12 @@ class PdfFile(File):PdfFile: A PdfFile object."""# Use fitz to extract text from pdf files+ try:+ import fitz+ except ImportError:+ raise ImportError("Please install `PyMuPDF` first. "+ "You can install it by running "+ "`pip install PyMuPDF`.")pdf = fitz.open(stream=file.read(), filetype="pdf")docs = []for i, page in enumerate(pdf):@@ -210,6 +218,12 @@ class HtmlFile(File):HtmlFile: A HtmlFile object."""# Parse the HTML data from the file+ try:+ from bs4 import BeautifulSoup+ except ImportError:+ raise ImportError("Please install `beautifulsoup4` first. "+ "You can install it by running "+ "`pip install beautifulsoup4`.")soup = BeautifulSoup(file, "html.parser")text = soup.get_text()text = strip_consecutive_newlines(text)diff --git a/camel/functions/search_functions.py b/camel/functions/search_functions.pyindex a40608255..4047f5327 100644--- a/camel/functions/search_functions.py+++ b/camel/functions/search_functions.py@@ -31,7 +31,13 @@ def search_wiki(entity: str) -> str:string: The search result. If the page corresponding to the entityexists, return the summary of this entity in a string."""- import wikipedia+ try:+ import wikipedia+ except ImportError:+ raise ImportError(+ "Please install `wikipedia` first. You can install it by running "+ "`pip install wikipedia`.")+result: strtry:diff --git a/camel/functions/weather_functions.py b/camel/functions/weather_functions.pynew file mode 100644index 000000000..d86868e20--- /dev/null+++ b/camel/functions/weather_functions.py@@ -0,0 +1,136 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+import os+from typing import List++from camel.functions import OpenAIFunction+++def get_openweathermap_api_key() -> str:+ r"""Retrieve the OpenWeatherMap API key from environment variables.++ Returns:+ str: The OpenWeatherMap API key.++ Raises:+ ValueError: If the API key is not found in the environment variables.+ """+ # Get `OPENWEATHERMAP_API_KEY` here: https://openweathermap.org+ OPENWEATHERMAP_API_KEY = os.environ.get('OPENWEATHERMAP_API_KEY')+ if not OPENWEATHERMAP_API_KEY:+ raise ValueError("`OPENWEATHERMAP_API_KEY` not found in environment "+ "variables. Get `OPENWEATHERMAP_API_KEY` here: "+ "`https://openweathermap.org`.")+ return OPENWEATHERMAP_API_KEY+++def get_weather_data(city: str, temp_units: str = 'kelvin',+ wind_units: str = 'meters_sec',+ visibility_units: str = 'meters',+ time_units: str = 'unix') -> str:+ r"""Fetch and return a comprehensive weather report for a given city as a+ string. The report includes current weather conditions, temperature,+ wind details, visibility, and sunrise/sunset times, all formatted as++ The function interacts with the OpenWeatherMap API to retrieve the data.++ Args:+ city (string): The name of the city for which the weather information+ is desired. Format "City, CountryCode" (e.g., "Paris, FR"+ for Paris, France). If the country code is not provided,+ the API will search for the city in all countries, which+ may yield incorrect results if multiple cities with the+ same name exist.+ temp_units (string): Units for temperature. Options: 'kelvin',+ 'celsius', 'fahrenheit'. (default: :obj:`kelvin`)+ wind_units (string): Units for wind speed. Options: 'meters_sec',+ 'miles_hour', 'knots', 'beaufort'. (default: :obj:`meters_sec`)+ visibility_units (string): Units for visibility distance. Options:+ 'meters', 'miles'. (default: :obj:`meters`)+ time_units (string): Format for sunrise and sunset times. Options:+ 'unix', 'iso', 'date'. (default: :obj:`unix`)++ Returns:+ str: A string containing the fetched weather data, formatted in a+ readable manner. If an error occurs, a message indicating the+ error will be returned instead.++ Example of return string:+ "Weather in Paris, FR: 15°C, feels like 13°C. Max temp: 17°C, Min temp+ : 12°C.+ Wind: 5 m/s at 270 degrees. Visibility: 10 kilometers.+ Sunrise at 05:46:05 (UTC), Sunset at 18:42:20 (UTC)."++ Note:+ Please ensure that the API key is valid and has permissions to access+ the weather data.+ """+ # NOTE: This tool may not work as expected since the input arguments like+ # `time_units` should be enum types which are not supported yet.++ try:+ import pyowm+ except ImportError:+ raise ImportError(+ "Please install `pyowm` first. You can install it by running "+ "`pip install pyowm`.")++ OPENWEATHERMAP_API_KEY = get_openweathermap_api_key()+ owm = pyowm.OWM(OPENWEATHERMAP_API_KEY)+ mgr = owm.weather_manager()++ try:+ observation = mgr.weather_at_place(city)+ weather = observation.weather++ # Temperature+ temperature = weather.temperature(temp_units)++ # Wind+ wind_data = observation.weather.wind(unit=wind_units)+ wind_speed = wind_data.get('speed')+ # 'N/A' if the degree is not available+ wind_deg = wind_data.get('deg', 'N/A')++ # Visibility+ visibility_distance = observation.weather.visibility_distance+ visibility = (str(visibility_distance) if visibility_units == 'meters'+ else str(observation.weather.visibility(unit='miles')))++ # Sunrise and Sunset+ sunrise_time = str(weather.sunrise_time(timeformat=time_units))+ sunset_time = str(weather.sunset_time(timeformat=time_units))++ # Compile all the weather details into a report string+ weather_report = (+ f"Weather in {city}: {temperature['temp']}°{temp_units.title()}, "+ f"feels like {temperature['feels_like']}°{temp_units.title()}. "+ f"Max temp: {temperature['temp_max']}°{temp_units.title()}, "+ f"Min temp: {temperature['temp_min']}°{temp_units.title()}. "+ f"Wind: {wind_speed} {wind_units} at {wind_deg} degrees. "+ f"Visibility: {visibility} {visibility_units}. "+ f"Sunrise at {sunrise_time}, Sunset at {sunset_time}.")++ return weather_report++ except Exception as e:+ error_message = (+ f"An error occurred while fetching weather data for {city}: "+ f"{str(e)}.")+ return error_message+++WEATHER_FUNCS: List[OpenAIFunction] = [+ OpenAIFunction(func) for func in [get_weather_data]+]diff --git a/examples/function_call/role_playing_with_function.py b/examples/function_call/role_playing_with_function.pyindex 57519606a..c402caf37 100644--- a/examples/function_call/role_playing_with_function.py+++ b/examples/function_call/role_playing_with_function.py@@ -17,7 +17,7 @@ from colorama import Forefrom camel.agents.chat_agent import FunctionCallingRecordfrom camel.configs import ChatGPTConfig, FunctionCallingConfig-from camel.functions import MATH_FUNCS, SEARCH_FUNCS+from camel.functions import MATH_FUNCS, SEARCH_FUNCS, WEATHER_FUNCSfrom camel.societies import RolePlayingfrom camel.types import ModelTypefrom camel.utils import print_text_animated@@ -25,11 +25,13 @@ from camel.utils import print_text_animateddef main(model_type=ModelType.GPT_4) -> None:task_prompt = ("Assuming the current year is 2023, estimate KAUST's "- "current age and then add 10 more years to this age.")+ "current age and then add 10 more years to this age, "+ "and get the current weather of the city where KAUST "+ "is located.")user_model_config = ChatGPTConfig(temperature=0.0)- function_list = [*MATH_FUNCS, *SEARCH_FUNCS]+ function_list = [*MATH_FUNCS, *SEARCH_FUNCS, *WEATHER_FUNCS]assistant_model_config = FunctionCallingConfig.from_openai_function_list(function_list=function_list,kwargs=dict(temperature=0.0),diff --git a/poetry.lock b/poetry.lockindex 2342d4357..da65187b5 100644--- a/poetry.lock+++ b/poetry.lock@@ -311,19 +311,6 @@ soupsieve = ">1.2"html5lib = ["html5lib"]lxml = ["lxml"]-[[package]]-name = "bs4"-version = "0.0.1"-description = "Dummy package for Beautiful Soup"-optional = false-python-versions = "*"-files = [- {file = "bs4-0.0.1.tar.gz", hash = "sha256:36ecea1fd7cc5c0c6e4a1ff075df26d50da647b75376626cc186e2212886dd3a"},-]--[package.dependencies]-beautifulsoup4 = "*"-[[package]]name = "certifi"version = "2023.7.22"@@ -562,6 +549,7 @@ files = [{file = "contourpy-1.1.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:18a64814ae7bce73925131381603fff0116e2df25230dfc80d6d690aa6e20b37"},{file = "contourpy-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90c81f22b4f572f8a2110b0b741bb64e5a6427e0a198b2cdc1fbaf85f352a3aa"},{file = "contourpy-1.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:53cc3a40635abedbec7f1bde60f8c189c49e84ac180c665f2cd7c162cc454baa"},+ {file = "contourpy-1.1.0-cp310-cp310-win32.whl", hash = "sha256:9b2dd2ca3ac561aceef4c7c13ba654aaa404cf885b187427760d7f7d4c57cff8"},{file = "contourpy-1.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:1f795597073b09d631782e7245016a4323cf1cf0b4e06eef7ea6627e06a37ff2"},{file = "contourpy-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:0b7b04ed0961647691cfe5d82115dd072af7ce8846d31a5fac6c142dcce8b882"},{file = "contourpy-1.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:27bc79200c742f9746d7dd51a734ee326a292d77e7d94c8af6e08d1e6c15d545"},@@ -570,6 +558,7 @@ files = [{file = "contourpy-1.1.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e5cec36c5090e75a9ac9dbd0ff4a8cf7cecd60f1b6dc23a374c7d980a1cd710e"},{file = "contourpy-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1f0cbd657e9bde94cd0e33aa7df94fb73c1ab7799378d3b3f902eb8eb2e04a3a"},{file = "contourpy-1.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:181cbace49874f4358e2929aaf7ba84006acb76694102e88dd15af861996c16e"},+ {file = "contourpy-1.1.0-cp311-cp311-win32.whl", hash = "sha256:edb989d31065b1acef3828a3688f88b2abb799a7db891c9e282df5ec7e46221b"},{file = "contourpy-1.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:fb3b7d9e6243bfa1efb93ccfe64ec610d85cfe5aec2c25f97fbbd2e58b531256"},{file = "contourpy-1.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bcb41692aa09aeb19c7c213411854402f29f6613845ad2453d30bf421fe68fed"},{file = "contourpy-1.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5d123a5bc63cd34c27ff9c7ac1cd978909e9c71da12e05be0231c608048bb2ae"},@@ -578,6 +567,7 @@ files = [{file = "contourpy-1.1.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:317267d915490d1e84577924bd61ba71bf8681a30e0d6c545f577363157e5e94"},{file = "contourpy-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d551f3a442655f3dcc1285723f9acd646ca5858834efeab4598d706206b09c9f"},{file = "contourpy-1.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:e7a117ce7df5a938fe035cad481b0189049e8d92433b4b33aa7fc609344aafa1"},+ {file = "contourpy-1.1.0-cp38-cp38-win32.whl", hash = "sha256:108dfb5b3e731046a96c60bdc46a1a0ebee0760418951abecbe0fc07b5b93b27"},{file = "contourpy-1.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:d4f26b25b4f86087e7d75e63212756c38546e70f2a92d2be44f80114826e1cd4"},{file = "contourpy-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bc00bb4225d57bff7ebb634646c0ee2a1298402ec10a5fe7af79df9a51c1bfd9"},{file = "contourpy-1.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:189ceb1525eb0655ab8487a9a9c41f42a73ba52d6789754788d1883fb06b2d8a"},@@ -586,6 +576,7 @@ files = [{file = "contourpy-1.1.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:143dde50520a9f90e4a2703f367cf8ec96a73042b72e68fcd184e1279962eb6f"},{file = "contourpy-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e94bef2580e25b5fdb183bf98a2faa2adc5b638736b2c0a4da98691da641316a"},{file = "contourpy-1.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ed614aea8462735e7d70141374bd7650afd1c3f3cb0c2dbbcbe44e14331bf002"},+ {file = "contourpy-1.1.0-cp39-cp39-win32.whl", hash = "sha256:71551f9520f008b2950bef5f16b0e3587506ef4f23c734b71ffb7b89f8721999"},{file = "contourpy-1.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:438ba416d02f82b692e371858143970ed2eb6337d9cdbbede0d8ad9f3d7dd17d"},{file = "contourpy-1.1.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:a698c6a7a432789e587168573a864a7ea374c6be8d4f31f9d87c001d5a843493"},{file = "contourpy-1.1.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:397b0ac8a12880412da3551a8cb5a187d3298a72802b45a3bd1805e204ad8439"},@@ -803,13 +794,13 @@ vision = ["Pillow (>=6.2.1)"][[package]]name = "diffusers"-version = "0.22.3"+version = "0.23.0"description = "State-of-the-art diffusion in PyTorch and JAX."optional = truepython-versions = ">=3.8.0"files = [- {file = "diffusers-0.22.3-py3-none-any.whl", hash = "sha256:fdaf3a4c9c728f7d90796e0e5826286db7c7a2dce0e37c66870aee4cc10a2d75"},- {file = "diffusers-0.22.3.tar.gz", hash = "sha256:47a20e16649899eb302af76e9103536708d57c3acaf7d3ab68e4140af67a17cd"},+ {file = "diffusers-0.23.0-py3-none-any.whl", hash = "sha256:4011e7a29681489e55496350c47ffb940fcfa52771306ae713a5810bf37d6813"},+ {file = "diffusers-0.23.0.tar.gz", hash = "sha256:51310bcdd48ab59dcb6dde904a0c2bb2430c835c6e046e9e36f60a42e03e90d4"},][package.dependencies]@@ -882,7 +873,7 @@ files = [name = "docx2txt"version = "0.8"description = "A pure python-based utility to extract text and images from docx files."-optional = false+optional = truepython-versions = "*"files = [{file = "docx2txt-0.8.tar.gz", hash = "sha256:2c06d98d7cfe2d3947e5760a57d924e3ff07745b379c8737723922e7009236e5"},@@ -1138,6 +1129,17 @@ smb = ["smbprotocol"]ssh = ["paramiko"]tqdm = ["tqdm"]+[[package]]+name = "geojson"+version = "2.5.0"+description = "Python bindings and utilities for GeoJSON"+optional = true+python-versions = "*"+files = [+ {file = "geojson-2.5.0-py2.py3-none-any.whl", hash = "sha256:ccbd13368dd728f4e4f13ffe6aaf725b6e802c692ba0dde628be475040c534ba"},+ {file = "geojson-2.5.0.tar.gz", hash = "sha256:6e4bb7ace4226a45d9c8c8b1348b3fc43540658359f93c3f7e03efa9f15f658a"},+]+[[package]]name = "gradio"version = "3.50.2"@@ -1584,6 +1586,16 @@ files = [{file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"},{file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"},{file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"},+ {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"},{file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"},{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"},{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"},@@ -2651,31 +2663,36 @@ plugins = ["importlib-metadata"]name = "pymupdf"version = "1.23.6"description = "A high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents."-optional = false+optional = truepython-versions = ">=3.8"files = [{file = "PyMuPDF-1.23.6-cp310-none-macosx_10_9_x86_64.whl", hash = "sha256:c4eb71b88a22c1008f764b3121b36a9d25340f9920b870508356050a365d9ca1"},{file = "PyMuPDF-1.23.6-cp310-none-macosx_11_0_arm64.whl", hash = "sha256:3ce2d3678dbf822cff213b1902f2e59756313e543efd516a2b4f15bb0353bd6c"},+ {file = "PyMuPDF-1.23.6-cp310-none-manylinux2014_aarch64.whl", hash = "sha256:2e27857a15c8a810d0b66455b8c8a79013640b6267a9b4ea808a5fe1f47711f2"},{file = "PyMuPDF-1.23.6-cp310-none-manylinux2014_x86_64.whl", hash = "sha256:5cd05700c8f18c9dafef63ac2ed3b1099ca06017ca0c32deea13093cea1b8671"},{file = "PyMuPDF-1.23.6-cp310-none-win32.whl", hash = "sha256:951d280c1daafac2fd6a664b031f7f98b27eb2def55d39c92a19087bd8041c5d"},{file = "PyMuPDF-1.23.6-cp310-none-win_amd64.whl", hash = "sha256:19d1711d5908c4527ad2deef5af2d066649f3f9a12950faf30be5f7251d18abc"},{file = "PyMuPDF-1.23.6-cp311-none-macosx_10_9_x86_64.whl", hash = "sha256:3f0f9b76bc4f039e7587003cbd40684d93a98441549dd033cab38ca07d61988d"},{file = "PyMuPDF-1.23.6-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:e047571d799b30459ad7ee0bc6e68900a7f6b928876f956c976f279808814e72"},+ {file = "PyMuPDF-1.23.6-cp311-none-manylinux2014_aarch64.whl", hash = "sha256:1cbcf05c06f314fdf3042ceee674e9a0ac7fae598347d5442e2138c6046d4e82"},{file = "PyMuPDF-1.23.6-cp311-none-manylinux2014_x86_64.whl", hash = "sha256:e33f8ec5ba7265fe78b30332840b8f454184addfa79f9c27f160f19789aa5ffd"},{file = "PyMuPDF-1.23.6-cp311-none-win32.whl", hash = "sha256:2c141f33e2733e48de8524dfd2de56d889feef0c7773b20a8cd216c03ab24793"},{file = "PyMuPDF-1.23.6-cp311-none-win_amd64.whl", hash = "sha256:8fd9c4ee1dd4744a515b9190d8ba9133348b0d94c362293ed77726aa1c13b0a6"},{file = "PyMuPDF-1.23.6-cp312-none-macosx_10_9_x86_64.whl", hash = "sha256:4d06751d5cd213e96f84f2faaa71a51cf4d641851e07579247ca1190121f173b"},{file = "PyMuPDF-1.23.6-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:526b26a5207e923aab65877ad305644402851823a352cb92d362053426899354"},+ {file = "PyMuPDF-1.23.6-cp312-none-manylinux2014_aarch64.whl", hash = "sha256:0f852d125defc26716878b1796f4d68870e9065041d00cf46bde317fd8d30e68"},{file = "PyMuPDF-1.23.6-cp312-none-manylinux2014_x86_64.whl", hash = "sha256:5bdf7020b90987412381acc42427dd1b7a03d771ee9ec273de003e570164ec1a"},{file = "PyMuPDF-1.23.6-cp312-none-win32.whl", hash = "sha256:e2d64799c6d9a3735be9e162a5d11061c0b7fbcb1e5fc7446e0993d0f815a93a"},{file = "PyMuPDF-1.23.6-cp312-none-win_amd64.whl", hash = "sha256:c8ea81964c1433ea163ad4b53c56053a87a9ef6e1bd7a879d4d368a3988b60d1"},{file = "PyMuPDF-1.23.6-cp38-none-macosx_10_9_x86_64.whl", hash = "sha256:761501a4965264e81acdd8f2224f993020bf24474e9b34fcdb5805a6826eda1c"},{file = "PyMuPDF-1.23.6-cp38-none-macosx_11_0_arm64.whl", hash = "sha256:fd8388e82b6045807d19addf310d8119d32908e89f76cc8bbf8cf1ec36fce947"},+ {file = "PyMuPDF-1.23.6-cp38-none-manylinux2014_aarch64.whl", hash = "sha256:4ac9673a6d6ee7e80cb242dacb43f9ca097b502d9c5e44687dbdffc2bce7961a"},{file = "PyMuPDF-1.23.6-cp38-none-manylinux2014_x86_64.whl", hash = "sha256:6e319c1f49476e07b9a12017c2d031687617713f8a46b7adcec03c636ed04607"},{file = "PyMuPDF-1.23.6-cp38-none-win32.whl", hash = "sha256:1103eea4ab727e32b9cb93347b35f71562033018c333a7f3a17d115e980fea4a"},{file = "PyMuPDF-1.23.6-cp38-none-win_amd64.whl", hash = "sha256:991a37e1cba43775ce094da87cf0bf72172a5532a09644003276bc8bfdfe9f1a"},{file = "PyMuPDF-1.23.6-cp39-none-macosx_10_9_x86_64.whl", hash = "sha256:57725e15872f7ab67a9fb3e06e5384d1047b2121e85755c93a6d4266d3ca8983"},{file = "PyMuPDF-1.23.6-cp39-none-macosx_11_0_arm64.whl", hash = "sha256:224c341fe254adda97c8f06a4c5838cdbcf609fa89e70b1fb179752533378f2f"},+ {file = "PyMuPDF-1.23.6-cp39-none-manylinux2014_aarch64.whl", hash = "sha256:271bdf6059bb8347f9c9c6b721329bd353a933681b1fc62f43241b410e7ab7ae"},{file = "PyMuPDF-1.23.6-cp39-none-manylinux2014_x86_64.whl", hash = "sha256:57e22bea69690450197b34dcde16bd9fe0265ac4425b4033535ccc5c044246fb"},{file = "PyMuPDF-1.23.6-cp39-none-win32.whl", hash = "sha256:2885a26220a32fb45ea443443b72194bb7107d6862d8d546b59e4ad0c8a1f2c9"},{file = "PyMuPDF-1.23.6-cp39-none-win_amd64.whl", hash = "sha256:361cab1be45481bd3dc4e00ec82628ebc189b4f4b6fd9bd78a00cfeed54e0034"},@@ -2689,16 +2706,36 @@ PyMuPDFb = "1.23.6"name = "pymupdfb"version = "1.23.6"description = "MuPDF shared libraries for PyMuPDF."-optional = false+optional = truepython-versions = ">=3.8"files = [{file = "PyMuPDFb-1.23.6-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:e5af77580aad3d1103aeec57009d156bfca429cecda14a17c573fcbe97bafb30"},{file = "PyMuPDFb-1.23.6-py3-none-macosx_11_0_arm64.whl", hash = "sha256:9925816cbe3e05e920f9be925e5752c2eef42b793885b62075bb0f6a69178598"},+ {file = "PyMuPDFb-1.23.6-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:009e2cff166059e13bf71f93919e688f46b8fc11d122433574cfb0cc9134690e"},{file = "PyMuPDFb-1.23.6-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:7132b30e6ad6ff2013344e3a481b2287fe0be3710d80694807dd6e0d8635f085"},{file = "PyMuPDFb-1.23.6-py3-none-win32.whl", hash = "sha256:9d24ddadc204e895bee5000ddc7507c801643548e59f5a56aad6d32981d17eeb"},{file = "PyMuPDFb-1.23.6-py3-none-win_amd64.whl", hash = "sha256:7bef75988e6979b10ca804cf9487f817aae43b0fff1c6e315b3b9ee0cf1cc32f"},]+[[package]]+name = "pyowm"+version = "3.3.0"+description = "A Python wrapper around OpenWeatherMap web APIs"+optional = true+python-versions = ">=3.7"+files = [+ {file = "pyowm-3.3.0-py3-none-any.whl", hash = "sha256:86463108e7613171531ba306040b43c972b3fc0b0acf73b12c50910cdd2107ab"},+ {file = "pyowm-3.3.0.tar.gz", hash = "sha256:8196f77c91eac680676ed5ee484aae8a165408055e3e2b28025cbf60b8681e03"},+]++[package.dependencies]+geojson = ">=2.3.0,<3"+PySocks = ">=1.7.1,<2"+requests = [+ {version = ">=2.20.0,<3"},+ {version = "*", extras = ["socks"]},+]+[[package]]name = "pyparsing"version = "3.1.1"@@ -2713,6 +2750,18 @@ files = [[package.extras]diagrams = ["jinja2", "railroad-diagrams"]+[[package]]+name = "pysocks"+version = "1.7.1"+description = "A Python SOCKS client module. See https://github.com/Anorov/PySocks for more information."+optional = true+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"+files = [+ {file = "PySocks-1.7.1-py27-none-any.whl", hash = "sha256:08e69f092cc6dbe92a0fdd16eeb9b9ffbc13cadfe5ca4c7bd92ffb078b293299"},+ {file = "PySocks-1.7.1-py3-none-any.whl", hash = "sha256:2725bd0a9925919b9b51739eea5f9e2bae91e83288108a9ad338b2e3a4435ee5"},+ {file = "PySocks-1.7.1.tar.gz", hash = "sha256:3f8804571ebe159c380ac6de37643bb4685970655d3bba243530d6558b799aa0"},+]+[[package]]name = "pytest"version = "7.4.3"@@ -2804,6 +2853,7 @@ files = [{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"},{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"},{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"},+ {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"},{file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"},{file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"},{file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"},@@ -2811,8 +2861,15 @@ files = [{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"},{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"},{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"},+ {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"},{file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"},{file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"},+ {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"},+ {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"},+ {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"},+ {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"},+ {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"},+ {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"},{file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"},{file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"},{file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"},@@ -2829,6 +2886,7 @@ files = [{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"},{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"},{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"},+ {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"},{file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"},{file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"},{file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"},@@ -2836,6 +2894,7 @@ files = [{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"},{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"},{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"},+ {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"},{file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"},{file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"},{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},@@ -2984,6 +3043,7 @@ files = [certifi = ">=2017.4.17"charset-normalizer = ">=2,<4"idna = ">=2.5,<4"+PySocks = {version = ">=1.5.6,<1.5.7 || >1.5.7", optional = true, markers = "extra == \"socks\""}urllib3 = ">=1.21.1,<3"[package.extras]@@ -4407,10 +4467,11 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linktesting = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy (>=0.9.1)", "pytest-ruff"][extras]-all = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "transformers", "wikipedia"]-huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "transformers", "wikipedia"]+all = ["PyMuPDF", "accelerate", "beautifulsoup4", "datasets", "diffusers", "docx2txt", "opencv-python", "pyowm", "sentencepiece", "soundfile", "torch", "transformers", "wikipedia"]+huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "transformers"]+tools = ["PyMuPDF", "beautifulsoup4", "docx2txt", "pyowm", "wikipedia"][metadata]lock-version = "2.0"python-versions = "^3.8.1"-content-hash = "8b8ef65116e28d57439a49fdd1b05e9bd55e961f97088f684ac3efe9ca470121"+content-hash = "43530ee01cefccbe8213d50900c5e8d062898008ef3c85fbec05742d97a45df9"diff --git a/pyproject.toml b/pyproject.tomlindex fa9b1cefc..b6657e8fc 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -32,11 +32,8 @@ colorama = "^0"jsonschema = "^4"types-colorama = "^0"types-requests = "^2"-bs4 = "^0"protobuf = "^4"-docx2txt = "^0.8"-PyMuPDF = "^1.22.5"-pathlib = "^1.0.1"+pathlib = "^1.0.1"transformers = { version = "^4", optional = true }diffusers = { version = "^0", optional = true }@@ -46,7 +43,11 @@ torch = { version = "^1", optional = true }soundfile = { version = "^0", optional = true }sentencepiece = { version = "^0", optional = true }opencv-python = { version = "^4", optional = true }+beautifulsoup4 = { version = "^4", optional = true }+docx2txt = { version = "^0.8", optional = true }+PyMuPDF = { version = "^1.22.5", optional = true }wikipedia = { version = "^1", optional = true }+pyowm = { version = "^3.3.0", optional = true }[tool.poetry.extras]huggingface-agent = [@@ -58,9 +59,17 @@ huggingface-agent = ["soundfile","sentencepiece","opencv-python",+]++tools = [+ "beautifulsoup4",+ "docx2txt",+ "PyMuPDF","wikipedia",+ "pyowm",]+all = ["transformers","diffusers",@@ -70,7 +79,11 @@ all = ["soundfile","sentencepiece","opencv-python",+ "beautifulsoup4",+ "docx2txt",+ "PyMuPDF","wikipedia",+ "pyowm",][tool.poetry.group.dev]@@ -142,6 +155,7 @@ module = ["huggingface_hub","huggingface_hub.utils._errors","wikipedia",+ "pyowm","jsonschema.*","bs4.*","docx2txt",diff --git a/test/functions/test_weather_function.py b/test/functions/test_weather_function.pynew file mode 100644index 000000000..8e0e29479--- /dev/null+++ b/test/functions/test_weather_function.py@@ -0,0 +1,130 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+import os+import re+from datetime import datetime, timezone++import pytest++from camel.functions.weather_functions import get_weather_data++[email protected](scope="module")+def api_key():+ key = os.environ.get('OPENWEATHERMAP_API_KEY')+ if not key:+ pytest.fail("OPENWEATHERMAP_API_KEY environment variable is not set.")+ return key+++def test_weather(api_key):+ # Test temperature in Paris, FR.+ city = "Paris, FR"+ temp_units_options = {+ 'celsius': (-100, 60),+ 'kelvin': (173, 333),+ 'fahrenheit': (-148, 140)+ }+ for temp_units, (temp_min, temp_max) in temp_units_options.items():+ report = get_weather_data(city, temp_units, 'meters_sec', 'meters',+ 'iso')+ # Parse temperature+ pattern = re.compile(+ rf"Weather in .+: (-?\d+\.?\d*)°{temp_units.title()},")+ match = pattern.search(report)+ temp = float(match.group(1)) if match else None+ # Test temperature+ assert temp is not None, (+ "Temperature information is missing from the report")+ assert temp_min <= temp <= temp_max, (+ f"Temperature {temp} not in range for {temp_units}")++ # Test wind speed in Jeddah, Saudi Arabia.+ city = "Jeddah"+ wind_units_options = {+ 'meters_sec': (0, 200),+ 'miles_hour': (0, 447),+ 'knots': (0, 390),+ 'beaufort': (0, 12)+ }+ for wind_units, (wind_min, wind_max) in wind_units_options.items():+ report = get_weather_data(city, 'celsius', wind_units, 'meters', 'iso')+ # Parse wind speed+ pattern = re.compile(rf"Wind: (-?\d+\.?\d*) {wind_units} at")+ match = pattern.search(report)+ wind_speed = float(match.group(1)) if match else None+ # Test wind speed+ assert wind_speed is not None, (+ "Wind speed information is missing from the report")+ assert wind_min <= wind_speed <= wind_max, (+ f"Wind speed {wind_speed} not in range for {wind_units}")++ # Test visibility distance in Harbin, China.+ city = "Harbin, China"+ visibility_units_options = {'meters': (0, 400000), 'miles': (0, 250)}+ for visibility_units, visibility_range in visibility_units_options.items():+ visibility_min, visibility_max = visibility_range+ report = get_weather_data(city, 'celsius', 'meters_sec',+ visibility_units, 'iso')+ # Parse visibility+ pattern = re.compile(+ rf"Visibility: (-?\d+\.?\d*) {visibility_units}\.")+ match = pattern.search(report)+ visibility = float(match.group(1)) if match else None+ # Test visibility+ assert visibility is not None, (+ "Visibility information is missing from the report")+ assert visibility_min <= visibility <= visibility_max, (+ f"Visibility {visibility} not in range for {visibility_units}")++ # Test sunrise and sunset time in London,GB.+ city = "London,GB"+ # Test each time_units option+ time_units_options = ['unix', 'iso', 'date']+ for time_units in time_units_options:+ report = get_weather_data(city, 'celsius', 'meters_sec', 'meters',+ time_units)+ # Regex to extract sunrise and sunset times based on time_units+ pattern_map = {+ 'unix': (r"Sunrise at (\d+), Sunset at (\d+)."),+ 'iso': (r"Sunrise at ([\d-]+\s[\d:]+)\+00:00, "+ r"Sunset at ([\d-]+\s[\d:]+)\+00:00."),+ 'date': (r"Sunrise at ([\d-]+\s[\d:]+\+00:00), "+ r"Sunset at ([\d-]+\s[\d:]+\+00:00).")+ }+ pattern = re.compile(pattern_map[time_units])+ match = pattern.search(report)+ # Ensure sunrise and sunset times are found in the report+ assert match, ("Sunrise and sunset information in {} "+ "format is missing from the report.".format(time_units))+ sunrise_str, sunset_str = match.groups()+ # Parse times according to format+ time_format_map = {+ 'unix': '%s',+ 'iso': '%Y-%m-%d %H:%M:%S',+ # The 'date' format includes timezone information for parsing+ 'date': '%Y-%m-%d %H:%M:%S%z'+ }+ if time_units == 'unix':+ sunrise_time = datetime.fromtimestamp(int(sunrise_str),+ tz=timezone.utc)+ sunset_time = datetime.fromtimestamp(int(sunset_str),+ tz=timezone.utc)+ else:+ sunrise_format = time_format_map[time_units]+ sunrise_time = datetime.strptime(sunrise_str, sunrise_format)+ sunset_time = datetime.strptime(sunset_str, sunrise_format)+ # Check that sunrise occurs before sunset+ assert sunrise_time < sunset_time, (+ "Sunrise time is not before sunset time in the report.")