mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 18:56:29 +08:00
chore: clean some isinstance (#37602)
Co-authored-by: WH-2099 <wh2099@pm.me>
This commit is contained in:
parent
265dc54c51
commit
d5cdb2e6f1
@ -74,11 +74,12 @@ def accept_subjects(*accepted: SubjectType) -> Callable[[F], F]:
|
||||
|
||||
|
||||
def _coerce_subject_type(raw: object) -> SubjectType | None:
|
||||
if raw is None:
|
||||
match raw:
|
||||
case None:
|
||||
return None
|
||||
if isinstance(raw, SubjectType):
|
||||
case SubjectType():
|
||||
return raw
|
||||
if isinstance(raw, str):
|
||||
case str():
|
||||
return SubjectType(raw)
|
||||
return None
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from http import HTTPStatus
|
||||
from typing import Any, cast
|
||||
|
||||
import httpx
|
||||
@ -293,15 +294,14 @@ class StreamableHTTPTransport:
|
||||
json=message.model_dump(by_alias=True, mode="json", exclude_none=True),
|
||||
headers=headers,
|
||||
) as response:
|
||||
if response.status_code == 202:
|
||||
match response.status_code:
|
||||
case HTTPStatus.ACCEPTED:
|
||||
logger.debug("Received 202 Accepted")
|
||||
return
|
||||
|
||||
if response.status_code == 204:
|
||||
case HTTPStatus.NO_CONTENT:
|
||||
logger.debug("Received 204 No Content")
|
||||
return
|
||||
|
||||
if response.status_code == 404:
|
||||
case HTTPStatus.NOT_FOUND:
|
||||
if isinstance(message.root, JSONRPCRequest):
|
||||
error_msg = (
|
||||
f"MCP server URL returned 404 Not Found: {self.url} "
|
||||
|
||||
@ -359,14 +359,15 @@ class ApiTool(Tool):
|
||||
if value is None:
|
||||
return None
|
||||
elif property["type"] == "object" or property["type"] == "array":
|
||||
if isinstance(value, str):
|
||||
match value:
|
||||
case str():
|
||||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
return value
|
||||
elif isinstance(value, dict):
|
||||
case dict():
|
||||
return value
|
||||
else:
|
||||
case _:
|
||||
return value
|
||||
else:
|
||||
raise ValueError(f"Invalid type {property['type']} for property {property}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user