创建 AI Shell 以帮助命令行用户找到正确的命令来使用、从错误中恢复,并更好地了解它们生成的命令和输出。 遵循并演练一些示例以开始使用 AI Shell。
启动 AI Shell
使用 Start-AIShell 模块中的命令在 Windows 终端中打开挎斗体验。 当 AI Shell 启动时,它会提示你选择代理。
使用 AI Shell
在使用 Azure OpenAI 代理之前,必须创建包含终结点、API 密钥和系统提示的配置。 启动 AI Shell,选择代理,然后运行 /agent config。
在打开的 JSON 配置文件中,必须提供终结点、部署名称、模型版本和 API 密钥。 可以将系统提示属性配置为更好地将模型与特定用例建立基础,默认包括 PowerShell 专家。 此外,如果希望使用 OpenAI,可以在 JSON 文件中注释掉的示例中仅使用 OpenAI 中的 API 密钥配置代理。
Azure 代理旨在将 Azure Copilot 体验直接带到你的命令行中。 它为 Azure CLI 和 Azure PowerShell 命令提供了帮助。 若要使用此代理,需要使用 Azure CLI 中的 az login 命令登录到 Azure。
使用 AI Shell 与代理交互
对每个代理使用这些示例查询。
Azure OpenAI 代理
- “如何在 PowerShell 中创建名为 helloworld 的文本文件?
- “PowerShell 中的开关和参数之间的区别是什么?
- 如何获取计算机上的前 10 个 CPU 密集型进程?
Azure Copilot Agent
- “如何使用 Azure CLI 创建新的资源组?”
- “如何在 Azure PowerShell 中列出存储帐户?
- “什么是 Application Insights?”
- “如何使用 Azure CLI 创建 Web 应用?”
下面是一个演示,演示了 Azure 代理的操作:
切换代理
可以使用聊天消息中的 @<agentName> 语法在代理之间切换。 例如
在两个代理之间切换的动画
还可以使用聊天命令切换代理。 例如,若要切换到 openai-gpt 代理,请使用 /agent use openai-gpt。
聊天命令
默认情况下,aish 提供了一组用于与 AI 模型交互的基本聊天命令。 若要获取命令列表,请使用聊天会话中的 /help 命令。
Name Description Source
──────────────────────────────────────────────────────────────────────
/agent Command for agent management. Core
/cls Clear the screen. Core
/code Command to interact with the code generated. Core
/dislike Dislike the last response and send feedback. Core
/exit Exit the interactive session. Core
/help Show all available commands. Core
/like Like the last response and send feedback. Core
/refresh Refresh the chat session. Core
/render Render a markdown file, for diagnosis purpose. Core
/retry Regenerate a new response for the last query. Core
插入代码
与代理聊天时,可以使用 /code post 命令将响应中的代码自动插入到工作 shell 中。 这是快速获取在 shell 中运行所需的代码的最简单方法。 还可以使用热键 Ctrl+d,Ctrl+d 将代码插入工作 shell。
命令的键绑定
AI Shell 具有 /code 命令的键绑定。 它们目前是硬编码的,但在将来的版本中将支持自定义密钥绑定。
| 键绑定 | 命令 | 功能性 |
|---|---|---|
| Ctrl+d Ctrl+c | /code copy |
将所有 生成的代码片段 复制到剪贴板 |
| 控制+<n> | /code copy <n> |
将第 n 个生成的代码片段复制到剪贴板 |
| 控制+dCtrl+d | /code post |
发布 所有 生成的代码片段到已连接的应用程序 |
| ctrl+d<n> | /code post <n> |
将 第 n 个 生成的代码片段发布到已连接的应用程序 |
此外,可以使用以下键盘快捷方式更轻松地在窗格之间切换。
| 键绑定 | 功能性 |
|---|---|
| 替代+右箭头 | 将光标移动到右侧 AI Shell 窗格 |
| 替代+左箭头 | 将光标移动到左侧 PowerShell 窗格 |
解决错误
如果在工作终端中遇到错误,可以使用 Resolve-Error cmdlet 将此错误发送到打开的 AI Shell 窗口以解决问题。 此命令要求 AI 模型帮助你解决错误。
调用 AI Shell
可以使用 Invoke-AIShell cmdlet 将查询发送到打开的 AI Shell 窗口中的当前代理。
此命令允许你从工作终端与 AI 模型进行交互。
使用 Invoke-AIShell 