Merge branch 'feature/omniparse_config' into 'mgx_ops'

feat: +omniparse config

See merge request pub/MetaGPT!323
This commit is contained in:
张雷 2024-08-16 05:55:27 +00:00
commit b75e25b1cf
4 changed files with 43 additions and 1 deletions

View file

@ -35,6 +35,7 @@ from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
from urllib.parse import quote, unquote
import aiofiles
import aiohttp
import chardet
import loguru
import requests
@ -1120,6 +1121,26 @@ def log_time(method):
return timeit_wrapper_async if iscoroutinefunction(method) else timeit_wrapper
async def check_http_endpoint(url: str, timeout: int = 3) -> bool:
"""
Checks the status of an HTTP endpoint.
Args:
url (str): The URL of the HTTP endpoint to check.
timeout (int, optional): The timeout in seconds for the HTTP request. Defaults to 3.
Returns:
bool: True if the endpoint is online and responding with a 200 status code, False otherwise.
"""
async with aiohttp.ClientSession() as session:
try:
async with session.get(url, timeout=timeout) as response:
return response.status == 200
except Exception as e:
print(f"Error accessing the endpoint {url}: {e}")
return False
def rectify_pathname(path: Union[str, Path], default_filename: str) -> Path:
"""
Rectifies the given path to ensure a valid output file path.