mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
feat: +omniparse timeout
This commit is contained in:
parent
eda130ca25
commit
b68c139125
3 changed files with 13 additions and 10 deletions
|
|
@ -3,3 +3,4 @@ from metagpt.utils.yaml_model import YamlModel
|
|||
|
||||
class OmniParseConfig(YamlModel):
|
||||
url: str = ""
|
||||
timeout: int = 600
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Union
|
||||
from typing import List, Optional, Tuple, Union
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
|
@ -251,15 +251,17 @@ class Editor(BaseModel):
|
|||
from metagpt.tools.libs import get_env_default
|
||||
from metagpt.utils.omniparse_client import OmniParseClient
|
||||
|
||||
base_url = await get_env_default(key="base_url", app_name="OmniParse", default_value="")
|
||||
if not base_url:
|
||||
base_url = await Editor._read_omniparse_config()
|
||||
base_url1 = await get_env_default(key="base_url", app_name="OmniParse", default_value="")
|
||||
timeout1 = await get_env_default(key="timeout", app_name="OmniParse", default_value="")
|
||||
base_url2, timeout2 = await Editor._read_omniparse_config()
|
||||
|
||||
base_url = base_url1 or base_url2
|
||||
if not base_url:
|
||||
return None
|
||||
api_key = await get_env_default(key="api_key", app_name="OmniParse", default_value="")
|
||||
v = await get_env_default(key="timeout", app_name="OmniParse", default_value="120")
|
||||
timeout = timeout1 or timeout2 or 120
|
||||
try:
|
||||
timeout = int(v) or 120
|
||||
timeout = int(timeout)
|
||||
except ValueError:
|
||||
timeout = 120
|
||||
|
||||
|
|
@ -287,8 +289,8 @@ class Editor(BaseModel):
|
|||
return result
|
||||
|
||||
@staticmethod
|
||||
async def _read_omniparse_config() -> str:
|
||||
async def _read_omniparse_config() -> Tuple[str, int]:
|
||||
config = Config.default()
|
||||
if config.omniparse and config.omniparse.url:
|
||||
return config.omniparse.url
|
||||
return ""
|
||||
return config.omniparse.url, config.omniparse.timeout
|
||||
return "", 0
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class OmniParseClient:
|
|||
# Do not verify if only byte data is provided
|
||||
return
|
||||
|
||||
file_ext = Path(verify_file_path).suffix
|
||||
file_ext = Path(verify_file_path).suffix.lower()
|
||||
if file_ext not in allowed_file_extensions:
|
||||
raise ValueError(f"Not allowed {file_ext} File extension must be one of {allowed_file_extensions}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue