GithubHelp home page GithubHelp logo

jiangweixian / actions-article-helper Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 14.69 MB

Check issue article grammar with ChatGPT

License: MIT License

Shell 5.76% TypeScript 94.24%
actions blog chatgpt workflow

actions-article-helper's Introduction

actions-article-helper's People

Contributors

jiangweixian avatar

Watchers

 avatar  avatar

actions-article-helper's Issues

test

My blog site is built on top of GitHub issues. When I create or edit my issue on GitHub, next.js ISR will recreate my blog site in the background. Additionally, ChatGPT is an excellent AI assistant tool that can be used for many purposes, such as a search engine and language translator. As a non-native English speaker, I plan to add ChatGPT to my article writing workflow this weekend to check my articles' grammar like a native English speaker.

TL;DR

If you write articles on GitHub issues like me, you can use the https://github.com/JiangWeixian/actions-article-helper action in your blog repository.

name: "article helper"
on:
  issues:
    types:
      - "opened"
      - "edited"

jobs:
  debug:
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v2
    - name: setup node.js
      uses: actions/setup-node@v2
      with:
        node-version: 16
    - name: article helper
      uses: jiangweixian/actions-article-helper@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

DEMO:

image

ChatGPT Open API

Lucky, ChatGPT provide open-api. First you should create API_KEY on OpenAI platform https://platform.openai.com/account/api-keys.

import { ChatGPTAPI } from 'chatgpt'

export const createChatGPTAPI = (apiKey: string) => {
  return new ChatGPTAPI({
    apiKey, // add you open-ai API_KEY here
  })
}

package chatgpt is a request client wrapper the basic open-ai endpoint.

Now, you can send you article content(from issue body) to ChatGPT, let ChatGPT to check grammar and rewrite it.

const client = createChatGPTAPI(apiKey)
client.sendMessage(content)

By default, you can't send article content like Hey, chatgpt help me check {{ content }} grammar. Maybe it will not work as you expect.

To make ChatGPT act as native English speaker, you need prompts. prompts like language(like JavaScript or Rust) that ChatGPT will understand better.

Theres are lots of prompts you can play with from https://github.com/f/awesome-chatgpt-prompts.

In order to make ChatGPT work as English native. Article content will send with the follow prompts, just replace "istanbulu cok seviyom burada olmak cok guzel" with real article content.

I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My markdown format article is "istanbulu cok seviyom burada olmak cok guzel"

const client = createChatGPTAPI(apiKey)
const result = await chatgptApi.sendMessage(article, {
  stream: true,
  // response original markdown format
  promptPrefix: 'Respond markdown format.<|im_end|>\n',
})

The main(hardest) part is complete, now we go futurter, and make it interaction with github actions.

Github Actions

First, get issue content

const issue = await octokit.rest.issues.get(params)

Then create comment under issue

await octokit.rest.issues.createComment({
  ...,
  body: result.text, // result is ChatGPT respsonse result.
})

That works great, but not perfect. Before issue publish, issue body will edit mutiple times. I don't wan't create too much comments, I need to find previous comment, and update it.

const comments = await octokit.rest.issues.listComments(params)
// find comments by bot<github_actioins> start with `<!--article-helper-->`
const comment = findComment(comments.data)
debug('find comment %o', comment)
if (comment) {
  await octokit.rest.issues.updateComment({
    owner,
    repo,
    comment_id: comment?.id,
    body: withLeadPrefix(`${result.text} ${Date.now()}`),
  })
} else {
  // create comment
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.