@@ -458,7 +458,7 @@ class BaseChatOpenAI(BaseChatModel):
458
458
alias = "api_key" , default_factory = secret_from_env ("OPENAI_API_KEY" , default = None )
459
459
)
460
460
openai_api_base : Optional [str ] = Field (default = None , alias = "base_url" )
461
- """Base URL path for API requests, leave blank if not using a proxy or service
461
+ """Base URL path for API requests, leave blank if not using a proxy or service
462
462
emulator."""
463
463
openai_organization : Optional [str ] = Field (default = None , alias = "organization" )
464
464
"""Automatically inferred from env var ``OPENAI_ORG_ID`` if not provided."""
@@ -489,7 +489,7 @@ class BaseChatOpenAI(BaseChatModel):
489
489
"""Whether to return logprobs."""
490
490
top_logprobs : Optional [int ] = None
491
491
"""Number of most likely tokens to return at each token position, each with
492
- an associated log probability. `logprobs` must be set to true
492
+ an associated log probability. `logprobs` must be set to true
493
493
if this parameter is used."""
494
494
logit_bias : Optional [dict [int , int ]] = None
495
495
"""Modify the likelihood of specified tokens appearing in the completion."""
@@ -507,7 +507,7 @@ class BaseChatOpenAI(BaseChatModel):
507
507
508
508
Reasoning models only, like OpenAI o1, o3, and o4-mini.
509
509
510
- Currently supported values are low, medium, and high. Reducing reasoning effort
510
+ Currently supported values are low, medium, and high. Reducing reasoning effort
511
511
can result in faster responses and fewer tokens used on reasoning in a response.
512
512
513
513
.. versionadded:: 0.2.14
@@ -529,67 +529,67 @@ class BaseChatOpenAI(BaseChatModel):
529
529
530
530
"""
531
531
tiktoken_model_name : Optional [str ] = None
532
- """The model name to pass to tiktoken when using this class.
533
- Tiktoken is used to count the number of tokens in documents to constrain
534
- them to be under a certain limit. By default, when set to None, this will
535
- be the same as the embedding model name. However, there are some cases
536
- where you may want to use this Embedding class with a model name not
537
- supported by tiktoken. This can include when using Azure embeddings or
538
- when using one of the many model providers that expose an OpenAI-like
539
- API but with different models. In those cases, in order to avoid erroring
532
+ """The model name to pass to tiktoken when using this class.
533
+ Tiktoken is used to count the number of tokens in documents to constrain
534
+ them to be under a certain limit. By default, when set to None, this will
535
+ be the same as the embedding model name. However, there are some cases
536
+ where you may want to use this Embedding class with a model name not
537
+ supported by tiktoken. This can include when using Azure embeddings or
538
+ when using one of the many model providers that expose an OpenAI-like
539
+ API but with different models. In those cases, in order to avoid erroring
540
540
when tiktoken is called, you can specify a model name to use here."""
541
541
default_headers : Union [Mapping [str , str ], None ] = None
542
542
default_query : Union [Mapping [str , object ], None ] = None
543
543
# Configure a custom httpx client. See the
544
544
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
545
545
http_client : Union [Any , None ] = Field (default = None , exclude = True )
546
- """Optional ``httpx.Client``. Only used for sync invocations. Must specify
546
+ """Optional ``httpx.Client``. Only used for sync invocations. Must specify
547
547
``http_async_client`` as well if you'd like a custom client for async
548
548
invocations.
549
549
"""
550
550
http_async_client : Union [Any , None ] = Field (default = None , exclude = True )
551
- """Optional ``httpx.AsyncClient``. Only used for async invocations. Must specify
551
+ """Optional ``httpx.AsyncClient``. Only used for async invocations. Must specify
552
552
``http_client`` as well if you'd like a custom client for sync invocations."""
553
553
stop : Optional [Union [list [str ], str ]] = Field (default = None , alias = "stop_sequences" )
554
554
"""Default stop sequences."""
555
555
extra_body : Optional [Mapping [str , Any ]] = None
556
556
"""Optional additional JSON properties to include in the request parameters when
557
557
making requests to OpenAI compatible APIs, such as vLLM, LM Studio, or other
558
558
providers.
559
-
559
+
560
560
This is the recommended way to pass custom parameters that are specific to your
561
561
OpenAI-compatible API provider but not part of the standard OpenAI API.
562
-
562
+
563
563
Examples:
564
564
- LM Studio TTL parameter: ``extra_body={"ttl": 300}``
565
565
- vLLM custom parameters: ``extra_body={"use_beam_search": True}``
566
566
- Any other provider-specific parameters
567
-
567
+
568
568
.. note::
569
-
569
+
570
570
Do NOT use ``model_kwargs`` for custom parameters that are not part of the
571
- standard OpenAI API, as this will cause errors when making API calls. Use
571
+ standard OpenAI API, as this will cause errors when making API calls. Use
572
572
``extra_body`` instead.
573
573
"""
574
574
575
575
include_response_headers : bool = False
576
576
"""Whether to include response headers in the output message ``response_metadata``.""" # noqa: E501
577
577
disabled_params : Optional [dict [str , Any ]] = Field (default = None )
578
- """Parameters of the OpenAI client or chat.completions endpoint that should be
578
+ """Parameters of the OpenAI client or chat.completions endpoint that should be
579
579
disabled for the given model.
580
-
581
- Should be specified as ``{"param": None | ['val1', 'val2']}`` where the key is the
580
+
581
+ Should be specified as ``{"param": None | ['val1', 'val2']}`` where the key is the
582
582
parameter and the value is either None, meaning that parameter should never be
583
583
used, or it's a list of disabled values for the parameter.
584
-
584
+
585
585
For example, older models may not support the ``'parallel_tool_calls'`` parameter at
586
- all, in which case ``disabled_params={"parallel_tool_calls": None}`` can be passed
586
+ all, in which case ``disabled_params={"parallel_tool_calls": None}`` can be passed
587
587
in.
588
-
588
+
589
589
If a parameter is disabled then it will not be used by default in any methods, e.g.
590
590
in :meth:`~langchain_openai.chat_models.base.ChatOpenAI.with_structured_output`.
591
591
However this does not prevent a user from directly passed in the parameter during
592
- invocation.
592
+ invocation.
593
593
"""
594
594
595
595
include : Optional [list [str ]] = None
@@ -3716,6 +3716,20 @@ def _construct_responses_api_input(messages: Sequence[BaseMessage]) -> list:
3716
3716
return input_
3717
3717
3718
3718
3719
+ def _get_output_text (response : Response ) -> str :
3720
+ """OpenAI SDK deleted response.output_text in 1.99.2"""
3721
+ if hasattr (response , "output_text" ):
3722
+ return response .output_text
3723
+ texts : list [str ] = []
3724
+ for output in response .output :
3725
+ if output .type == "message" :
3726
+ for content in output .content :
3727
+ if content .type == "output_text" :
3728
+ texts .append (content .text )
3729
+
3730
+ return "" .join (texts )
3731
+
3732
+
3719
3733
def _construct_lc_result_from_responses_api (
3720
3734
response : Response ,
3721
3735
schema : Optional [type [_BM ]] = None ,
@@ -3830,17 +3844,18 @@ def _construct_lc_result_from_responses_api(
3830
3844
# text_format=Foo,
3831
3845
# stream=True, # <-- errors
3832
3846
# )
3847
+ output_text = _get_output_text (response )
3833
3848
if (
3834
3849
schema is not None
3835
3850
and "parsed" not in additional_kwargs
3836
- and response . output_text # tool calls can generate empty output text
3851
+ and output_text # tool calls can generate empty output text
3837
3852
and response .text
3838
3853
and (text_config := response .text .model_dump ())
3839
3854
and (format_ := text_config .get ("format" , {}))
3840
3855
and (format_ .get ("type" ) == "json_schema" )
3841
3856
):
3842
3857
try :
3843
- parsed_dict = json .loads (response . output_text )
3858
+ parsed_dict = json .loads (output_text )
3844
3859
if schema and _is_pydantic_class (schema ):
3845
3860
parsed = schema (** parsed_dict )
3846
3861
else :
0 commit comments