题意:langchain - Azure OpenAI API - 返回超出所问问题的额外信息
问题背景:
I am trying to develop a chatbot using streamlit,langchain Azure OpenAI api. I have been successful in deploying the model and invoking an response but it is not what I expect. here is the prompt and the code that to invoke the API
我正在尝试使用 Streamlit、Langchain 和 Azure OpenAI API 开发一个聊天机器人。我已经成功部署了模型并调用了一个响应,但结果不是我预期的。以下是提示词和调用 API 的代码。
llm = AzureOpenAI(model_name="gpt-35-turbo",
temperature=0,
openai_api_key=open_api_key,
openai_api_base=openai_api_base,
openai_api_type=openai_api_type,
openai_api_version=openai_api_version,
deployment_name=openai_deployment)
embedding = OpenAIEmbeddings(openai_api_key=open_api_key,
deployment=open_ai_embed_model,
openai_api_base=openai_api_base,
openai_api_type=openai_api_type,
)
prompt_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
Just answer the question asked. do not provide additional question and helpful answers
{context}
Question: {question}
"""
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["context", "question"]
)
Code to invoke the chain and pass the prompt 调用链并传递提示的代码
chain_type_kwargs = {"prompt": PROMPT}
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=retriever,
chain_type="stuff",
chain_type_kwargs=chain_type_kwargs
)
result = qa_chain.run(user_input)
now if I ask it a question such as “现在如果我问它一个问题,例如
What is the limit of breakfast
I get the correct response such as 我得到的正确回应是,例如
A: 20$
But the issue is after that I get bunch of additional information in a question answer format which although is produced using the context but not requested such as
但问题是,在那之后我会得到大量以问答形式呈现的额外信息,尽管这些信息是根据上下文生成的,但并未被请求,例如...
Question: What is the limit for Laundary? Answer: 10$ Question: Question: What is the guideline for selecting flights for domestic flights? Answer: Helpful answer
It seems like model is trying to use maximum tokens allowed despite clear instruction in prompt to not provide any additional information. How can I control this any inputs will be helpful?
似乎模型在提示中有明确指示不提供任何额外信息的情况下,仍然尝试使用允许的最大 token 数量。我该如何控制这种情况?任何建议都会有所帮助。
P.S: it work properly if I use OpenAI model rather than Azure OpenAI model
附注:如果我使用 OpenAI 模型而不是 Azure OpenAI 模型,它可以正常工作。
问题解决:
Please try by replacing “AzureOpenAI” with “AzureChatOpenAI”. I ran into this similar problem and making this change solved my problem.
请尝试将‘AzureOpenAI’替换为‘AzureChatOpenAI’。我遇到了类似的问题,做出这个更改后解决了我的问题。