fix: fix ipython running error for Engine due to outlines nest_asyncio (#4582)

Co-authored-by: shuaills <shishuaiuoe@gmail.com>
This commit is contained in:
mlmz
2025-03-22 10:11:15 +08:00
committed by GitHub
parent c7c7dbebbe
commit f6ab4ca6bc
4 changed files with 37 additions and 14 deletions

View File

@@ -22,6 +22,7 @@ from typing import Any, Callable, List, Optional, Tuple, Type, Union
import numpy as np
import requests
from IPython.display import HTML, display
from pydantic import BaseModel
from tqdm import tqdm
from sglang.srt.utils import kill_process_tree
@@ -29,6 +30,36 @@ from sglang.srt.utils import kill_process_tree
logger = logging.getLogger(__name__)
def convert_json_schema_to_str(json_schema: Union[dict, str, Type[BaseModel]]) -> str:
"""Convert a JSON schema to a string.
Parameters
----------
json_schema
The JSON schema.
Returns
-------
str
The JSON schema converted to a string.
Raises
------
ValueError
If the schema is not a dictionary, a string or a Pydantic class.
"""
if isinstance(json_schema, dict):
schema_str = json.dumps(json_schema)
elif isinstance(json_schema, str):
schema_str = json_schema
elif issubclass(json_schema, BaseModel):
schema_str = json.dumps(json_schema.model_json_schema())
else:
raise ValueError(
f"Cannot parse schema {json_schema}. The schema must be either "
+ "a Pydantic class, a dictionary or a string that contains the JSON "
+ "schema specification"
)
return schema_str
def get_exception_traceback():
etype, value, tb = sys.exc_info()
err_str = "".join(traceback.format_exception(etype, value, tb))