File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
backend/apps/ai_model/openai Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 11from collections .abc import Iterator , Mapping
2- from typing import Any , cast
2+ from typing import Any , Optional , cast
33
44from langchain_core .language_models import LanguageModelInput
55from langchain_core .messages import (
@@ -84,6 +84,26 @@ def _convert_delta_to_message_chunk(
8484
8585
8686class BaseChatOpenAI (ChatOpenAI ):
87+ @property
88+ def _default_params (self ) -> dict [str , Any ]:
89+ max_tokens = self .max_tokens
90+ params = super ()._default_params
91+ if max_tokens :
92+ params ["max_tokens" ] = max_tokens
93+ return params
94+
95+ def _get_request_payload (
96+ self ,
97+ input_ : LanguageModelInput ,
98+ * ,
99+ stop : Optional [list [str ]] = None ,
100+ ** kwargs : Any ,
101+ ) -> dict :
102+ max_tokens = self .max_tokens
103+ payload = super ()._get_request_payload (input_ , stop = stop , ** kwargs )
104+ if max_tokens :
105+ payload ["max_tokens" ] = max_tokens
106+ return payload
87107 usage_metadata : dict = {}
88108
89109 # custom_get_token_ids = custom_get_token_ids
You can’t perform that action at this time.
0 commit comments