Skip to content

Added "filter" option to webChatGPT #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -86,6 +86,10 @@ No, the extension does not collect any user data or analytics.

<br>

## Disclaimer

This extension does not provide financial, medical, or social advice. This information, including but not limited to, text, graphics, images and other material found through this extension are for informational purposes only. No material found through this extension is intended to be a substitute for professional financial, medical, or social advice, strategies, diagnosis, treatment, or feedback. You agree, acknowledge, and alone assume the sole responsibility of evaluating the merits and risks associated with the use of any information or other content found through this extension before making any decisions based on such information. Always seek the advice of trained financial advisors, physicians, healthcare providers, or representatives with any questions you may have regarding financial, medical, and social conditions. Never disregard professional advice or delay in seeking it because of something you have read through this extension.

## Contributing

Contributions are welcome! Please submit pull requests to the `dev` branch.
Binary file modified build/webchatgpt-3.1.6-chrome.zip
Binary file not shown.
Binary file modified build/webchatgpt-3.1.6-firefox.zip
Binary file not shown.
12 changes: 12 additions & 0 deletions src/components/toolbar.tsx
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { icons } from 'src/util/icons'
import { getSavedPrompts, Prompt } from 'src/util/promptManager'
import { getUserConfig, updateUserConfig } from 'src/util/userConfig'
import timePeriodOptions from 'src/util/timePeriodOptions.json'
import filterTypeOptions from 'src/util/filterTypeOptions.json'
import regionOptions from 'src/util/regionOptions.json'
import Browser from 'webextension-polyfill'
import Dropdown from './dropdown'
@@ -25,6 +26,7 @@ function Toolbar(
const [numResults, setNumResults] = useState(3)
const [timePeriod, setTimePeriod] = useState('')
const [region, setRegion] = useState('wt-wt')
const [filterType, setFilterType] = useState('All')
const [promptUUID, setPromptUUID] = useState<string>('')
const [prompts, setPrompts] = useState<Prompt[]>([])

@@ -34,6 +36,7 @@ function Toolbar(
setNumResults(userConfig.numWebResults)
setTimePeriod(userConfig.timePeriod)
setRegion(userConfig.region)
setFilterType(userConfig.filterType)
setPromptUUID(userConfig.promptUUID)

setLocaleLanguage(userConfig.language)
@@ -110,6 +113,11 @@ function Toolbar(
updateUserConfig({ promptUUID: uuid })
}

const handleFilterTypeChange = (e: { target: { value: string } }) => {
setFilterType(e.target.value)
updateUserConfig({ filterType: e.target.value })
}

const removeFocusFromCurrentElement = () => (document.activeElement as HTMLElement)?.blur()


@@ -148,6 +156,10 @@ function Toolbar(
value={region}
onChange={handleRegionChange}
options={regionOptions} />
<Dropdown
value={filterType}
onChange={handleFilterTypeChange}
options={filterTypeOptions} />
<Dropdown
value={promptUUID}
onChange={handlePromptChange}
6 changes: 3 additions & 3 deletions src/content-scripts/mainUI.tsx
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ async function onSubmit(event: MouseEvent | KeyboardEvent) {
results = await webSearch(searchRequest, userConfig.numWebResults)
}

await pasteWebResultsToTextArea(results, query)
await pasteWebResultsToTextArea(results, query, userConfig.filterType)
pressEnter()
isProcessing = false

@@ -92,9 +92,9 @@ async function onSubmit(event: MouseEvent | KeyboardEvent) {
}
}

async function pasteWebResultsToTextArea(results: SearchResult[], query: string) {
async function pasteWebResultsToTextArea(results: SearchResult[], query: string, filterType: string) {

textarea.value = await compilePrompt(results, query)
textarea.value = await compilePrompt(results, query, filterType)
}

function pressEnter() {
6 changes: 6 additions & 0 deletions src/util/filterTypeOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{ "value": "All", "label": "All" },
{ "value": "Med", "label": "Med" },
{ "value": "Gov", "label": "Gov" },
{ "value": "Res", "label": "Res" }
]
14 changes: 10 additions & 4 deletions src/util/promptManager.ts
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@ export interface Prompt {

const removeCommands = (query: string) => query.replace(/\/page:(\S+)\s+/g, '').replace(/\/site:(\S+)\s+/g, '')

export const compilePrompt = async (results: SearchResult[], query: string) => {
export const compilePrompt = async (results: SearchResult[], query: string, filterType: string) => {
const currentPrompt = await getCurrentPrompt()
const formattedResults = formatWebResults(results)
const formattedResults = formatWebResults(results, filterType)
const currentDate = new Date().toLocaleDateString()
const prompt = replaceVariables(currentPrompt.text, {
'{web_results}': formattedResults,
@@ -26,11 +26,17 @@ export const compilePrompt = async (results: SearchResult[], query: string) => {
return prompt
}

const formatWebResults = (results: SearchResult[]) => {
const formatWebResults = (results: SearchResult[], filterType: string) => {
if (results.length === 0) {
return "No results found.\n"
}

if (filterType === "Med") {
results = results.filter(result => (result.url.includes("mayoclinic.org") || result.url.includes("medlineplus.gov") || result.url.includes("merckmanuals.com") || result.url.includes("pubmed.ncbi.nlm.nih.gov") || result.url.includes("webmd.com") || result.url.includes("nih.gov") || result.url.includes("womenshealth.gov") || result.url.includes("healthline.com") || result.url.includes("uptodate.com") || result.url.includes("diabetes.org") || result.url.includes("familydoctor.org") || result.url.includes("heart.org") || result.url.includes("fda.gov") || result.url.includes("medscape.com") || result.url.includes("cdc.gov") || result.url.includes("examine.com") || result.url.includes("nhs.uk") || result.url.includes("thefreedictionary.com") || result.url.includes("bestpractice.bmj.com") || result.url.includes("nejm.org") || result.url.includes("samhsa.gov") || result.url.includes("cancer.gov") || result.url.includes("nice.org.uk") || result.url.includes("journals.plos.org") || result.url.includes("apa.org") || result.url.includes("cochranelibrary.com"))); // New code to check for credibility
} else if (filterType === "Gov") {
results = results.filter(result => (result.url.includes(".gov"))); // New code to check for credibility
} else if (filterType === "Res") {
results = results.filter(result => (result.url.includes("doi") || result.url.includes("sciencedirect.com") || result.url.includes("academic.oup.com") || result.url.includes("journal") || result.url.includes("article") || result.url.includes("abstract") || result.url.includes("publication") || result.url.includes("mdpi.com"))); // New code to check for credibility
}
let counter = 1
return results.reduce((acc, result): string => acc += `[${counter++}] "${result.body}"\nURL: ${result.url}\n\n`, "")
}
1 change: 1 addition & 0 deletions src/util/userConfig.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ const defaultConfig = {
webAccess: true,
region: 'wt-wt',
timePeriod: '',
filterType: 'All',
language: getSystemLanguage(),
promptUUID: 'default',
}