diff --git a/.gitignore b/.gitignore index f1cf600..7ab4727 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist dist.zip +web-ext-artifacts diff --git a/package.json b/package.json index 5a2441c..0c538c1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "nodemon", "prebuild": "rimraf dist", - "build-prod": "cross-env NODE_ENV=production webpack --config webpack.config.production.js", + "build-prod": "cross-env NODE_ENV=production webpack --config webpack.config.production.js && web-ext build -s dist/", "build": "cross-env NODE_ENV=development webpack --config webpack.config.js" }, "dependencies": { diff --git a/public/manifest.json b/public/manifest.json index e41ec0b..d747fe6 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,8 +1,8 @@ { "manifest_version": 2, - "name": "Test extension", + "name": "GPT Web", "version": "1.0", - "description": "React chrome extension", + "description": "Use GPT on your current webpage content", "permissions": ["activeTab", "tabs", "storage", "*://*/*"], "browser_action": { "default_popup": "index.html" diff --git a/src/components/hooks/useSummary.js b/src/components/hooks/useSummary.js index 7bf89bd..7dc0d14 100644 --- a/src/components/hooks/useSummary.js +++ b/src/components/hooks/useSummary.js @@ -9,81 +9,56 @@ Always respond in the initial webpage language. For example, if the webpage is i ` const PREPROMPT_SUMMARY_SUDOLANG = ` -# InternetBrowsingAssistant - -You are an internet browsing assistant. You are an expert in summarizing webpages. +You are an internet browsing assistant and an expert at summarizing webpages. Your job is to write bullets points to summarize webpage text content. -function list():format=numbered markdown +Constraints { + - Use bullet points preceded by a dash (-). + - Always respond in the initial webpage language. For example, if the webpage is in french, respond in french. + - Focus on the main content of the webpage. Ignore the rest. Filter out useless information. + - Use concise sentences. +} +` +const PREPROMPT_SUMMARY_SUDOLANG_SHORT = ` +# Short Summary -InternetBrowsingAssistant { - State { - Information { - BulletPoint - } - } - Constraints { - Use bullet points. - Always write in bullet points preceded by a dash (-). - Always respond in the initial webpage language. For example, if the webpage is in french, respond in french. - - Instruct the AI: - - Focus on the main content of the webpage. Ignore the rest. - - Filter out useless information. - - Use concise sentences. - } - /list - List current property settings +You are an internet browsing assistant. You are an expert at summarizing webpages in 5 bullet points. + +Constraints { + - Always use the initial webpage language. Eg: if the webpage is in french, respond in french. + - Focus on the main content of the webpage. Ignore the rest. Filter out useless information. + - Use concise sentences. + - Use 5 bullet points preceded by a dash (-). } ` +const PREPROMPT_SUMMARY = PREPROMPT_SUMMARY_SUDOLANG_SHORT const PREPROMPT_ASK_SUDOLANG = ` -# InternetBrowsingAssistant +# Internet Browsing Assistant You are an internet browsing assistant. You an expert in answering user questions about webpages. Your job is to answer user questions about the webpage text content. -The question is always the last line of the input. - -function list():format=numbered markdown - -InternetBrowsingAssistant { - State { - Information { - Description - } - } - Constraints { - Use bullet points. - Use concise sentences. - - Instruct the AI: - - Always respond in the initial webpage language. For example, if the webpage is in french, respond in french. - - Just answer the question. Do not add any additional information. - - If the question is not clear, ask for clarification. - } - /list - List current property settings +The question is always the last line of the prompt. + +Constraints { + - Use bullet points. + - Use concise sentences. + - Always respond in the question language. For example, if the question is in french, respond in french. + - Focus on answering the question. Do not add any additional information. + - If the question is unclear, ask for clarification. } ` -const PREPROMPT_SUMMARY = PREPROMPT_SUMMARY_SUDOLANG +export const MAX_MESSAGE_LENGTH = 12000 -let appendToSummary = () => { - console.log("appendToSummary not initialized") +let setSummaryGlobal = () => { + console.log("setSummary not initialized") } -export const MAX_MESSAGE_LENGTH = 12000 - export const useSummary = () => { const [summary, setSummary] = useState("") - // useEffect(() => { - // sendRequest(prompt) - // }, [prompt]) - - useEffect(() => { - appendToSummary = (toAppend) => { - setSummary(summary + toAppend) - } - }, [summary]) + setSummaryGlobal = setSummary return [summary, setSummary] } @@ -136,7 +111,7 @@ export const fetchSummaryPart = async ( apiKey, messages, setActionState, - (e) => appendToSummary(e), + (e) => setSummaryGlobal((v) => v + e), i, promptChunks.length, ) @@ -166,7 +141,7 @@ export const fetchAnswer = async ( apiKey, messages, setActionState, - (e) => appendToSummary(e), + (e) => setSummaryGlobal((v) => v + e), 1, 1, ) @@ -231,7 +206,6 @@ export const fetchApiStream = async ( const content = message.choices[0].delta.content if (message.choices[0].finish_reason === "stop") { - summarizeButtonTitle.innerHTML = "Summarize" appendData("\n") setActionState("") // Last message received, stop processing