Jiangweixian, a front-end engineer
jiangweixian / actions-article-helper Goto Github PK
View Code? Open in Web Editor NEWCheck issue article grammar with ChatGPT
License: MIT License
Check issue article grammar with ChatGPT
License: MIT License
Jiangweixian, a front-end engineer
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.
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:
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 basicopen-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.
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
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.