-
-
Save todays-mitsui/b9bd574f6267f82f64aa51f6b20b48ab to your computer and use it in GitHub Desktop.
ココピーからChatGPTを呼んで文章生成させる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ({ title, url, content }) => { | |
| const parser = new DOMParser().parseFromString(content, 'text/html'); | |
| const paragraphs = parser.querySelectorAll('body p'); | |
| const article = Array.from(paragraphs) | |
| .map(p => p.textContent.trim().replace(/\s+/g, ' ')) | |
| .filter(text => text.length > 0) | |
| .join("\n").slice(0, 10000); | |
| const endpoint = 'https://api.openai.com/v1/chat/completions'; | |
| const apiKey = '{YOUR_OPENAI_API_KEY}'; // Replace with your OpenAI API key | |
| const payload = { | |
| model: 'gpt-4o', | |
| messages: [ | |
| { | |
| role: 'system', | |
| content: 'ユーザーがWebページのコンテンツを提示するので、今北産業(3行まとめ)を生成してください。行頭には`・`を置いてください。1行は24文字程度で、ラフに言い切りの口調にしてください。行末に句読点をつけないでください。', | |
| }, | |
| { | |
| role: 'user', | |
| content: article, | |
| }, | |
| ], | |
| }; | |
| return fetch(endpoint, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${apiKey}` | |
| }, | |
| body: JSON.stringify(payload) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => `${title} | |
| ${url} | |
| 【3行まとめ】 | |
| ${data.choices[0].message.content} | |
| `); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ({ content }) => { | |
| const parser = new DOMParser().parseFromString(content, 'text/html'); | |
| const paragraphs = parser.querySelectorAll('body p'); | |
| const article = Array.from(paragraphs) | |
| .map(p => p.textContent.trim().replace(/\s+/g, ' ')) | |
| .filter(text => text.length > 0) | |
| .join("\n").slice(0, 10000); | |
| const endpoint = 'https://api.openai.com/v1/chat/completions'; | |
| const apiKey = '{YOUR_OPENAI_API_KEY}'; // Replace with your OpenAI API key | |
| const payload = { | |
| model: 'gpt-4o', | |
| messages: [ | |
| { | |
| role: 'system', | |
| content: 'ユーザーがWebページのコンテンツを提示するので、それをもとにはてなブックマークのタグとコメントを生成してください。タグは "[プログラミング][Python][Web]" のようにブラケットで囲んで最大で5つ返してください。ただし5つよりも少なくて十分だと思われるときには少ない個数のタグを返しても構いません。コメントはWebページを読んだユーザーの気持ちになって感想を生成してください。コメントはタグの後ろに続けます。タグとコメントで100文字に収まるようにしてください。', | |
| }, | |
| { | |
| role: 'user', | |
| content: article, | |
| }, | |
| ], | |
| }; | |
| return fetch(endpoint, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${apiKey}` | |
| }, | |
| body: JSON.stringify(payload) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => data.choices[0].message.content); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ({ content }) => { | |
| const parser = new DOMParser().parseFromString(content, 'text/html'); | |
| const paragraphs = parser.querySelectorAll('body p'); | |
| const article = Array.from(paragraphs) | |
| .map(p => p.textContent.trim().replace(/\s+/g, ' ')) | |
| .filter(text => text.length > 0) | |
| .join("\n").slice(0, 10000); | |
| const endpoint = 'https://api.openai.com/v1/chat/completions'; | |
| const apiKey = '{YOUR_OPENAI_API_KEY}'; // Replace with your OpenAI API key | |
| const payload = { | |
| model: 'gpt-4o', | |
| messages: [ | |
| { | |
| role: 'system', | |
| content: 'ユーザーがWebページのコンテンツを提示するので、ページの内容を要約して5・7・5形式で俳句を詠んでください。区切り文字は全角スペースで、1行で生成してください。', | |
| }, | |
| { | |
| role: 'user', | |
| content: article, | |
| }, | |
| ], | |
| }; | |
| return fetch(endpoint, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${apiKey}` | |
| }, | |
| body: JSON.stringify(payload) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => data.choices[0].message.content); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment