Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openai.error.InvalidRequestError: The completion operation does not work with the specified model, gpt-4. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993. #7878

Closed
4 of 14 tasks
pradeepdev-1995 opened this issue Jul 18, 2023 · 2 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: embeddings Related to text embedding models module

Comments

@pradeepdev-1995
Copy link

pradeepdev-1995 commented Jul 18, 2023

System Info

langchain==0.0.219
python 3.9

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

I am using the gpt-4 model with azureOpenAI using the below code.

from langchain.llms import AzureOpenAI
from langchain.chains.question_answering import load_qa_chain
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from langchain.document_loaders import DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
import os
import openai
openai.api_type = "azure"
openai.api_base = os.getenv("OPENAI_API_BASE")
openai.api_version = "2023-03-15-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")
DEPLOYMENT_NAME = 'gpt-4 model'

llm = AzureOpenAI(
    openai_api_base=os.getenv("OPENAI_API_BASE"),
    openai_api_version="2023-03-15-preview",
    deployment_name=DEPLOYMENT_NAME,
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    openai_api_type="azure",
)
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
query = "sample query"
my_loader = DirectoryLoader('/Data', glob='**/*.pdf')
docs = my_loader.load()
text_split = RecursiveCharacterTextSplitter(chunk_size = 3000, chunk_overlap = 2)
texts = text_split.split_documents(docs)
docsearch = Chroma.from_documents(texts, embeddings, metadatas=[{"source": str(i)} for i in range(len(texts))],persist_directory="./official_db").as_retriever(search_type="similarity")
docs = docsearch.get_relevant_documents(query)
chain = load_qa_chain(llm, chain_type="stuff")
result = chain.run(input_documents=docs, question=query)

But it returns the errror

openai.error.InvalidRequestError: The completion operation does not work with the specified model, gpt-4. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.

Note: The same code is working well with gpt-3.5 in azureOpenAI llm

Expected behavior

It should able to integrate gpt-4 without any issue.

@dosubot dosubot bot added Ɑ: embeddings Related to text embedding models module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Jul 18, 2023
@dosubot
Copy link

dosubot bot commented Jul 18, 2023

Answer generated by a 🤖

Answer

I understand that you're encountering an error when trying to use the GPT-4 model with the Azure OpenAI API in your LangChain application. The error message indicates that the GPT-4 model is not currently supported by the Azure OpenAI API, and you're advised to choose a different model that is supported.

To resolve this issue, you can switch to a model that is supported by the Azure OpenAI API, such as GPT-3 or Codex. You can do this by changing the DEPLOYMENT_NAME variable in your code to the name of your deployment of the supported model. For instance, if you have a GPT-3 model deployment named text-davinci-002-prod, you can set DEPLOYMENT_NAME = 'text-davinci-002-prod'.

Additionally, you might consider using the AzureChatOpenAI class from the langchain.chat_models.azure_openai module, which wraps around the Azure OpenAI Chat Completion API. This class requires a deployed model on Azure OpenAI, and the deployment_name should refer to the "Model deployment name" in the Azure portal. For example, if you have gpt-35-turbo deployed with the deployment name 35-turbo-dev, you can initialize the class like this:

AzureChatOpenAI(
    deployment_name="35-turbo-dev",
    openai_api_version="2023-03-15-preview",
)

Please note that the API version may change, so always ensure you're using the correct version.

This is one potential solution to your issue. If you find that this solution works and you believe it's a bug that could impact other users, you're encouraged to make a pull request to help improve LangChain. If this solution doesn't align with your experience or if you're still encountering issues after trying it, I recommend checking if you're using the latest version of LangChain, as updates often include bug fixes and improvements.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

@pradeepdev-1995
Copy link
Author

Yea..AzureChatOpenAI worked with GPT-4. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: embeddings Related to text embedding models module
Projects
None yet
Development

No branches or pull requests

1 participant