Skip to content

Commit

Permalink
feat: enabled API Modes option (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Apr 29, 2023
1 parent 4ba1a8d commit ae28ca6
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/_locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@
"Modules": "Modules",
"API Params": "API Params",
"API Url": "API Url",
"Others": "Others"
"Others": "Others",
"API Modes": "API Modes"
}
3 changes: 2 additions & 1 deletion src/_locales/zh-hans/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@
"Modules": "模块",
"API Params": "API参数",
"API Url": "API地址",
"Others": "其他"
"Others": "其他",
"API Modes": "API模式"
}
3 changes: 2 additions & 1 deletion src/_locales/zh-hant/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@
"Modules": "模組",
"API Params": "API參數",
"API Url": "API網址",
"Others": "其他"
"Others": "其他",
"API Modes": "API模式"
}
3 changes: 2 additions & 1 deletion src/components/ConversationCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ function ConversationCard(props) {
else setSession(newSession)
}}
>
{Object.entries(Models).map(([key, model]) => {
{config.activeApiModes.map((key) => {
const model = Models[key]
return (
<option value={key} key={key} selected={key === session.modelName}>
{t(model.desc)}
Expand Down
15 changes: 15 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ export const defaultConfig = {
// others

alwaysCreateNewConversationWindow: false,
activeApiModes: [
'chatgptFree35',
'chatgptPlus4',
'chatgptApi35',
'bingFree4',
'bingFreeSydney',
'poeAiWebSage',
'poeAiWebGPT4',
'poeAiWebClaudePlus',
'chatgptApi4_8k',
'customModel',
'azureOpenAi',
'poeAiWebCustom',
],
activeSelectionTools: ['translate', 'summary', 'polish', 'code', 'ask'],
activeSiteAdapters: [
'bilibili',
Expand All @@ -139,6 +153,7 @@ export const defaultConfig = {
// unchangeable

userLanguage: getNavigatorLanguage(),
apiModes: Object.keys(Models),
selectionTools: [
'translate',
'translateToEn',
Expand Down
4 changes: 4 additions & 0 deletions src/content-script/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ async function overwriteAccessToken() {
async function prepareForForegroundRequests() {
if (location.hostname !== 'chat.openai.com') return

const userConfig = await getUserConfig()

if (!chatgptWebModelKeys.some((model) => userConfig.activeApiModes.includes(model))) return

const div = document.createElement('div')
document.body.append(div)
render(<NotificationForChatGPTWeb container={div} />, div)
Expand Down
32 changes: 32 additions & 0 deletions src/popup/sections/ApiModes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import { Models } from '../../config/index.mjs'

ApiModes.propTypes = {
config: PropTypes.object.isRequired,
updateConfig: PropTypes.func.isRequired,
}

export function ApiModes({ config, updateConfig }) {
const { t } = useTranslation()

return (
<>
{config.apiModes.map((key) => (
<label key={key}>
<input
type="checkbox"
checked={config.activeApiModes.includes(key)}
onChange={(e) => {
const checked = e.target.checked
const activeApiModes = config.activeApiModes.filter((i) => i !== key)
if (checked) activeApiModes.push(key)
updateConfig({ activeApiModes })
}}
/>
{t(Models[key].desc)}
</label>
))}
</>
)
}
3 changes: 2 additions & 1 deletion src/popup/sections/GeneralPart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export function GeneralPart({ config, updateConfig }) {
updateConfig({ modelName: modelName })
}}
>
{Object.entries(Models).map(([key, model]) => {
{config.activeApiModes.map((key) => {
const model = Models[key]
return (
<option value={key} key={key} selected={key === config.modelName}>
{t(model.desc)}
Expand Down
5 changes: 5 additions & 0 deletions src/popup/sections/ModulesPart.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs'
import { ApiModes } from './ApiModes'
import { SelectionTools } from './SelectionTools'
import { SiteAdapters } from './SiteAdapters'

Expand All @@ -16,10 +17,14 @@ export function ModulesPart({ config, updateConfig }) {
<>
<Tabs selectedTabClassName="popup-tab--selected">
<TabList>
<Tab className="popup-tab">{t('API Modes')}</Tab>
<Tab className="popup-tab">{t('Selection Tools')}</Tab>
<Tab className="popup-tab">{t('Sites')}</Tab>
</TabList>

<TabPanel>
<ApiModes config={config} updateConfig={updateConfig} />
</TabPanel>
<TabPanel>
<SelectionTools config={config} updateConfig={updateConfig} />
</TabPanel>
Expand Down

0 comments on commit ae28ca6

Please sign in to comment.