Skip to content

Commit

Permalink
✨ feat: Add summary prompt and refine prompt for git diff summary
Browse files Browse the repository at this point in the history
Add summary prompt and refine prompt for git diff summary to create clean and comprehensive commit messages in the conventional commit convention and explain WHAT were the changes and WHY the changes were done.
  • Loading branch information
canisminor1990 committed Nov 23, 2023
1 parent f5d0143 commit b01df9c
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 21 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ English ・ [简体中文](./README.zh-CN.md) ・ [Report Bug][github-issues-lin
| [**💌 Lobe Commit**][lobe-commit-github] [(中文)][lobe-commit-github-cn]<br/>CLI tool that leverages Langchain/ChatGPT to generate Gitmoji-based commit messages.<br/><br/>[![][lobe-commit-version] ![][lobe-commit-download]][lobe-commit-url] | [![][lobe-commit-cover]][lobe-commit-github] |
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------- |
| [**🌏 Lobe i18n**][lobe-i18n-github] [(中文)][lobe-i18n-github-cn]<br/>Automation tool for the i18n (internationalization) translation process, powered by ChatGPT. It supports features such as automatic splitting of large files, incremental updates, and customization options for the OpenAI model, API proxy, and temperature.<br/><br/>[![][lobe-i18n-version] ![][lobe-i18n-download]][lobe-i18n-url] | [![][lobe-i18n-cover]][lobe-i18n-github] |
| [**🔖 Lobe label**][lobe-label-github]<br/>Automatically copy issues labels from template repo.<br/><br/>[![][lobe-label-version] ![][lobe-label-download]][lobe-label-url] | [![][lobe-label-cover]][lobe-label-github] |
| [**🔖 Lobe label**][lobe-label-github] [(中文)][lobe-label-github-cn]<br/>Automatically copy issues labels from template repo.<br/><br/>[![][lobe-label-version] ![][lobe-label-download]][lobe-label-url] | [![][lobe-label-cover]][lobe-label-github] |

<div align="right">

Expand Down Expand Up @@ -143,31 +143,32 @@ This project is [MIT](./LICENSE) licensed.
[lobe-chat]: https://github.com/lobehub/lobe-chat
[lobe-commit-cover]: https://gw.alipayobjects.com/zos/kitchen/3%26ByxtP39X/preview.webp
[lobe-commit-download]: https://img.shields.io/npm/dt/@lobehub/commit-cli?labelColor=black&&style=flat-square
[lobe-commit-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-commit
[lobe-commit-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-commit/README.md
[lobe-commit-github-cn]: https://github.com/lobehub/lobe-cli-toolbox/blob/master/packages/lobe-commit/README.zh-CN.md
[lobe-commit-url]: https://www.npmjs.com/package/@lobehub/commit-cli
[lobe-commit-version]: https://img.shields.io/npm/v/@lobehub/commit-cli?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[lobe-i18n-cover]: https://gw.alipayobjects.com/zos/kitchen/AH7rvv06qn/preview-i18n.webp
[lobe-i18n-download]: https://img.shields.io/npm/dt/@lobehub/i18n-cli?labelColor=black&&style=flat-square
[lobe-i18n-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-i18n
[lobe-i18n-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-i18n/README.md
[lobe-i18n-github-cn]: https://github.com/lobehub/lobe-cli-toolbox/blob/master/packages/lobe-i18n/README.zh-CN.md
[lobe-i18n-url]: https://www.npmjs.com/package/@lobehub/i18n-cli
[lobe-i18n-version]: https://img.shields.io/npm/v/@lobehub/i18n-cli?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[lobe-label-cover]: https://gw.alipayobjects.com/zos/kitchen/qeTFEqgF8O/437shots_so.png
[lobe-label-download]: https://img.shields.io/npm/dt/@lobehub/label-cli?labelColor=black&&style=flat-square
[lobe-label-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-label
[lobe-label-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-label/README.md
[lobe-label-github-cn]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-label/README.zh-CN.md
[lobe-label-url]: https://www.npmjs.com/package/@lobehub/label-cli
[lobe-label-version]: https://img.shields.io/npm/v/@lobehub/label-cli?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[lobe-theme]: https://github.com/lobehub/sd-webui-lobe-theme
[pr-welcome-link]: https://github.com/lobehub/lobe-cli-toolbox/pulls
[pr-welcome-shield]: https://img.shields.io/badge/%F0%9F%A4%AF%20PR%20WELCOME-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge
[profile-link]: https://github.com/lobehub
[shebang-download]: https://img.shields.io/npm/dt/@lobehub/cli-shebang?labelColor=black&style=flat-square
[shebang-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-cli-shebang
[shebang-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-cli-shebang/README.md
[shebang-shield]: https://img.shields.io/npm/v/@lobehub/cli-shebang?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[shebang-url]: https://www.npmjs.com/package/@lobehub/cli-shebang
[split]: https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png
[ui-download]: https://img.shields.io/npm/dt/@lobehub/cli-ui?labelColor=black&style=flat-square
[ui-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-cli-ui
[ui-github]: https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-cli-ui/README.md
[ui-shield]: https://img.shields.io/npm/v/@lobehub/cli-ui?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[ui-url]: https://www.npmjs.com/package/@lobehub/cli-ui
8 changes: 6 additions & 2 deletions packages/lobe-commit/src/core/Commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ChatPromptTemplate } from 'langchain/prompts';
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { execSync } from 'node:child_process';

import { promptCommits } from '@/prompts/commits';
import { SUMMARY_PROMPT, SUMMARY_REFINE_PROMPT, promptCommits } from '@/prompts/commits';
import { selectors } from '@/store';
import { Config } from '@/types/config';
import { ModelTokens } from '@/types/models';
Expand Down Expand Up @@ -97,7 +97,11 @@ export class Commits {
);

// STEP 2
const chain = loadSummarizationChain(this.model, { type: 'map_reduce' });
const chain = loadSummarizationChain(this.model, {
questionPrompt: SUMMARY_PROMPT,
refinePrompt: SUMMARY_REFINE_PROMPT,
type: 'refine',
});
setLoadingInfo(
` [2/3] Split diff info to (${diffDocument.length} * ${this.config.diffChunkSize} chunk-size), generate summary...`,
);
Expand Down
26 changes: 25 additions & 1 deletion packages/lobe-commit/src/prompts/commits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatPromptTemplate } from 'langchain/prompts';
import { ChatPromptTemplate, PromptTemplate } from 'langchain/prompts';

import gitmojis from '@/constants/gitmojis';
import { selectors } from '@/store';
Expand Down Expand Up @@ -34,3 +34,27 @@ export const promptCommits = () => {
['human', 'Return only 1 type commit message describes the git diff summary: {summary}'],
]);
};

const sumaryTemplate = [
`You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain WHAT were the changes and WHY the changes were done.`,
`I'll enter a git diff summary, and your job is to convert it into a useful commit message.`,
`--------`,
`{text}`,
`--------`,
`Add a short description of the changes are done after the commit message. Don't start it with "This commit", just return only 1 type commit message describes the git diff summary.`,
]
.filter(Boolean)
.join('\n');

const summaryRefineTemplate = [
sumaryTemplate,
`## Rules`,
`- Choose only 1 type from the type-to-description below: <${TYPES_EXAMPLE}>`,
`- Commit message must be a maximum of ${MAX_LENGTH} characters.`,
LOCALE && `- Commit message language: ${LOCALE}`,
]
.filter(Boolean)
.join('\n');

export const SUMMARY_PROMPT = PromptTemplate.fromTemplate(sumaryTemplate);
export const SUMMARY_REFINE_PROMPT = PromptTemplate.fromTemplate(summaryRefineTemplate);
11 changes: 0 additions & 11 deletions packages/lobe-i18n/.i18nrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/lobe-label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Automatically copy issues labels from template repo
[![][github-issues-shield]][github-issues-link]
[![][github-license-shield]][github-license-link]

[Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-issues-link]
English ・ [简体中文](./README.zh-CN.md)[Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-issues-link]

![](https://gw.alipayobjects.com/zos/kitchen/qeTFEqgF8O/437shots_so.png)

Expand Down
167 changes: 167 additions & 0 deletions packages/lobe-label/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<div align="center"><a name="readme-top"></a>

<img height="120" src="https://gw.alipayobjects.com/zos/kitchen/T6E4BDoMNb/lobe-cli.webp">
<img height="120" src="https://gw.alipayobjects.com/zos/kitchen/qJ3l3EPsdW/split.svg">
<img height="120" src="https://registry.npmmirror.com/@lobehub/assets-emoji/1.3.0/files/assets/label.webp">

<h1>Lobe标签</h1>

自动从模板仓库复制 Issues 标签

[![][npm-release-shield]][npm-release-link]
[![][github-releasedate-shield]][github-releasedate-link]
[![][github-action-test-shield]][github-action-test-link]
[![][github-action-release-shield]][github-action-release-link]<br/>
[![][github-contributors-shield]][github-contributors-link]
[![][github-forks-shield]][github-forks-link]
[![][github-stars-shield]][github-stars-link]
[![][github-issues-shield]][github-issues-link]
[![][github-license-shield]][github-license-link]

[English](./README.md) ・ 简体中文 ・ [变更日志](./CHANGELOG.md) · [报告问题][github-issues-link] · [请求功能][github-issues-link]

![](https://gw.alipayobjects.com/zos/kitchen/qeTFEqgF8O/437shots_so.png)

</div>

## 📦 安装

要安装 Lobe 标签,请运行以下命令:

```bash
npm install -g @lobehub/label-cli
```

> \[!NOTE]\
> 确保您的 Node.js 版本 >= 18\*
<div align="right">

[![][back-to-top]](#readme-top)

</div>

## 🤯 使用

要初始化 Lobe i8n 配置,请运行以下命令:

```shell
$ lobe-label --config # 或使用短标志 -o
```

### 选项

Lobe 标签支持以下选项:

```shell
--target -t 目标仓库
--source -s 源仓库
```

> \[!NOTE]\
> 默认源仓库是[canisminor1990/canisminor-template](https://github.com/canisminor1990/canisminor-template)\*
### 复制问题标签

```shell
# 从canisminor1990/canisminor-template复制问题标签到lobehub/chat
$ lobe-label -t lobehub/chat

# 从lobehub/commit复制问题标签到lobehub/chat
$ lobe-label -t lobehub/chat -s lobehub/commit
```

<div align="right">

[![][back-to-top]](#readme-top)

</div>

## ⌨️ 本地开发

您可以使用 Github Codespaces 进行在线开发:

[![][github-codespace-shield]][github-codespace-link]

或者克隆它进行本地开发:

[![][bun-shield]][bun-link]

```bash
$ git clone https://github.com/lobehub/lobe-cli-toolbox.git
$ cd lobe-cli-toolbox
$ bun install
$ cd packages/lobe-label
$ bun dev
```

<div align="right">

[![][back-to-top]](#readme-top)

</div>

## 🤝 贡献

欢迎各种类型的贡献,如果您有兴趣贡献代码,请随时查看我们的 GitHub [问题][github-issues-link],展示您的才华。

[![][pr-welcome-shield]][pr-welcome-link]

[![][github-contrib-shield]][github-contrib-link]

<div align="right">

[![][back-to-top]](#readme-top)

</div>

## 🔗 链接

### 更多产品

- **[🤖 Lobe Chat][lobe-chat]** - 一个开源、可扩展(函数调用)、高性能的聊天机器人框架。支持一键免费部署您的私有 ChatGPT/LLM Web 应用程序。
- **[🤯 Lobe Theme][lobe-theme]** - 稳定扩散 WebUI 的现代主题,精美的界面设计,高度可定制的 UI 和提高效率的功能。

### 鸣谢

- **ink** - <https://github.com/vadimdemedes/ink>

---

#### 📝 License

Copyright © 2023 [LobeHub][profile-link]. <br />
This project is [MIT](./LICENSE) licensed.

<!-- LINK GROUP -->

[back-to-top]: https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square
[bun-link]: https://bun.sh
[bun-shield]: https://img.shields.io/badge/-speedup%20with%20bun-black?logo=bun&style=for-the-badge
[github-action-release-link]: https://github.com/lobehub/lobe-cli-toolbox/actions/workflows/release.yml
[github-action-release-shield]: https://img.shields.io/github/actions/workflow/status/lobehub/lobe-cli-toolbox/release.yml?label=release&labelColor=black&logo=githubactions&logoColor=white&style=flat-square
[github-action-test-link]: https://github.com/lobehub/lobe-cli-toolbox/actions/workflows/test.yml
[github-action-test-shield]: https://img.shields.io/github/actions/workflow/status/lobehub/lobe-cli-toolbox/test.yml?label=test&labelColor=black&logo=githubactions&logoColor=white&style=flat-square
[github-codespace-link]: https://codespaces.new/lobehub/lobe-cli-toolbox
[github-codespace-shield]: https://github.com/codespaces/badge.svg
[github-contrib-link]: https://github.com/lobehub/lobe-cli-toolbox/graphs/contributors
[github-contrib-shield]: https://contrib.rocks/image?repo=lobehub%2Flobe-cli-toolbox
[github-contributors-link]: https://github.com/lobehub/lobe-cli-toolbox/graphs/contributors
[github-contributors-shield]: https://img.shields.io/github/contributors/lobehub/lobe-cli-toolbox?color=c4f042&labelColor=black&style=flat-square
[github-forks-link]: https://github.com/lobehub/lobe-cli-toolbox/network/members
[github-forks-shield]: https://img.shields.io/github/forks/lobehub/lobe-cli-toolbox?color=8ae8ff&labelColor=black&style=flat-square
[github-issues-link]: https://github.com/lobehub/lobe-cli-toolbox/issues
[github-issues-shield]: https://img.shields.io/github/issues/lobehub/lobe-cli-toolbox?color=ff80eb&labelColor=black&style=flat-square
[github-license-link]: https://github.com/lobehub/lobe-cli-toolbox/blob/master/LICENSE
[github-license-shield]: https://img.shields.io/github/license/lobehub/lobe-cli-toolbox?color=white&labelColor=black&style=flat-square
[github-releasedate-link]: https://github.com/lobehub/lobe-cli-toolbox/releases
[github-releasedate-shield]: https://img.shields.io/github/release-date/lobehub/lobe-cli-toolbox?labelColor=black&style=flat-square
[github-stars-link]: https://github.com/lobehub/lobe-cli-toolbox/network/stargazers
[github-stars-shield]: https://img.shields.io/github/stars/lobehub/lobe-cli-toolbox?color=ffcb47&labelColor=black&style=flat-square
[lobe-chat]: https://github.com/lobehub/lobe-chat
[lobe-theme]: https://github.com/lobehub/sd-webui-lobe-theme
[npm-release-link]: https://www.npmjs.com/package/@lobehub/label-cli
[npm-release-shield]: https://img.shields.io/npm/v/@lobehub/label-cli?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[pr-welcome-link]: https://github.com/lobehub/lobe-cli-toolbox/pulls
[pr-welcome-shield]: https://img.shields.io/badge/%F0%9F%A4%AF%20PR%20WELCOME-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge
[profile-link]: https://github.com/lobehub

0 comments on commit b01df9c

Please sign in to comment.