使用LLMs进行自动代码审查

Certainly! Here's the translation of the phrase "How Faire implemented an LLM-powered automated review pipeline to boost productivity" into simplified Chinese while keeping the HTML structure intact: ```html 如何Faire实施了由LLM驱动的自动化审核流程以提升生产力 ``` This HTML structure maintains the text content while ensuring it can be integrated into a web page or document seamlessly.

Text image: Automated code reviews with LLMs

大型语言模型(LLMs)在科技行业中引起了巨大的轰动,改进了各种形式的自然语言处理和任务自动化,尤其是随着ChatGPT的推出。 在OpenAI推出其API产品后不久,Faire成立了一个AI基础团队,以更好地理解和利用这个领域。 我们举办了一场为期三天的AI黑客马拉松活动,就像我们的黑客周一样,公司各部门的贡献者组成团队,原型开发了各种基于LLM技术的功能理念。 活动取得了巨大成功,共有92个项目提交。

Faire 工程团队投资进一步的项目之一是自动化审查。在 Faire,我们相信代码审查的价值。这个过程对我们编写代码至关重要。虽然代码审查的许多方面需要更深入项目背景的相关信息,但也有一系列更通用的审查要求可以在额外背景信息的情况下考虑。这些包括期望明确的标题和描述、充足的测试覆盖、风格指南的执行,或者在服务边界上发现不兼容的更改。

往往情况下,LLMs很适合执行代码审查的更通用方面。有关拉取请求的足够信息,比如元数据、差异、构建日志或测试覆盖报告,LLMs可以有效地被提示添加有用信息,标记危险更改,甚至自动修复简单问题。

在本文中,我们将描述Faire开发的评论生命周期和RAG(检索增强生成)设置,以支持各种特定于上下文的自动评论。我们还将着重介绍我们的测试覆盖率审核,该审核突出显示覆盖率低的区域,并建议额外的测试案例,以展示评论自动化的灵活性和价值。

Fairey,我们的LLM Orchestrator服务

Faire已开发了一个LLM orchestrator服务,我们将其命名为Fairey 🧚。这个orchestrator服务处理来自我们用户的聊天请求,将它们分解为生成响应所需的所有必要步骤。这包括调用LLM模型,获取额外信息,调用函数以及其他各种逻辑。

Fairey与OpenAI的助手API密切集成。 我们为管理AI助手创建了一个简单的UI,例如调整助手的指令或添加它可以调用的功能。 功能为助手提供了额外的能力,例如获取其他信息 - 这种技术被称为RAG(检索增强生成)。

Certainly! Here's the HTML structure with the translated text in simplified Chinese: ```html

RAG 迅速成为行业标准方法,用于向LLM提供必要信息,以执行特定上下文任务。LLM接受广泛信息培训,但通常不包括贵公司的专有数据。即使您已经像Faire一样开始调优开源模型,LLM通常仍需要任何特定案例的信息 — 在我们的审查流程中,这指的是被审查的代码变更信息。

``` In this HTML snippet: - `

` tags are used to enclose the translated text for paragraph formatting. - The text is translated into simplified Chinese while preserving the structure of the HTML document.

Input form for configuring the behavior of an OpenAI assistant, filled with the settings of a test coverage helper.
Screenshot of Faire’s internal OpenAI Assistant manager.

每次函数调用都在编排服务中定义了一个回调,我们会在GPT决定我们应该调用时调用它。这使得Fairey能够决定何时获取所需的数据,而不必在主提示中发送过多的额外信息。

Certainly! Here's the translation of "Review lifecycle" into simplified Chinese while maintaining HTML structure: ```html 审查生命周期 ``` In this translation: - `` is used to wrap the text. - `lang="zh-CN"` specifies the language as simplified Chinese. - "审查生命周期" is the translated text for "Review lifecycle".

费雷还连接到Github的webhook,每当拉取请求上发生有趣的事情时发送事件负载。我们会以各种方式对每个Github webhook做出反应,包括检查是否现在准备处理拉取请求的任何自动审阅。对于符合审阅标准的拉取请求(例如编程语言或特定的区别内容),费雷将与OpenAI交互以执行审阅。

Diagram showing the lifecycle flow of GitHub webhooks through Fairey and out to OpenAI.
A simplification of how Fairey orchestrates interactions with Open AI’s Assistant APIs.

Certainly! Here's the HTML structure with the translated text in simplified Chinese: ```html

与OpenAI互动后,我们会检查输出,看看Fairey有没有有用的内容。当有用的内容存在时,我们会在拉取请求上发布审查。审查通常包括评论和提示,甚至可能包括对代码的具体修改建议。

``` In simplified Chinese: ```html

与OpenAI互动后,我们会检查输出,看看Fairey有没有有用的内容。当有用的内容存在时,我们会在拉取请求上发布审查。审查通常包括评论和提示,甚至可能包括对代码的具体修改建议。

``` This HTML snippet preserves the structure while displaying the translated text in simplified Chinese.

为了避免重复评论,每个由Fairey留下的评论也会包含一些隐藏的元数据,以便我们可以检查已经涵盖的内容。这还可能允许在之前的评论线程上继续,或者将之前评论的输出作为增量评论的输入。

测试覆盖率审查

为了更好地展示Faire的自动评论如何工作,我们将更深入地研究测试覆盖率审查。测试覆盖率是一种衡量特定代码分支在运行测试套件时是否实际执行的方式。举个简单的例子,让我们想象一个拉取请求,该请求正在实施一个新功能,并受到我们设置框架中的新设置的保护。代码可能会看起来像这样:

const isSettingEnabled = getSettingValue();
if (myNewSetting) {
doTheNewThing();
} else {
doTheOldThing();
}

测试覆盖率告诉我们,我们的测试是否覆盖了代码中启用和未启用设置的分支。也许我们还没有为新代码添加测试,代码审查者会指出我们需要添加测试!

在我们的前端(Web)代码库中,Faire 使用 Jest 来进行单元测试套件。我们强制用户界面代码的最低测试覆盖率。我们在拉取请求中的测试覆盖率是逐步计算的,也就是说当我们创建拉取请求时,我们的 CI 系统将使用 --changedSince 标志执行测试套件,导致 Jest 仅执行对拉取请求中包含的源文件有依赖的测试。我们还设置了 --coverage 标志,这会导致 Jest 收集并输出覆盖率报告,然后可以在我们的内部开发门户网站中查看(请参见下面的示例)。

Example test coverage report, with a table showing the percentage of coverage for statements, branches, functions, and lines.
An example test coverage report for a pull request.

测试覆盖率审核会在我们收到 Github 的 webhook 通知测试覆盖检查运行失败后触发。当覆盖检查失败时,意味着拉取请求中的增量覆盖率低于我们所需的覆盖率阈值。通常情况下,这是因为作者添加了新的源代码文件但没有相应的单元测试,或者在代码中创建了新的分支而现有测试未覆盖到。

测试覆盖率审查使用了自定义助手(如上图所示)。它可以访问几个重要的功能工具,包括:

  • 获取拉取请求中更改的diff的fech_github_diff
  • 获取GitHub拉取请求,获取拉取请求的元数据,例如标题、描述等。
  • 获取代码覆盖率报告,加载lcov报告,来自我们CI构建工件
  • 获取github文件内容,加载给定文件的全部内容

Sure, here's how you could structure that sentence in HTML with the simplified Chinese translation: ```html

助手说明,即系统提示信息的同义词,大致如下:

``` In this HTML snippet: - `

` is the paragraph tag indicating a paragraph of text. - `助手说明` means "assistant instructions". - `即` means "that is" or "namely". - `系统提示信息` means "system prompt message". - `同义词` means "synonym". - `大致如下` means "something like". This should maintain the structure of the HTML while providing the translated text in simplified Chinese.

You are an expert React and Typescript programmer.
Using the test coverage reports and contents of source code and corresponding
test files, suggest new test cases that would increase coverage of the source
code.

Test files in our frontend codebases are located in a `./__tests__/` folder
next to the source code, with `*.test.ts` suffix instead of `*.ts`. A couple
of examples,
```yaml
- source: `src/something.ts`
tests: `src/__tests__/something.test.ts`.
- source: `app/home/utils.ts`
tests: `app/home/__tests__/utils.test.ts`
```

我们的代码库在每次拉取请求时收集lcov代码覆盖报告。测试覆盖率审查被指示使用覆盖报告来确定代码覆盖率较低的区域。

Sure, here's the translation in simplified Chinese, maintaining the HTML structure: ```html

除了这些系统级别的助理指示外,审查还有一个特定的提示模板。即将发送的聊天消息大致如下:

``` This HTML snippet contains the translated text while preserving the HTML structure around it.
You are performing a code review of ${diffSource}. The PR has failing test coverage checks for ${failingCoverage.join(",")}.

Use the diff and the code coverage report to identify the changes in the PR that are not covered by tests.
For those changes, suggest test cases that should be added to the code.
Use the existing test file as a reference when suggesting test cases. Do not suggest cases that are already covered by the existing tests.

当用户提交拉取请求时,我们的构建流水线最终将以失败的测试覆盖率检查运行返回报告。这将导致Fairey启动一个助手聊天,使用上面的提示。为了产生回复,ChatGPT将发出函数调用,Fairey执行并提交回ChatGPT,最终产生一个回复消息。

Sure, here's the translation of "Then, we craft a Github Review using the reply, and post it to the pull request" in simplified Chinese, keeping the HTML structure intact: ```html 然后,我们使用回复撰写 GitHub 评审,并将其发布到拉取请求中。 ``` This translation maintains the structure and meaning while converting the text into simplified Chinese.

A GitHub review comment left by the automated review. It contains suggestions of where to add test coverage.
An example review for a pull request that didn’t include any unit tests.

评估评论

LLM非常灵活,可以接受各种输入,但在输出方面同样多样化。GPT(生成式预训练变压器)模型只是预测模型,可能会犯错,产生幻觉,并生成过于冗长或无关的输出。我们使用两个信号评估评论的质量:一个是定量的,另一个是定性的。我们的定量评估涉及使用LLM评估框架,而定性评估涉及调查最终用户(我们的工程师)。

A more elaborate lifecycle diagram showing flow from GitHub webhooks through Fairey to OpenAI, Gentrace and DX
A simplified overview of how we assess the quality of the review outputs

为了量化质量,我们建立了一组测试用例,对评审进行迭代,并重新运行它们,计算正确性分数。为了实现这一流程,Faire 使用LLM评估工具,比如Gentrace、CometLLM或Langsmith提供的工具。每当我们进行评审时,我们会将输入和输出发送给评估工具。每个输入/输出对可以用来创建一个测试用例。然后,当我们对评审进行迭代(比如调整提示,更改模型,获取不同数据等),我们可以对所有测试用例重新运行评审流水线。然后,我们使用LLM来评估结果的质量。

Sure, here's how you can write that sentence in simplified Chinese while keeping the HTML structure intact: ```html

那就是对的 — LLM 评审输出是使用 LLM 来评估的!

``` In this HTML snippet: - `

` and `

` are used to denote a paragraph. - The Chinese text is enclosed within the paragraph tags. This maintains the HTML structure while presenting the translated text in simplified Chinese.

Certainly! Here is the HTML structure with the translated text in simplified Chinese: ```html

关于质量评分,我们利用DX,一个用于衡量和提高开发者生产力的平台。每当进行评审时,DX 都会收到通知,并向拉取请求的作者请求调查反馈。这些反馈,无论是好是坏,随后会被导入到Gentrace中,用作筛选良好测试用例的信号。

``` This HTML snippet encapsulates the translated text in simplified Chinese, maintaining the structure for web or document formatting.

固定装置

Certainly! Here is the translated text in simplified Chinese, while keeping the HTML structure intact: ```html

拉取请求审查在性质上是非常短暂的。通常,在工程师准备迭代行为并重新评估之前,关于拉取请求相关审查的信息可能已经发生了变化。

```

Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html 为了支持这一点,Fairey 支持“fixtures”功能,其中函数调用的输出被保存为快照,以便在稍后的运行中重新使用。我们通过 OpenAI 的线程历史实现这一点,将函数调用的结果提取到 fixture 文件中,然后上传到存储中。在以后的审核中运行时,这些 fixture 文件将被读取并传递给 Fairey,作为 ChatGPT 调用函数时应该给出的覆盖内容。 ``` This translation maintains the structure of the HTML text while providing the Chinese translation of the original English text.

自动评论的早期影响

Sure, here's the translation of the provided text into simplified Chinese while keeping the HTML structure intact: ```html

在 Faire,我们相信赋予生产力。利用LLMs自动化审查有助于通过简化审查流程,减少简单问题的审查延迟,并释放我们的人才,集中精力解决审查中最具影响力和复杂的部分 — 如正确满足产品需求、实施清晰的架构、长期可维护性和适当的代码复用。

``` This HTML snippet contains the translated text in simplified Chinese within a paragraph (`

` tag), maintaining the original HTML structure.

到目前为止,我们已经看到了成功 - 通过积极用户满意度和高准确性来衡量 - 自动化审查。

  • 强制执行样式指南
  • 评估标题和描述的质量
  • Sure, here's how you could write that in simplified Chinese while maintaining the HTML structure: ```html 诊断构建失败,包括执行自动修复操作 ``` In HTML context, it would be embedded within tags like this: ```html

    诊断构建失败,包括执行自动修复操作

    ``` This HTML structure ensures that the text is properly formatted within a paragraph (`

    `) tag.

  • Sure, here's the translation of "Suggest additional test coverage" into simplified Chinese, keeping the HTML structure intact: ```html 建议增加测试覆盖率 ``` In this HTML snippet, the Chinese text is represented within `` tags for clarity: ```html 建议增加测试覆盖率 ``` This will display "建议增加测试覆盖率" on a webpage in simplified Chinese.
  • Certainly! Here's the translation of "Detect backward-incompatible changes" in simplified Chinese while keeping the HTML structure: ```html 检测向后不兼容的更改 ``` In HTML, it would look like this: ```html 检测向后不兼容的更改 ``` This HTML structure ensures that the text is displayed correctly and can be styled if needed.

还有增长的空间 — 每种新的审查类型,产出质量最初会有很大差异。我们发现,对于LLMs来说,笨重的输入会导致不可预测的输出。获得C的完美结合 — 一致、简洁和正确 — 需要对输入内容和结构进行良好的细化处理,一个广泛的测试用例集,以及使用更复杂的提示技术,如自我评估和CoT (Chain-of-Thought)。使用我们的迭代周期,工程师能够自信地迭代提示和能力,推动效力。

Sure, here's the translated text in simplified Chinese while maintaining HTML structure: ```html 当正确使用时,LLM(大型语言模型)可以为工程师提供一种令人兴奋的新辅助水平,帮助他们快速向用户交付高质量产品。我们很兴奋能够乘风破浪,体验生成式人工智能的力量。🌊 ``` This HTML snippet preserves the structure of the text and includes the wave emoji at the end.

Sure, here is the translation of the provided text into simplified Chinese, while keeping the HTML structure intact: ```html 这对于 Faire 的工程团队来说是一项开创性的工作,但如果没有 Luke Bjerring、Btara Truhandarien、Justin Fangrad、Jordan Upiter 和当然也包括原始“向后兼容性 Cop” AI 黑客马拉松原型背后的团队的巨大贡献,这是不可能完成的:Mike Welsh、Runqi Luo、Korosh Ahangar、Noah Eisen、James Oliver 和 Ximing Yang 🙏 ``` This HTML structure ensures that the text remains formatted and can be integrated directly into web content or emails without losing formatting details.

有兴趣加入一个团队,为全球的小企业提供有趣的工作?申请开放职位:https://www.faire.com/careers

2024-08-28 04:17:25 AI中文站翻译自原文