询问 OpenAI 和 Azure AI 搜索集成中的 Intent 功能

问题描述 投票:0回答:1

我有兴趣了解 OpenAI 聊天完成和 Azure AI 搜索之间集成的意图功能背后的逻辑。具体来说,我注意到,在附加和发送聊天历史记录以进行检索增强生成 (RAG) 时,响应中有一个名为“意图”的功能。此输出似乎是发送到 AI 搜索的重新制定的查询,以确保它收到有意义的请求,从而使搜索引擎能够有效地完成其任务。

看一下:

completion = client.chat.completions.create(
    messages=[
        {"role": "user", "content": "Who is the first man to land on the moon?"},
        {"role": "assistant", "content": "The first man to land on the moon was Neil Armstrong."},
        {"role": "user", "content": "How old was he at that time?"}
    ],
    model=deployment,
    extra_body={
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": os.environ["SEARCH_ENDPOINT"],
                    "key": os.environ["SEARCH_KEY"],
                    "indexName": os.environ["SEARCH_INDEX_NAME"],
                }
            }
        ]
    }
)

聊天完成不仅会返回38岁的正确答案,还会返回“意图”功能:

print(completion.choices[0].message.context['intent'])

["How old was Neil Armstrong when he landed on the moon?", "What was Neil Armstrong's age when he landed on the moon?", "How old was Neil Armstrong when he was on the moon?"]

我对理解这种机制非常感兴趣,因为我正在使用无状态的 LangChain 代理,并且我很想实现类似的东西。

我想知道 OpenAI 使用什么提示来重新构造查询并使用“意图”功能将其发送到 Azure AI 搜索。我希望能够使用提示或某些工具来复制此功能。

我正在寻找一种解决方案,允许我汇总用户输入并将这些重新制定的查询发送给 LangChain 代理。是否有任何文档或报告解释如何在标准聊天完成中实现此意图功能?另外,OpenAI 有没有使用任何提示来重新制定和查询问题?

azure openai-api azure-openai
1个回答
0
投票

这是从聊天记录中检测到的意图,检查this 考虑您提供的所有聊天记录,获得意图。

azure openai 没有提供如何公开创建意图。 因此,您可以使用意图检测模型或带有示例的提示来创建意图。

这是一个使用提示的示例。

import json

messages=[
        {"role": "user", "content": "Who is the first man to land on the moon?"},
        {"role": "assistant", "content": "The first man to land on the moon was Neil Armstrong."},
        {"role": "user", "content": "How old was he at that time?"}
    ]

userquery = ','.join([json.dumps(i) for i in messages])

reformulation_prompt = """
You are an intelligent assistant tasked with helping users retrieve information from a database. The user may ask ambiguous, incomplete, or vague questions. Your task is to reformulate their query in a clear and precise way that can be sent to a search engine to retrieve the most relevant documents.

Here are some examples:
- User input: {"role": "user","content": "what is vector profiles?"}
  Reformulated queries: "What are vector profiles?", "Definition of vector profiles", "How do vector profiles work?"

Now, please reformulate the following user input, also give 2 to 3 Reformulated queries:
User input:""" + userquery + """
Reformulated query:
"""

t = client.completions.create(model=deployment,prompt=reformulation_prompt)
t.choices[0].text

和输出:

enter image description here

现在您在 langchain 代理中使用此响应。

© www.soinside.com 2019 - 2024. All rights reserved.