wkgcass / demo-of-chat-in-issue

A demo repo of chat-in-issue github action: github.com/wkgcass/chat-in-issue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chat-in-issue的README翻译

wkgcass opened this issue · comments

/chat:请将如下中文markdown格式的文件翻译为英文,并保留markdown格式

chat-in-issue

通过Github Actions,在issue中使用OpenAI ChatGPT。

如何使用

快速启动!

如果只是想使用ChatGPT而不关心与已有仓库的集成,可以直接fork demo仓库
然后按照那个仓库README中记录的步骤进行配置即可。

在已有仓库中使用Action

在仓库中创建文件:/.github/workflows/chat-in-issue.yaml

name: chat-in-issue
run-name: '[chat-in-issue][${{ github.workflow }}] - ${{ github.event.issue.title }}'
on:
  issues:
    types: ['opened']
  issue_comment:
    types: ['created']
jobs:
  chat-in-issue:
    if: ${{ !github.event.issue.pull_request }}
    runs-on: ubuntu-latest
    steps:
      - uses: wkgcass/chat-in-issue@v1
        with:
          openai-key: ${{ secrets.OPENAI_KEY }}
          user-whitelist: ${{ vars.CHAT_IN_ISSUE_USER_WHITELIST }}

该配置将读取Secrets中的OPENAI_KEY配置,以及Variables中的CHAT_IN_ISSUE_USER_WHITELIST配置。
如果你的仓库是public仓库,那么则建议配置user-whitelist,否则该配置可以视情况省略。

配置项

支持如下配置项:

token

Github token。默认使用${{ github.token }},需要配置读写权限(默认的workflow token权限为只读)。

具体会调用的API如下:

  • 读取issue
  • 读取和写入issue comment
  • 读取issue comment列表

openai-key

必填项

调用Openai API所使用的密钥,一般以"sk-"开头。

推荐将该key配置在"Secrets"中。

issue-number

触发事件的issue。默认使用${{ github.event.issue.number }}

一般省略不写即可。

comment-id

触发事件的comment。默认使用${{ github.event.comment.id }},可能为空。

一般省略不写即可。

prefix

Issue或评论的内容应当以这里配置的"$prefix"为开头,具体格式为"/$prefix:"。
比方说,如果前缀配置为"chat",那么只有以"/chat:"开头的issue或评论才会触发prompt。
多个前缀可以用逗号分隔。
请注意,有一些不应使用的前缀:

  • /ai-says: 响应信息,在prompt中会被作为role=assistant消息
  • /err: 错误信息,以该字符串开头的issue或评论不会作为prompt的一部分
  • /system: 不会触发prompt,但是会被作为role=system消息

如果消息包含的字符串恰好为"submit",则该消息本身将不会用作prompt的一部分。

prefix的默认值为chat

user-whitelist

用户白名单。仅白名单上的用户可以触发prompt。白名单的每一行是一个正则表达式,任何一行的正则检查通过则算作通过。
如果不写,则使用默认值.*(全部允许)。

建议将白名单配置在Variables中。

prompt-limit

该配置可与prompt-from-beginning-max配合使用。

Prompt最大字符数限制。

如果整个聊天上下文的总字数不超过该值,则所有内容都将作为prompt消息。
否则将从最前面开始,取不超过$prompt-from-beginning-max指定的数量的字符;然后再从最后面开始,取总量不超过本配置的字符。

如果某条消息被截断,则该消息整体都会被丢弃。

默认值为3000

prompt-from-beginning-max

该配置可与prompt-limit配合使用。

从聊天上下文的最前面开始计算的最大字符数。

默认值为500

/ai-says: # chat-in-issue

Use OpenAI ChatGPT in Github issues with Github Actions.

How to Use

Quick Start!

If you just want to use ChatGPT and don't care about integrating it with an existing repository, you can simply fork the demo repository.
Then follow the steps described in that repository's README to configure it.

Use with an Existing Repository and GitHub Actions

Create the /github/workflows/chat-in-issue.yaml file in your repository with the following contents:

name: chat-in-issue
run-name: '[chat-in-issue][${{ github.workflow }}] - ${{ github.event.issue.title }}'
on:
  issues:
    types: ['opened']
  issue_comment:
    types: ['created']
jobs:
  chat-in-issue:
    if: ${{ !github.event.issue.pull_request }}
    runs-on: ubuntu-latest
    steps:
      - uses: wkgcass/chat-in-issue@v1
        with:
          openai-key: ${{ secrets.OPENAI_KEY }}
          user-whitelist: ${{ vars.CHAT_IN_ISSUE_USER_WHITELIST }}

This configuration reads the OPENAI_KEY configuration from your repository's Secrets and the CHAT_IN_ISSUE_USER_WHITELIST from your repository's Variables.
If your repository is a public repository, it is recommended to configure user-whitelist. Otherwise, this configuration can be omitted depending on the situation.

Configuration

The following configurations are available:

token

The Github token. By default, ${{ github.token }} is used and requires read and write permissions (the default workflow token permission is read-only).

The following APIs will be called:

  • Read issue
  • Read and write issue comments
  • Read issue comment list

openai-key

Required

The key used to call the OpenAI API, generally prefixed with "sk-".

It is recommended to configure this key in "Secrets".

issue-number

The issue which triggered the event. By default, ${{ github.event.issue.number }} is used.

Generally, it can be omitted.

comment-id

The comment which triggered the event. By default, ${{ github.event.comment.id }} is used and may be empty.

Generally, it can be omitted.

prefix

The content of the Issue or comment should start with "$prefix" configured here, in the format of "/$prefix:".
For example, if the prefix configuration is "chat", only issues or comments starting with "/chat:" will trigger the prompt.
Multiple prefixes can be separated by commas.
Please note that there are some prefixes that should not be used:

  • /ai-says: Response information, in the prompt will be treated as role=assistant message
  • /err: Error information, issues or comments starting with this string will not be part of the prompt
  • /system: Will not trigger the prompt, but will be treated as role=system message

If the message contains the string "submit", the message itself will not be used as part of the prompt.

The default value of prefix is chat.

user-whitelist

User whitelist. Only users on the whitelist can trigger the prompt. Each line of the whitelist is a regular expression, and if any line's regular check passes, it counts as passed.
If not written, the default value .* (allow everything) will be used.

It is recommended to configure the whitelist in Variables.

prompt-limit

This configuration can be used in conjunction with prompt-from-beginning-max.

The maximum number of characters allowed in a Prompt.

If the total number of characters in the entire chat context does not exceed this value, all content will be used as prompt messages.
Otherwise, the prompt will be taken from the start, with a maximum of $prompt-from-beginning-max characters; then, starting from the end, a maximum of the number of characters specified in this configuration will be taken.

If a message is truncated, the entire message will be discarded.

The default value is 3000.

prompt-from-beginning-max

This configuration can be used in conjunction with prompt-limit.

The maximum number of characters calculated from the beginning of the chat context.

The default value is 500.

/err: 这翻译真的很省力很省事,消耗也不多。这次的token消耗如下:

{ prompt_tokens: 1079, completion_tokens: 900, total_tokens: 1979 }

/chat: 将如下markdown文件翻译为英文并保留markdown格式:

model

使用的AI模型名。默认为gpt-3.5-turbo

/ai-says: #### Model

The name of the AI model being used. Default is gpt-3.5-turbo.