|
|
@ -355,7 +355,7 @@ class ChatOpenAI(BaseChatModel):
|
|
|
|
def _create_message_dicts(
|
|
|
|
def _create_message_dicts(
|
|
|
|
self, messages: List[BaseMessage], stop: Optional[List[str]]
|
|
|
|
self, messages: List[BaseMessage], stop: Optional[List[str]]
|
|
|
|
) -> Tuple[List[Dict[str, Any]], Dict[str, Any]]:
|
|
|
|
) -> Tuple[List[Dict[str, Any]], Dict[str, Any]]:
|
|
|
|
params = dict(self._client_params)
|
|
|
|
params = self._client_params
|
|
|
|
if stop is not None:
|
|
|
|
if stop is not None:
|
|
|
|
if "stop" in params:
|
|
|
|
if "stop" in params:
|
|
|
|
raise ValueError("`stop` found in both the input and default params.")
|
|
|
|
raise ValueError("`stop` found in both the input and default params.")
|
|
|
@ -419,12 +419,12 @@ class ChatOpenAI(BaseChatModel):
|
|
|
|
return self._create_chat_result(response)
|
|
|
|
return self._create_chat_result(response)
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def _identifying_params(self) -> Mapping[str, Any]:
|
|
|
|
def _identifying_params(self) -> Dict[str, Any]:
|
|
|
|
"""Get the identifying parameters."""
|
|
|
|
"""Get the identifying parameters."""
|
|
|
|
return {**{"model_name": self.model_name}, **self._default_params}
|
|
|
|
return {**{"model_name": self.model_name}, **self._default_params}
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def _client_params(self) -> Mapping[str, Any]:
|
|
|
|
def _client_params(self) -> Dict[str, Any]:
|
|
|
|
"""Get the parameters used for the openai client."""
|
|
|
|
"""Get the parameters used for the openai client."""
|
|
|
|
openai_creds: Dict[str, Any] = {
|
|
|
|
openai_creds: Dict[str, Any] = {
|
|
|
|
"api_key": self.openai_api_key,
|
|
|
|
"api_key": self.openai_api_key,
|
|
|
@ -436,17 +436,17 @@ class ChatOpenAI(BaseChatModel):
|
|
|
|
import openai
|
|
|
|
import openai
|
|
|
|
|
|
|
|
|
|
|
|
openai.proxy = {"http": self.openai_proxy, "https": self.openai_proxy} # type: ignore[assignment] # noqa: E501
|
|
|
|
openai.proxy = {"http": self.openai_proxy, "https": self.openai_proxy} # type: ignore[assignment] # noqa: E501
|
|
|
|
return {**openai_creds, **self._default_params}
|
|
|
|
return {**self._default_params, **openai_creds}
|
|
|
|
|
|
|
|
|
|
|
|
def _get_invocation_params(
|
|
|
|
def _get_invocation_params(
|
|
|
|
self, stop: Optional[List[str]] = None, **kwargs: Any
|
|
|
|
self, stop: Optional[List[str]] = None, **kwargs: Any
|
|
|
|
) -> Dict[str, Any]:
|
|
|
|
) -> Dict[str, Any]:
|
|
|
|
"""Get the parameters used to invoke the model FOR THE CALLBACKS."""
|
|
|
|
"""Get the parameters used to invoke the model."""
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
**super()._get_invocation_params(stop=stop, **kwargs),
|
|
|
|
|
|
|
|
**self._default_params,
|
|
|
|
|
|
|
|
"model": self.model_name,
|
|
|
|
"model": self.model_name,
|
|
|
|
"function": kwargs.get("functions"),
|
|
|
|
**super()._get_invocation_params(stop=stop),
|
|
|
|
|
|
|
|
**self._default_params,
|
|
|
|
|
|
|
|
**kwargs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|