mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 23:29:21 +00:00
openai[patch]: azure max completion tokens fix
This commit is contained in:
parent
8adc4a5bcc
commit
eec4df0d0a
@ -737,3 +737,15 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return chat_result
|
return chat_result
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_params(self) -> Dict[str, Any]:
|
||||||
|
"""Get the default parameters for calling OpenAI API."""
|
||||||
|
params = super()._default_params
|
||||||
|
if (
|
||||||
|
"o1" in params["model"]
|
||||||
|
and "max_tokens" in params["model"]
|
||||||
|
and "max_completion_tokens" not in params["model"]
|
||||||
|
):
|
||||||
|
params["max_completion_tokens"] = params.pop("max_tokens")
|
||||||
|
return params
|
||||||
|
@ -262,3 +262,13 @@ async def test_json_mode_async(llm: AzureChatOpenAI) -> None:
|
|||||||
assert isinstance(full, AIMessageChunk)
|
assert isinstance(full, AIMessageChunk)
|
||||||
assert isinstance(full.content, str)
|
assert isinstance(full.content, str)
|
||||||
assert json.loads(full.content) == {"a": 1}
|
assert json.loads(full.content) == {"a": 1}
|
||||||
|
|
||||||
|
|
||||||
|
def test_o1_max_tokens() -> None:
|
||||||
|
response = ChatOpenAI(model="o1-mini", max_tokens=10).invoke("how are you") # type: ignore[call-arg]
|
||||||
|
assert isinstance(response, AIMessage)
|
||||||
|
|
||||||
|
response = ChatOpenAI(model="gpt-4o", max_completion_tokens=10).invoke(
|
||||||
|
"how are you"
|
||||||
|
)
|
||||||
|
assert isinstance(response, AIMessage)
|
||||||
|
Loading…
Reference in New Issue
Block a user