Skip to content

Commit

Permalink
Dev (#87)
Browse files Browse the repository at this point in the history
* Feat:"favicon ์ถ”๊ฐ€"

* Feat: "ํ™ˆํŽ˜์ด์ง€ ๋ ˆ์ด์•„์›ƒ ๋ฐ UI ์ˆ˜์ •"

* feat: reset ๊ธฐ๋Šฅ ์ถ”๊ฐ€

* Feature ai (#86)

* props ์ถ”๊ฐ€

* Fix: conflict ํ•ด๊ฒฐ

* Fix: conflict ํ•ด๊ฒฐ

---------

Co-authored-by: lee-ji-hong <[email protected]>
Co-authored-by: ์ด์žฌํ˜‘ <[email protected]>
  • Loading branch information
3 people authored May 9, 2024
1 parent e326861 commit 8844804
Show file tree
Hide file tree
Showing 15 changed files with 2,644 additions and 2,394 deletions.
4,472 changes: 2,236 additions & 2,236 deletions .pnp.cjs

Large diffs are not rendered by default.

31 changes: 4 additions & 27 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="apple-touch-icon" href="%PUBLIC_URL%/images/rm-logo.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Readme monster</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<noscript>Readme ์ž‘์„ฑ์„ ๋” ์‰ฝ๊ณ  ํŽธ๋ฆฌํ•˜๊ฒŒ</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added public/logo.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"src": "logo.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
Expand Down
184 changes: 139 additions & 45 deletions src/components/Editor/Components/AiGenerator.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck

import React, { useEffect } from "react";
import React, { useEffect, useRef } from "react";
import axios from "axios";
import { useState } from "react";
import OpenAI from "openai";

const AiGenerator = () => {
const githubToken = process.env.REACT_APP_GITHUB_API_KEY;
const AiGenerator = ({ githubAddress, openAiKey, formList }: GenerateKeyType) => {
console.log("githubAddress", githubAddress);
console.log("openAiKey", openAiKey);
const githubApiToken = process.env.REACT_APP_GITHUB_API_KEY;
const [repos, setRepos] = useState({});
const [response, setResponse] = useState("");
// const [response, setResponse] = useState("");
const [githubRepo, setGithubRepo] = useState([]);
const [openAiToken, setOpenAiToken] = useState("");
const [aboutRepo, setAboutRepo] = useState([]);

const [isLoading, setIsLoading] = useState(false); // ๋กœ๋”ฉ ์ƒํƒœ ๊ด€๋ฆฌ
const [responseData, setResponseData] = useState(null); // API ์‘๋‹ต ๋ฐ์ดํ„ฐ ์ €์žฅ
const prevResponseData = useRef();

useEffect(() => {
if (githubAddress) {
setGithubRepo(githubAddress.split("/"));
}
}, [githubAddress]);

useEffect(() => {
if (openAiKey) {
setOpenAiToken(openAiKey);
}
}, [openAiKey]);

useEffect(() => {
if (formList) {
setAboutRepo(formList);
}
}, [formList]);

useEffect(() => {
if (prevResponseData.current !== responseData && responseData) {
const storedEditSections = localStorage.getItem("edit-sections-list");
const editSectionsList = storedEditSections ? JSON.parse(storedEditSections) : [];

// editSectionsList๊ฐ€ ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์ƒˆ๋กœ์šด ์„น์…˜์„ ์ถ”๊ฐ€
if (editSectionsList.length === 0) {
const newSection = { id: 8, title: "์ž๋™์ƒ์„ฑRM", markdown: responseData };
localStorage.setItem("edit-sections-list", JSON.stringify([newSection]));
localStorage.setItem("builder-sections-list", JSON.stringify([newSection]));
}

// ์ด์ „ responseData ์—…๋ฐ์ดํŠธ
prevResponseData.current = responseData;
}
}, [responseData]);

// openAiKey={openAiKey} githubAddress={githubAddress}
const getRepos = async (username: string, token: string) => {
if (!githubRepo.length || !openAiToken) {
if (!githubRepo.length) {
console.log("githubRepo", githubRepo);
return alert("GitHub repository ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”");
} else if (!openAiToken) {
console.log("openAiToken", openAiToken);
return alert("OpenAi key๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”");
}
}
try {
const response = await axios.get("https://api.github.com/repos/Readme-Monster/readme-monster", {
headers: { Authorization: `token ${githubToken}` },
const response = await axios.get(`https://api.github.com/repos/${githubRepo.slice(-2).join("/")}`, {
headers: { Authorization: `token ${githubApiToken}` },
});
console.log("responseresponse", response.data);
setRepos(response.data);
if (response) {
console.log(Object.keys(response.data).length);
if (Object.keys(response.data).length) {
console.log("์—ฌ๊ธฐ์—ฌ๊ธฐ");
console.log("์—ฌ๊ธฐ์—ฌ๊ธฐ", response.data);
const aiResponse = await createReadme(response.data);
console.log("aiResponse", aiResponse);
setResponse(aiResponse.choices[0].text.trim());
setResponseData(aiResponse.choices[0].text.trim());
// return response.data;
}
}
Expand All @@ -34,69 +88,109 @@ const AiGenerator = () => {
}
};

async function createReadme({ name, description, language, contributors, html_url }): Promise<string> {
async function createReadme({
name,
description,
language,
stargazers_count,
watchers_count,
forks_count,
open_issues_count,
contributors,
html_url,
has_wiki,
created_at,
updated_at,
}): Promise<string> {
const openai = new OpenAI({
apiKey: process.env.REACT_APP_OPENAI_API_KEY,
// apiKey: process.env.REACT_APP_OPENAI_API_KEY,
apiKey: openAiToken,
dangerouslyAllowBrowser: true,
});

console.log(name, description, language, contributors, html_url);

// prompt ๊ด€๋ จ ๋‚ด์šฉ
const prompt = `${html_url}
์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์„ค๋ช…ํ•˜๋Š” ๋ฆฌ๋“œ๋ฏธ๋ฅผ ์ž‘์„ฑํ• ๊ฑฐ์•ผ. ์ง€๊ธˆ๋ถ€ํ„ฐ ์„ค๋ช…ํ•˜๋Š” ๋‚ด์šฉ์„ ๋งˆํฌ๋‹ค์šด ๋ฌธ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•ด์ค˜.
ํ”„๋กœ์ ํŠธ ์ œ๋ชฉ์ธ ${name}๋Š” ๊ฐ€์žฅ ํฐ h1์œผ๋กœ ๋งจ ์œ„์— ์จ์ค˜.
์ œ๋ชฉ์— ์–ด์šธ๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™์€ ์ด๋ชจ์ง€๋„ ํ•˜๋‚˜ ์ถ”์ฒœํ•ด์„œ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ฃผ๋ฉด ์ข‹๊ฒ ์–ด.
๊ทธ ๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "ํ”„๋กœ์ ํŠธ ๊ฐœ์š”"๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.
๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ์— ์˜ค๋Š” ํ…์ŠคํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ๋„ฃ์–ด์ค˜. unordered list๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋„ฃ์œผ๋ฉด ๋ผ.
${description}
๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "๊ธฐ์ˆ  ์Šคํƒ"์ด๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.
${language}๋ฅผ ๊ฐ๊ฐ https://simpleicons.org/ ์‚ฌ์ดํŠธ์—์„œ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ฑ„์›Œ์„œ ์ด์–ด ์จ์ฃผ๋ฉด ๋ผ. ์ค„๋ฐ”๊ฟˆ ์—†์ด ๋ถ™์—ฌ์„œ ์จ์ค˜์•ผํ•ด.
![Badge](https://img.shields.io/badge/๋กœ๊ณ ์ด๋ฆ„-์ƒ‰์ƒ์ฝ”๋“œ?style=flat&logo=๋กœ๊ณ ์ด๋ฆ„&logoColor=white)
๋กœ๊ณ  ์ด๋ฆ„์—๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์—์„œ ๊ฐ€์žฅ ์ฒซ๋ฒˆ์งธ๋กœ ์ฐพ์€ ํ…์ŠคํŠธ๋ฅผ, ์ƒ‰์ƒ ์ฝ”๋“œ์—์„œ๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์— ๋‚˜์˜จ #๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ปฌ๋Ÿฌ ํ—ฅ์‚ฌ์ฝ”๋“œ 6์ž๋ฆฌ๋ฅผ #์„ ์ œ์™ธํ•˜๊ณ  ๋„ฃ์–ด์ค˜.
๊ทธ ๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "์ฐธ์—ฌ ํŒ€์›"์ด๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.
๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ์˜ค๋Š” ๋‚ด์šฉ์„ ํ‘œ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ์ข‹๊ฒ ์–ด.
1๋ฒˆ์งธ ํ–‰์— ๊ฐ๊ฐ์˜ ํŒ€์› ์ด๋ฆ„์„ ๋„ฃ์–ด์ค˜.
2๋ฒˆ์งธ ํ–‰์—๋Š” ๊ฐ ํŒ€์›์ด ๋งก์€ ๊ธฐ๋Šฅ์„ ์“ธ๊ฑฐ์•ผ.
ํŒ€์› ์ด๋ฆ„๊ณผ ๊ฐ ํŒ€์›์ด ๋งก์€ ๊ธฐ๋Šฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•„.
${contributors}`;
const prompt = `GitHub ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•œ README ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜์„ธ์š”. ๋‹ค์Œ์€ ํ”„๋กœ์ ํŠธ ์ƒ์„ธ ์ •๋ณด์ž…๋‹ˆ๋‹ค:
ํ”„๋กœ์ ํŠธ ์ด๋ฆ„: ${name}
์„ค๋ช…: ${description}
์ฃผ์š” ์‚ฌ์šฉ ์–ธ์–ด: ${language}
๋ณ„ํ‘œ ์ˆ˜: ${stargazers_count}
๊ฐ์‹œ์ž ์ˆ˜: ${watchers_count}
ํฌํฌ ์ˆ˜: ${forks_count}
์—ด๋ฆฐ ์ด์Šˆ ์ˆ˜: ${open_issues_count}
ํ”„๋กœ์ ํŠธ URL: ${html_url}
์ฃผ์š” ๊ธฐ๋Šฅ: ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ถ„์„ํ•ด์„œ ์ฃผ์š” ๊ธฐ๋Šฅ์„ ์š”์•ฝํ•ด ์ฃผ์„ธ์š”.
์œ„ํ‚ค: ${has_wiki}
๋ผ์ด์„ ์Šค: ['์ง€์ •๋˜์ง€ ์•Š์Œ']
์ƒ์„ฑ์ผ: ${created_at}
์ตœ๊ทผ ์—…๋ฐ์ดํŠธ: ${updated_at}
${aboutRepo.map(item => `${item.title}: ${item.value}`).join("\n")}
์ด ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋‹ค์Œ์„ ํฌํ•จํ•˜๋Š” ๊ฐ„๊ฒฐํ•˜๋ฉด์„œ๋„ ํฌ๊ด„์ ์ธ README๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”:
- ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ
- ํ”„๋กœ์ ํŠธ ์‚ฌ์šฉ ์‹œ ์ฃผ์š” ๊ธฐ๋Šฅ ๋ฐ ์ด์ 
- ํ”„๋กœ์ ํŠธ ์„ค์น˜ ๋ฐ ์‹œ์ž‘ ๋ฐฉ๋ฒ•
- ํ”„๋กœ์ ํŠธ ๊ธฐ์—ฌ ๋ฐฉ๋ฒ•
- '๋ผ์ด์„ ์Šค', '๊ธฐ์—ฌ์ž', '๊ฐ์‚ฌ์˜ ๋ง' ๋“ฑ ๊ด€๋ จ ์žˆ๋Š” ์ถ”๊ฐ€ ์„น์…˜ ์ •๋ณด`;

// `${html_url}

// ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์„ค๋ช…ํ•˜๋Š” ๋ฆฌ๋“œ๋ฏธ๋ฅผ ์ž‘์„ฑํ• ๊ฑฐ์•ผ. ์ง€๊ธˆ๋ถ€ํ„ฐ ์„ค๋ช…ํ•˜๋Š” ๋‚ด์šฉ์„ ๋งˆํฌ๋‹ค์šด ๋ฌธ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•ด์ค˜.

// ํ”„๋กœ์ ํŠธ ์ œ๋ชฉ์ธ ${name}๋Š” ๊ฐ€์žฅ ํฐ h1์œผ๋กœ ๋งจ ์œ„์— ์จ์ค˜.
// ์ œ๋ชฉ์— ์–ด์šธ๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™์€ ์ด๋ชจ์ง€๋„ ํ•˜๋‚˜ ์ถ”์ฒœํ•ด์„œ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ฃผ๋ฉด ์ข‹๊ฒ ์–ด.

// ๊ทธ ๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "ํ”„๋กœ์ ํŠธ ๊ฐœ์š”"๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.
// ๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ์— ์˜ค๋Š” ํ…์ŠคํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ๋„ฃ์–ด์ค˜. unordered list๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋„ฃ์œผ๋ฉด ๋ผ.
// ${description}

// ๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "๊ธฐ์ˆ  ์Šคํƒ"์ด๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.

// ${language}๋ฅผ ๊ฐ๊ฐ https://simpleicons.org/ ์‚ฌ์ดํŠธ์—์„œ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ฑ„์›Œ์„œ ์ด์–ด ์จ์ฃผ๋ฉด ๋ผ. ์ค„๋ฐ”๊ฟˆ ์—†์ด ๋ถ™์—ฌ์„œ ์จ์ค˜์•ผํ•ด.

// ![Badge](https://img.shields.io/badge/๋กœ๊ณ ์ด๋ฆ„-์ƒ‰์ƒ์ฝ”๋“œ?style=flat&logo=๋กœ๊ณ ์ด๋ฆ„&logoColor=white)
// ๋กœ๊ณ  ์ด๋ฆ„์—๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์—์„œ ๊ฐ€์žฅ ์ฒซ๋ฒˆ์งธ๋กœ ์ฐพ์€ ํ…์ŠคํŠธ๋ฅผ, ์ƒ‰์ƒ ์ฝ”๋“œ์—์„œ๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์— ๋‚˜์˜จ #๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ปฌ๋Ÿฌ ํ—ฅ์‚ฌ์ฝ”๋“œ 6์ž๋ฆฌ๋ฅผ #์„ ์ œ์™ธํ•˜๊ณ  ๋„ฃ์–ด์ค˜.

// ๊ทธ ๋‹ค์Œ์œผ๋กœ๋Š” h3(###)๋กœ "์ฐธ์—ฌ ํŒ€์›"์ด๋ผ๊ณ  ์“ด ๋‹ค์Œ, ์–ด์šธ๋ฆฌ๋Š” ์ด๋ชจ์ง€๋ฅผ ํ•˜๋‚˜ ์ œ๋ชฉ ์™ผ์ชฝ์— ๋„ฃ์–ด์ค˜.
// ๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ์˜ค๋Š” ๋‚ด์šฉ์„ ํ‘œ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ์ข‹๊ฒ ์–ด.
// 1๋ฒˆ์งธ ํ–‰์— ๊ฐ๊ฐ์˜ ํŒ€์› ์ด๋ฆ„์„ ๋„ฃ์–ด์ค˜.
// 2๋ฒˆ์งธ ํ–‰์—๋Š” ๊ฐ ํŒ€์›์ด ๋งก์€ ๊ธฐ๋Šฅ์„ ์“ธ๊ฑฐ์•ผ.

// ํŒ€์› ์ด๋ฆ„๊ณผ ๊ฐ ํŒ€์›์ด ๋งก์€ ๊ธฐ๋Šฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•„.
// ${contributors}`;

// `
// Please create the README for GitHub in Korean.. This repository named ${name} and description is ${description}. The main language used is ${language}. The Contributors are ${contributors}. For the rest of the information, refer to the repo link ${html_url}, summarize it, and add it yourself to the readme file.`;

console.log("openai", openai);
console.log("prompt", prompt);
setIsLoading(true); // ๋กœ๋”ฉ ์‹œ์ž‘
try {
const response = await openai.completions.create({
// messages: [{ role: "user", content: `${prompt}` }],
model: "gpt-3.5-turbo-instruct",
prompt: prompt,
max_tokens: 150,
max_tokens: 100,
});
console.log(response);
// setResponseData(response); // ์‘๋‹ต ๋ฐ์ดํ„ฐ ์ €์žฅ
// setResponseData(response.choices[0].text.trim()); // ์‹ค์ œ ์‚ฌ์šฉ ์‹œ ๊ตฌ์ฒด์  ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ
return response;

// return response.data.choices[0].text.trim();
} catch (error) {
console.log("Error generating README:", error);
throw new Error("Failed to generate README");
} finally {
setIsLoading(false); // ๋กœ๋”ฉ ์ข…๋ฃŒ
}
}

console.log("open api ์—์„œ ๋„˜๊ฒจ์ฃผ๋Š” ์‘๋‹ต", response);
console.log("open api ์—์„œ ๋„˜๊ฒจ์ฃผ๋Š” ์‘๋‹ต", responseData);
console.log("repos", repos);
console.log("aboutRepo", aboutRepo);
return (
<div className="border-3">
<button onClick={getRepos}>readme์ƒ์„ฑ</button>
</div>
<button onClick={getRepos} className="w-1/2 rounded-[8px] bg-textBlue text-white hover:bg-[#6E9EFF]">
Create
</button>
);
};

Expand Down
Loading

0 comments on commit 8844804

Please sign in to comment.