llm = AzureOpenAI(openai_api_key=OPENAI_API_KEY, deployment_name=OPENAI_DEPLOYMENT_NAME, model_name=MODEL_NAME)
# Configure the location of the PDF file.
pdfReader = PdfReader('data\borders.pdf')
# Extract the text from the PDF file.
raw_text = ''
for i, page in enumerate(pdfReader.pages):
text = page.extract_text()
if text:
raw_text += text
# Show first 1000 characters of the text.
raw_text[:1000]
# Split the text into chunks of 1000 characters with 200 characters overlap.
text_splitter = CharacterTextSplitter(
separator = "\n",
chunk_size = 1000,
chunk_overlap = 200,
length_function = len,
)
pdfTexts = text_splitter.split_text(raw_text)
# Show how many chunks of text are generated.
len(pdfTexts)
# Pass the text chunks to the Embedding Model from Azure OpenAI API to generate embeddings.
embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY, deployment=OPENAI_EMBEDDING_MODEL_NAME, client="azure", chunk_size=1)
# Use FAISS to index the embeddings. This will allow us to perform a similarity search on the texts using the embeddings.
# https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/faiss.html
pdfDocSearch = FAISS.from_texts(pdfTexts, embeddings)
# Create a Question Answering chain using the embeddings and the similarity search.
# https://docs.langchain.com/docs/components/chains/index_related_chains
chain = load_qa_chain(llm, chain_type="stuff")
# Perform first sample of question answering.
inquiry = "Who is the author of this book?"
docs = pdfDocSearch.similarity_search(inquiry)
chain.run(input_documents=docs, question=inquiry)
字符串
它给出了这个错误:openai.error.InvalidRequestError:完成操作不适用于指定的模型gpt-4。请选择其他模型并重试。您可以在此处了解有关每个操作可以使用哪些模型的详细信息:https://go.microsoft.com/fwlink/?linkid=2197993。
2条答案
按热度按时间aiqt4smr1#
它给出了这个错误:openai.error.InvalidRequestError:完成操作不适用于指定的模型gpt-4。请选择其他模型并重试。您可以在此处了解有关每个操作可以使用哪些模型的详细信息。
当您在配置中传递错误的模型或不正确的部署时,会发生上述错误。
根据这个**Document-1和Document-2**,需要**
text-davinci-003
模型来完成,需要text-embedding-ada-002
**模型来嵌入。当我尝试使用上面的模型时,代码执行并给我输出。
产品代码:
字符串
输出:
型
x1c 0d1x的数据
ergxz8rk2#
在OpenAI中,你必须对文本生成进行主要操作:
chatCompletion
个一些模型可用于完成(例如:GPT3.5版本0301,GPT-4等),其他可用于聊天完成(例如:GPT3.5版本0613,GPT-4等)。

在你的代码中有一些东西是不可见的,那就是langchain将在其步骤
load_qa_chain
中使用OpenAI和completion
操作。文档:https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability
的
因此,在您的情况下,您应该在设置
llm
时传递一个符合completion
查询的部署:字符串