[ perf ] Replace json-> orjson in hot path (#11221)
Signed-off-by: vincentzed <207368749+vincentzed@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import uuid
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
|
||||
import orjson
|
||||
from fastapi import HTTPException, Request
|
||||
from fastapi.responses import ORJSONResponse, StreamingResponse
|
||||
|
||||
@@ -197,7 +198,7 @@ class OpenAIServingBase(ABC):
|
||||
)
|
||||
try:
|
||||
raw_labels = (
|
||||
json.loads(raw_request.headers.get(header))
|
||||
orjson.loads(raw_request.headers.get(header))
|
||||
if raw_request and raw_request.headers.get(header)
|
||||
else None
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import time
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, List, Optional, Union
|
||||
|
||||
import orjson
|
||||
from fastapi import Request
|
||||
from fastapi.responses import ORJSONResponse, StreamingResponse
|
||||
from jsonschema import Draft202012Validator, SchemaError
|
||||
@@ -285,7 +286,7 @@ class OpenAIServingChat(OpenAIServingBase):
|
||||
if "arguments" in item["function"] and isinstance(
|
||||
item["function"]["arguments"], str
|
||||
):
|
||||
item["function"]["arguments"] = json.loads(
|
||||
item["function"]["arguments"] = orjson.loads(
|
||||
item["function"]["arguments"]
|
||||
)
|
||||
|
||||
@@ -860,7 +861,7 @@ class OpenAIServingChat(OpenAIServingBase):
|
||||
finish_reason["matched"] = None
|
||||
try:
|
||||
# For required tool choice, we expect a JSON array of tool calls
|
||||
tool_call_data = json.loads(text)
|
||||
tool_call_data = orjson.loads(text)
|
||||
tool_calls = []
|
||||
for i, tool in enumerate(tool_call_data):
|
||||
# Create a ToolCallItem from the JSON data
|
||||
|
||||
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from contextlib import AsyncExitStack
|
||||
@@ -14,6 +13,7 @@ from typing import TYPE_CHECKING, Any, AsyncGenerator, AsyncIterator, Optional,
|
||||
|
||||
import jinja2
|
||||
import openai.types.responses as openai_responses_types
|
||||
import orjson
|
||||
from fastapi import Request
|
||||
from fastapi.responses import ORJSONResponse
|
||||
from openai.types.responses import (
|
||||
@@ -1061,7 +1061,7 @@ class OpenAIServingResponses(OpenAIServingChat):
|
||||
):
|
||||
function_name = previous_item.recipient[len("browser.") :]
|
||||
action = None
|
||||
parsed_args = json.loads(previous_item.content[0].text)
|
||||
parsed_args = ororjson.loads(previous_item.content[0].text)
|
||||
if function_name == "search":
|
||||
action = openai_responses_types.response_function_web_search.ActionSearch(
|
||||
type="search",
|
||||
|
||||
Reference in New Issue
Block a user