Skip to content

Commit 3f4e2b7

Browse files
committed
feat: model switcher (#98, #126)
1 parent 63ab62c commit 3f4e2b7

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

src/components/ConversationCard/index.jsx

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FileSaver from 'file-saver'
1010
import { render } from 'preact'
1111
import FloatingToolbar from '../FloatingToolbar'
1212
import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
13-
import { defaultConfig, getUserConfig } from '../../config/index.mjs'
13+
import { defaultConfig, getUserConfig, Models } from '../../config/index.mjs'
1414
import { useTranslation } from 'react-i18next'
1515
import DeleteButton from '../DeleteButton'
1616

@@ -35,7 +35,7 @@ function ConversationCard(props) {
3535
const [isReady, setIsReady] = useState(!props.question)
3636
const [port, setPort] = useState(() => Browser.runtime.connect())
3737
const [session, setSession] = useState(props.session)
38-
const windowSize = useClampWindowSize([0, Infinity], [250, 1100])
38+
const windowSize = useClampWindowSize([750, 1500], [250, 1100])
3939
const bodyRef = useRef(null)
4040
/**
4141
* @type {[ConversationItemData[], (conversationItemData: ConversationItemData[]) => void]}
@@ -175,27 +175,46 @@ function ConversationCard(props) {
175175
return (
176176
<div className="gpt-inner">
177177
<div className="gpt-header" style="margin: 15px;">
178-
{props.closeable ? (
179-
<XLg
180-
className="gpt-util-icon"
181-
title={t('Close the Window')}
182-
size={16}
183-
onClick={() => {
184-
if (props.onClose) props.onClose()
185-
}}
186-
/>
187-
) : props.dockable ? (
188-
<Pin
189-
className="gpt-util-icon"
190-
title={t('Pin the Window')}
191-
size={16}
192-
onClick={() => {
193-
if (props.onDock) props.onDock()
178+
<span className="gpt-util-group">
179+
{props.closeable ? (
180+
<XLg
181+
className="gpt-util-icon"
182+
title={t('Close the Window')}
183+
size={16}
184+
onClick={() => {
185+
if (props.onClose) props.onClose()
186+
}}
187+
/>
188+
) : props.dockable ? (
189+
<Pin
190+
className="gpt-util-icon"
191+
title={t('Pin the Window')}
192+
size={16}
193+
onClick={() => {
194+
if (props.onDock) props.onDock()
195+
}}
196+
/>
197+
) : (
198+
<img src={logo} style="user-select:none;width:20px;height:20px;" />
199+
)}
200+
<select
201+
style={{ width: windowSize[0] * 0.05 + 'px' }}
202+
className="normal-button"
203+
required
204+
onChange={(e) => {
205+
const modelName = e.target.value
206+
setSession({ ...session, modelName, aiName: t(Models[modelName].desc) })
194207
}}
195-
/>
196-
) : (
197-
<img src={logo} style="user-select:none;width:20px;height:20px;" />
198-
)}
208+
>
209+
{Object.entries(Models).map(([key, model]) => {
210+
return (
211+
<option value={key} key={key} selected={key === session.modelName}>
212+
{t(model.desc)}
213+
</option>
214+
)
215+
})}
216+
</select>
217+
</span>
199218
{props.draggable ? (
200219
<div className="dragbar" />
201220
) : (

0 commit comments

Comments
 (0)