Harrison/add warning to openaichat (#1781)

This commit is contained in:
Harrison Chase 2023-03-19 09:43:56 -07:00 committed by GitHub
parent 3161ced4bc
commit 779790167e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import logging
import sys
import warnings
from typing import (
Any,
Callable,
@ -165,6 +166,11 @@ class BaseOpenAI(BaseLLM, BaseModel):
"""Initialize the OpenAI object."""
model_name = data.get("model_name", "")
if model_name.startswith("gpt-3.5-turbo") or model_name.startswith("gpt-4"):
warnings.warn(
"You are trying to use a chat model. This way of initializing it is "
"no longer supported. Instead, please use: "
"`from langchain.chat_models import ChatOpenAI`"
)
return OpenAIChat(**data)
return super().__new__(cls)
@ -599,6 +605,11 @@ class OpenAIChat(BaseLLM, BaseModel):
"due to an old version of the openai package. Try upgrading it "
"with `pip install --upgrade openai`."
)
warnings.warn(
"You are trying to use a chat model. This way of initializing it is "
"no longer supported. Instead, please use: "
"`from langchain.chat_models import ChatOpenAI`"
)
return values
@property