随着新 AI 模型不断发布,为您的应用选择合适的模型可能充满挑战。GitHub Models 通过让您在示例输入上 比较不同模型和提示变体,并使用 内置评估器 验证模型输出,帮助您优化 AI 驱动的应用。
通过一个示例场景,我们将构建一个 AI 驱动的助手,帮助用户学习如何在命令行使用 Git。我们将演示如何比较不同模型,并学习如何优化提示变体以提升输出质量。
注意
- GitHub Models 目前处于公开预览阶段,可能会有变动。
- 使用受到速率限制。请参阅 使用 AI 模型进行原型设计。
测试提示
The GitHub Models 比较 view allows you to adjust model parameters and prompts to test model output.
1. 创建示例仓库
You can access the Comparisons view directly from the Models tab in any repository, but in this guide we'll create a new repository to use as a test environment.
- Navigate to the 新建仓库 page.
- Under "Owner", make sure your user account is selected.
- In the "Repository name" field, type
models-playground. - Beneath the description field, select Private to set the repository visibility.
- 点击 创建仓库。
2. 创建新提示
- On the main page of your new repository, click the Models tab.
- In the "Prompts" section, click 新提示.
- In the upper-left corner, choose a model from the dropdown menu.
3. 编写系统提示
系统提示是一组指令,在 AI 模型与用户交互之前定义其角色、行为和限制。在本示例中,我们将处理一个解释如何在命令行使用 Git 的 AI 驱动应用。
In the System prompt field, copy and paste the following text
You are an expert at using the Git version control system. I will ask questions looking for guidance on the best way to perform tasks using Git, and you will give clear, step-by-step answers that explain each step you are recommending.
You are an expert at using the Git version control system. I will ask questions looking for guidance on the best way to perform tasks using Git, and you will give clear, step-by-step answers that explain each step you are recommending.
注意
If the System text field is not editable, try choosing a different model in the model dropdown above. Not all models allow the system prompt to be modified.
4. 编写用户提示
用户提示是用户在对话期间向 AI 系统提出的直接问题或指令,AI 系统会据此作出回复。
In the User prompt field, copy and paste the following text
I want to learn how to use Git from the command line.
I want to learn how to use Git from the command line.
5. 输入示例
{{input}} 变量在 User prompt 中充当示例输入的占位符。要管理此占位符,点击 Variables 按钮并输入以下文本
When should I use rebase or merge?
When should I use rebase or merge?
6. 运行示例提示
- In the upper-right corner, click 运行.
- Make a change to the model or prompt, then run the prompt again to see what results you get.
针对同一提示测试不同模型
现在,让我们使用 Comparisons(比较)视图确定哪个模型最适合我们的应用。此视图允许您在相同输入上测试不同模型,展示准确性、创造力、语气、推理和可靠性方面的差异。这有助于我们在质量、速度、成本和一致性方面选择最符合需求的模型。
-
In the upper-left corner, click Comparisons(比较).
-
To compare different models, click 添加提示 并选择 复制原始提示 以复制您现有的系统和用户提示。至少创建原始提示的两个副本,以评估三个不同的模型。
-
Next to each prompt, click. From the Model dropdown, choose a different model for each prompt you created.
-
Click 添加输入 以创建示例输入的新行。
-
Click 添加输入。随后,在 “Input(输入)” 字段中,复制并粘贴以下文本
Text How do I modify the most recent commit message in my current branch?
How do I modify the most recent commit message in my current branch? -
Click 添加输入 再次点击,然后粘贴以下输入
Text How do I move a specific commit from one branch to a different branch?
How do I move a specific commit from one branch to a different branch? -
Click 添加输入 再一次点击,并粘贴此输入
Text How do I find the author of a specific commit in a repository's history?
How do I find the author of a specific commit in a repository's history?
-
-
To run the prompts, in the upper-right corner, click 运行.
-
尝试使用不同模型运行您的提示,并记录不同模型的 Latency(延迟)、Input(输入) 和 Output(输出) 令牌使用情况。
使用特定模型测试提示变体
如果您使用特定的 AI 模型构建应用,需要响应具有可预测性和可靠性。测试提示变体有助于
- 优化性能和质量:措辞的细微变化可能影响响应质量。通过测试变体,您可以找到产生最佳响应的表述。
- 明确指令:通过改变提示的表述,您可以识别模型最清晰理解的版本。
- 适配特定模型行为:您可以根据特定模型的语言解读方式定制输入。
- 验证输出格式:您可能需要列表、段落、代码块或特定语气。测试提示变体帮助您强制特定的结构或风格。
现在,让我们使用 GitHub Models 对您特定模型的用户输入进行提示变体测试。
1. 添加提示变体
在本示例场景中,为每列 选择相同的模型,但通过编辑现有提示的 “User prompt(用户提示)” 字段来提供不同的提示变体。对每个提示,点击.
-
Click 在 “Prompt 2”。随后,在 “User prompt(用户提示)” 字段中,复制并粘贴以下文本
Text I want to learn how to use Git from the command line, but explain it to me like I am five years old.
I want to learn how to use Git from the command line, but explain it to me like I am five years old. -
Click 在 “Prompt 3”,然后粘贴以下输入
Text I want to learn how to use Git from the command line. Give me instructions in the form of a haiku.
I want to learn how to use Git from the command line. Give me instructions in the form of a haiku.
2. 运行提示变体
- To run the prompts, in the upper-right corner, click 运行.
- 尝试不同的提示变体,并比较模型给出的输出类型。
评估模型输出
我们已经在 GitHub Models 中测试了不同模型和提示变体,下一步是解释并比较结果,以便为我们的 AI 驱动应用做出明智决策。
在示例场景中运行模型后,Input(输入)、Output(输出) 令牌使用量和 Latency(延迟) 会在每次运行后显示。令牌使用量很重要,因为它直接影响 成本、性能和模型限制。
- 由于大多数模型对输入和输出的每个令牌都收费,使用更多令牌会增加您的成本。
- 每个模型还有最大令牌限制(称为上下文窗口),超出后可能导致错误或截断的响应。
- 较长的提示可能导致响应时间变慢或降低清晰度,而简洁的提示通常能产生更好、更高效的输出。
利用 GitHub Models 测试令牌使用量和延迟,可帮助您保持在限制范围内,管理成本,并提升 AI 驱动应用的整体效果。
使用评估器评判输出
根据您评估的提示和模型数量,手动筛选模型输出可能会让人不堪重负。为帮助评估每个模型输出的质量,您可以使用 Evaluators(评估器) 在清晰度、准确性和相关性等关键维度上对结果打分。您可以定义自己的评估标准,或使用内置评估器自动对输出进行评级,从而更容易识别表现最佳的模型和提示变体。
在本示例场景中,我们使用 String check(字符串检查) 评估器来检测输出中是否包含特定字符串。
-
在 Prompts(提示)字段的右下角,点击 添加评估器 并选择 String check(字符串检查)。
-
In the Name field, enter "Amend check", then copy and paste the following input for the Value field
Text git commit --amend
git commit --amend -
To run the prompts, in the upper-right corner, click 运行.
-
The prompt output will now show a Pass or Fail label, letting you know which model contained the required string.
欲了解更多关于相似度、可信度和相关性等预构建评估器,请参阅 Evaluating AI models(评估 AI 模型)。
后续步骤
现在,您已经了解如何使用 GitHub Models 测试模型、优化提示并评估输出,便可以开始为您的 AI 驱动应用构建提示。创建提示后,您可以通过将 .prompt.yml 文件提交到仓库来存储、版本化和共享提示。这使提示受版本控制,并便于在提示和模型优化上进行协作。更多信息请参阅 Storing prompts in GitHub repositories(在 GitHub 仓库中存储提示)。
加入社区
如需提问或反馈,请查看此 GitHub Models 讨论帖子。
想了解其他人如何使用 GitHub Models,请访问 GitHub 社区的 Models 讨论区。