File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
langchain_openai/chat_models
tests/unit_tests/chat_models Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change 8989from langchain_core .outputs import ChatGeneration , ChatGenerationChunk , ChatResult
9090from langchain_core .runnables import (
9191 Runnable ,
92+ RunnableBranch ,
9293 RunnableLambda ,
9394 RunnableMap ,
9495 RunnablePassthrough ,
@@ -2215,8 +2216,12 @@ def _get_raw_structured_output_chain(
22152216 parser_with_fallback = parser_assign .with_fallbacks (
22162217 [parser_error_fallback ], exception_key = "parsing_error"
22172218 )
2219+ branch = RunnableBranch [dict , dict ](
2220+ (lambda x : x .get ("parsing_error" ) is not None , RunnablePassthrough ()),
2221+ parser_with_fallback ,
2222+ )
22182223
2219- return wrap_input | llm_with_fallback | parser_with_fallback
2224+ return wrap_input | llm_with_fallback | branch
22202225
22212226 def _get_message_from_error_response (
22222227 self , error : Exception
Original file line number Diff line number Diff line change @@ -3266,7 +3266,7 @@ def test_with_structured_output_validation_error() -> None:
32663266 "usage" : {"prompt_tokens" : 10 , "completion_tokens" : 5 , "total_tokens" : 15 },
32673267 }
32683268 mock_api_response = MagicMock (spec = APIResponse )
3269- mock_api_response .http_response = MagicMock (spec = Response )
3269+ mock_api_response .http_response = MagicMock (spec = httpx . Response )
32703270 mock_api_response .http_response .json .return_value = response_json
32713271 mock_api_response .parse .side_effect = ValidationError .from_exception_data (
32723272 title = "Foo" ,
You can’t perform that action at this time.
0 commit comments