Skip to content

Commit 6beebc0

Browse files
authored
[Fix] Fix Structured output Performance issues (#69)
Fix Structured output Performance issues
1 parent 4667acb commit 6beebc0

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

sygra/core/models/custom_models.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -221,30 +221,27 @@ async def _handle_structured_output(
221221
self, input: ChatPromptValue, model_params: ModelParams, **kwargs: Any
222222
) -> Optional[ModelResponse]:
223223
"""Handle structured output generation"""
224-
lock = await self._get_lock()
225-
# Re-entry prevention using asyncio locking
226-
async with lock:
227-
pydantic_model = self.structured_output.get_pydantic_model()
228-
if not pydantic_model:
229-
logger.warning(
230-
"Structured output enabled but no valid schema found, falling back to regular generation"
231-
)
232-
# Return a flag to signal that regular generation should be used
233-
return None
224+
pydantic_model = self.structured_output.get_pydantic_model()
225+
if not pydantic_model:
226+
logger.warning(
227+
"Structured output enabled but no valid schema found, falling back to regular generation"
228+
)
229+
# Return a flag to signal that regular generation should be used
230+
return None
234231

235-
# Check if model supports native structured output
236-
if self._supports_native_structured_output():
237-
logger.info(f"Using native structured output for {self.name()}")
238-
return await self._generate_native_structured_output(
239-
input, model_params, pydantic_model, **kwargs
240-
)
241-
else:
242-
logger.info(f"Using fallback structured output for {self.name()}")
243-
# Get response from fallback method
244-
model_response: ModelResponse = await self._generate_fallback_structured_output(
245-
input, model_params, pydantic_model, **kwargs
246-
)
247-
return model_response
232+
# Check if model supports native structured output
233+
if self._supports_native_structured_output():
234+
logger.info(f"Using native structured output for {self.name()}")
235+
return await self._generate_native_structured_output(
236+
input, model_params, pydantic_model, **kwargs
237+
)
238+
else:
239+
logger.info(f"Using fallback structured output for {self.name()}")
240+
# Get response from fallback method
241+
model_response: ModelResponse = await self._generate_fallback_structured_output(
242+
input, model_params, pydantic_model, **kwargs
243+
)
244+
return model_response
248245

249246
def _supports_native_structured_output(self) -> bool:
250247
"""Check if the model supports native structured output"""

sygra/core/models/lite_llm/vllm_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, model_config: dict[str, Any]) -> None:
2222
utils.validate_required_keys(["url", "auth_token"], model_config, "model")
2323
self.model_config = model_config
2424
self.auth_token = str(model_config.get("auth_token")).replace("Bearer ", "")
25-
self.model_name = model_config.get("model_serving_name", self.name())
25+
self.model_name = model_config.get("model_serving_name", self.model_name)
2626

2727
def _validate_completions_api_model_support(self) -> None:
2828
logger.info(f"Model {self.name()} supports completion API.")

0 commit comments

Comments
 (0)