langchain - Azure OpenAI api - returning additional information than the asked question

题意: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’。我遇到了类似的问题,做出这个更改后解决了我的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值