作者:来自 Elastic Jonathan Simon

最近,Elastic 宣布 AI 观测助手现已正式向所有 Elastic 用户开放。该 AI 观测助手为 Elastic 观测提供了一种新工具,提供了大型语言模型(LLM)连接的聊天和上下文洞察,以解释错误并建议纠正措施。类似于微软 Copilot 是一款人工智能伴侣,为开发人员引入了新的能力并提高了生产力,Elastic AI 观测助手是一款可以帮助你快速从你的可观测数据中获得更多价值的人工智能伴侣。
本博客文章提供了关于如何使用 Azure OpenAI 作为后端 LLM 设置 AI 观测助手的分步指南。一旦你设置好了 AI 观测助手,本文将向你展示如何将文档添加到 AI 观测助手的知识库中,并演示 AI 观测助手如何利用其知识库改进其响应,以解决特定问题。
设置 Elastic AI 观测助手:创建 Azure OpenAI 密钥
首先,创建一个 Microsoft Azure OpenAI API 密钥,以便验证来自 Elastic AI 观测助手的请求。前往 Microsoft Azure,并使用现有订阅或在 Azure 门户创建一个新订阅。
目前,访问 Azure OpenAI 服务需要通过申请获得权限。请参阅官方 Microsoft 文档,了解当前的先决条件。

在 Azure 门户中,选择 Azure OpenAI。

在 Azure OpenAI 服务中,单击 "Create" 按钮。

输入实例 Name 并单击 Next。

选择你对 Azure OpenAI 实例的网络访问偏好,并单击 "Next"。

添加可选的 Tags ,然后点击 "Next"。

确认设置并单击 "Create" 以创建 Azure OpenAI 实例。

一旦实例创建完成,点击 "Go to resource" 按钮。

单击 Manage keys 链接以访问实例的 API 密钥。

复制你的 Azure OpenAI API Key 和 Endpoint,并将它们都保存在安全的地方,以便在后续步骤中使用。

接下来,单击 "Model deployments" 以在刚刚创建的 Azure OpenAI 实例中创建部署。

单击 "Manage deployments" 按钮打开 Azure OpenAI Studio。

单击 Create new deployment 按钮。

选择你要使用的模型类型并输入部署名称。 记下部署名称,以便在后续步骤中使用。 单击 "Create" 按钮来部署模型。

设置 Elastic AI Assistant for Observability:在 Elastic Cloud 中创建 OpenAI 连接器
本文中的其余说明将在 Elastic Cloud 中进行。 你可以使用现有部署,如果你是首次尝试 Elastic Cloud,则可以创建新的 Elastic Cloud 部署作为免费试用版。 另一个开始选择是从 Microsoft Azure Marketplace 创建 Elastic 部署。

下一步是在 Elastic Cloud 中创建 Azure OpenAI 连接器。 在部署的 Elastic Cloud 控制台中,选择顶级菜单,然后选择 Stack Management。

在 "Stack Management " 页面中选择 "Connectors"。

选择 Create connector。

选择 Azure OpenAI 的连接器。

输入你为连接器选择的 Name 。 选择 Azure OpenAI 作为 OpenAI 提供商。

使用以下格式输入端点 URL:
- 将 {your-resource-name} 替换为上一步中在 Azure 门户中创建的 name of the Azure Open AI instance。
- 将 {deployment-id} 替换为上一步中在 Azure 门户中创建模型部署时指定的 Deployment name。
- 将 {api-version} 替换为 Azure OpenAI 参考页的完整部分中列出的有效 Supported versions 之一。
bash
https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}
你完正的端点 URL 应如下所示:
bash
https://example-openai-instance.openai.azure.com/openai/deployments/gpt-4-turbo/chat/completions?api-version=2024-02-01
输入你在上一步中复制的 API 密钥。 然后单击 "Save & test" 按钮。

在 "Edit Connector " 弹出窗口中,单击 "Run" 按钮以确认连接器配置有效并且可以成功连接到 Azure OpenAI 实例。

成功的连接器测试应该如下所示

添加示例日志记录
现在你已经使用 AI Assistant 连接器设置了 Elastic Cloud 部署,让我们添加一个示例日志记录来演示 AI Assistant 如何帮助你更好地理解日志数据。
我们将使用 Elastic Dev Tools 添加单个日志记录。 单击顶层菜单并选择 Dev Tools。

在开发工具的控制台区域中,输入以下 POST 语句:
swift
1. POST /logs-elastic_agent-default/_doc
2. {
3. "message": "Status(StatusCode=\"FailedPrecondition\", Detail=\"Can't access cart storage. \nSystem.ApplicationException: Wasn't able to connect to redis \n at cartservice.cartstore.RedisCartStore.EnsureRedisConnected() in /usr/src/app/src/cartstore/RedisCartStore.cs:line 104 \n at cartservice.cartstore.RedisCartStore.EmptyCartAsync(String userId) in /usr/src/app/src/cartstore/RedisCartStore.cs:line 168\").",
4. "@timestamp": "2024-02-22T11:34:00.884Z",
5. "log": {
6. "level": "error"
7. },
8. "service": {
9. "name": "cartService"
10. },
11. "host": {
12. "name": "appserver-1"
13. }
14. }
然后单击绿色的 "Run" 按钮来运行 POST 命令。

你应该看到 201 响应,确认示例日志记录已成功创建。

使用 Elastic AI 助手
现在你已经有了可以使用的日志记录,让我们跳转到 Observability Logs Explorer,看看 AI Assistant 如何与日志数据交互。 单击顶层菜单并选择可观测性。

选择 Logs Explorer 来浏览日志数据。

在 Logs Explorer 搜索框中,输入文本 "redis" 并按 Enter 键执行搜索。

单击 View all matches 按钮以包含所有搜索结果。

你应该会看到之前通过开发工具插入的一条日志记录。 单击展开图标可查看日志记录的详细信息。

你应该看到日志记录的展开视图。 我们不会尝试自己去理解它的内容,而是使用人工智能助手来总结它。 单击 What's this message? 按钮。

我们得到了一个相当笼统的答案。 根据我们尝试分析的异常或错误,这仍然非常有用,但我们可以通过向 AI Assistant 知识库添加额外的文档来使其更好。

让我们看看如何使用 AI Assistant 的知识库来提高其对特定日志消息的理解。
创建 Elastic AI Assistant 知识库
从 "Observability " 菜单中选择 "Overview"。

点击窗口右上角的 AI Assistant 按钮。

单击 Install Knowledge base 按钮。

单击顶层菜单并选择 Stack Management。

然后选择 AI Assistants。

单击 Elastic AI Assistant for Observability。

选择 Knowledge base 选项卡。

单击 "New entry " 按钮并选择 "Single entry"。

将其 Name 设置为 "cartservice" 并输入以下文本作为内容:
markdown
1. I have the following GitHub issue. Store this information in your knowledge base and always return the link to it if relevant.
2. GitHub Issue, return if relevant
4. Link: https://github.com/elastic/observability-examples/issues/25
6. Title: Cartservice Intermittent connection issue
8. Body:
9. The cartservice occasionally encounters storage errors due to an unreliable network connection.
11. The errors typically indicate a failure to connect to Redis, as seen in the error message:
13. Status(StatusCode="FailedPrecondition", Detail="Can't access cart storage.
14. System.ApplicationException: Wasn't able to connect to redis
15. at cartservice.cartstore.RedisCartStore.EnsureRedisConnected() in /usr/src/app/src/cartstore/RedisCartStore.cs:line 104
16. at cartservice.cartstore.RedisCartStore.EmptyCartAsync(String userId) in /usr/src/app/src/cartstore/RedisCartStore.cs:line 168')'.
17. I just talked to the SRE team in Slack, they have plans to implement retries as a quick fix and address the network issue later.
单击 Save 以保存新的知识库条目。

现在让我们回到 Observability Logs Explorer.。 单击顶层菜单并选择可 Observability。

然后选择 "Logs " 下的 "Explorer"。

展开与之前相同的日志条目,然后单击 What's this message? 按钮。

你现在得到的回复应该更加相关。

使用包含你自己的数据的知识库试用 Elastic AI Assistant
现在你已经了解了设置 Elastic AI Assistant for Observability 是多么容易,请继续亲自尝试一下。 注册 14 天免费试用。 你可以在几分钟内快速启动 Elastic Cloud 部署,并拥有自己的搜索驱动的 AI 知识库来帮助你完成最重要的工作。
本文中描述的任何特性或功能的发布和时间安排均由 Elastic 自行决定。 当前不可用的任何特性或功能可能无法按时交付或根本无法交付。
原文:Get started with Elastic AI Assistant for Observability and Microsoft Azure OpenAI | Elastic Blog