Skip to content

Commit

Permalink
Refactor model naming to use a readable format
Browse files Browse the repository at this point in the history
  • Loading branch information
Royal-lobster committed Apr 14, 2024
1 parent f826854 commit 92d53bd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/components/Settings/Sections/ChatSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ const ChatSettings = () => {
</FieldWrapper>

{/* =========================
Modal Setting
Model Setting
===========================*/}

<FieldWrapper
title="Show Local Models"
description="Show local models in the modal selection via ollama (https://ollama.com/) which allows you to use open source models that run on your machine."
description="Show local models in the model selection via ollama (https://ollama.com/) which allows you to use open source models that run on your machine."
row={true}
>
<Switch.Root
Expand Down Expand Up @@ -130,27 +130,27 @@ const ChatSettings = () => {
)}

<FieldWrapper
title="Modal"
title="Model"
description="Choose between OpenAI Chat Modals. For more information, visit https://platform.openai.com/docs/models/overview"
row={true}
>
<select
value={chatSettings.modal}
value={chatSettings.model}
className="input cdx-w-44"
onChange={(e) => {
setSettings({
...settings,
chat: {
...chatSettings,
modal: e.target.value as AvailableModels,
model: e.target.value as AvailableModels,
},
})
}}
>
{availableModels.map(([modal, value]) => (
<option key={modal} value={value}>
{availableModels.map(([model, value]) => (
<option key={model} value={value}>
{capitalizeText(
modal
model
.toLowerCase()
.replace('gpt', 'GPT')
.replace('3_5', '3.5')
Expand Down
14 changes: 4 additions & 10 deletions src/components/Sidebar/chat/ChangeChatModel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BsRobot } from 'react-icons/bs'
import type { AvailableModels } from '../../../config/settings'
import { useChatModels } from '../../../hooks/useChatModels'
import { capitalizeText } from '../../../lib/capitalizeText'
import { getReadableModelName } from '../../../lib/getReadableModelName'

const ChangeChatModel = () => {
const { availableModels, activeChatModel, setActiveChatModel } =
Expand All @@ -16,15 +16,9 @@ const ChangeChatModel = () => {
setActiveChatModel(e.target.value as AvailableModels)
}}
>
{availableModels.map(([modal, value]) => (
<option key={modal} value={value}>
{capitalizeText(
modal
.toLowerCase()
.replace('gpt', 'GPT')
.replace('3_5', '3.5')
.replaceAll('_', ' '),
)}
{availableModels.map(([model, value]) => (
<option key={model} value={value}>
{getReadableModelName(model)}
</option>
))}
</select>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sidebar/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Chat = ({ settings }: ChatProps) => {
removeMessagePair,
error,
} = useChatCompletion({
model: settings.chat.modal,
model: settings.chat.model,
apiKey: settings.chat.openAIKey!,
mode: settings.chat.mode,
systemPrompt: SYSTEM_PROMPT,
Expand Down Expand Up @@ -57,7 +57,7 @@ const Chat = ({ settings }: ChatProps) => {
clearMessages={clearMessages}
cancelRequest={cancelRequest}
isWebpageContextOn={settings.general.webpageContext}
isVisionModel={settings.chat.modal === AvailableModels.GPT_4_VISION}
isVisionModel={settings.chat.model === AvailableModels.GPT_4_VISION}
/>
</>
)
Expand Down
4 changes: 2 additions & 2 deletions src/config/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Settings = {
}
chat: {
openAIKey: string | null
modal: AvailableModels
model: AvailableModels
mode: Mode
showLocalModels: boolean
}
Expand All @@ -46,7 +46,7 @@ export const defaultSettings: Settings = {
},
chat: {
openAIKey: null,
modal: AvailableModels.GPT_4_VISION,
model: AvailableModels.GPT_4_VISION,
mode: Mode.BALANCED,
showLocalModels: false,
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChatModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useChatModels = () => {
const [settings, setSettings] = useSettings()
const [dynamicModels, setDynamicModels] = useState<string[]>([])
const chatSettings = settings.chat
const activeChatModel = chatSettings.modal
const activeChatModel = chatSettings.model

const fetchLocalModels = useCallback(async () => {
if (chatSettings.showLocalModels) {
Expand Down Expand Up @@ -38,7 +38,7 @@ export const useChatModels = () => {
...settings,
chat: {
...chatSettings,
modal: model,
model: model,
},
})
}
Expand Down
11 changes: 11 additions & 0 deletions src/lib/getReadableModelName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { capitalizeText } from './capitalizeText'

export const getReadableModelName = (model: string) => {
return capitalizeText(
model
.toLowerCase()
.replace('gpt', 'GPT')
.replace(/(\d+)_(\d+)/, '$1.$2')
.replace(/[_:]/g, ' '),
)
}

0 comments on commit 92d53bd

Please sign in to comment.