Skip to content

Commit

Permalink
stability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
snwfdhmp committed Jun 9, 2023
1 parent a218aa5 commit 649c84b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
dist.zip
web-ext-artifacts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
92 changes: 33 additions & 59 deletions src/components/hooks/useSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down Expand Up @@ -136,7 +111,7 @@ export const fetchSummaryPart = async (
apiKey,
messages,
setActionState,
(e) => appendToSummary(e),
(e) => setSummaryGlobal((v) => v + e),
i,
promptChunks.length,
)
Expand Down Expand Up @@ -166,7 +141,7 @@ export const fetchAnswer = async (
apiKey,
messages,
setActionState,
(e) => appendToSummary(e),
(e) => setSummaryGlobal((v) => v + e),
1,
1,
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 649c84b

Please sign in to comment.