-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
229 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
frontend/src/components/ModelSelectionBox/ModelSelectionBox.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#model-selection-box { | ||
padding: 1px 32px; | ||
position: relative; | ||
} | ||
|
||
#model-selection-row { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
#model-selection-info { | ||
align-items: center; | ||
text-align: center; | ||
} | ||
|
||
#model-selection-info p { | ||
margin: 0; | ||
padding: 0; | ||
color:cadetblue | ||
} | ||
|
||
#p error { | ||
color: red; | ||
} | ||
|
||
#model-selection-info { | ||
|
||
} | ||
|
||
|
||
#model-selection-menu { | ||
width: 60%; | ||
padding: 5px; | ||
margin-right: 10px; | ||
} | ||
|
||
#model-selection-button { | ||
padding: 5px; | ||
} |
80 changes: 80 additions & 0 deletions
80
frontend/src/components/ModelSelectionBox/ModelSelectionBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Path: frontend\src\components\ModelSelectionBox\ModelSelectionBox.tsx | ||
import React, { useEffect, useState } from "react"; | ||
import "./ModelSelectionBox.css"; | ||
import { setGptModel, getGptModel } from "../../service/chatService"; | ||
import { CHAT_MODELS } from "../../models/chat"; | ||
|
||
// return a drop down menu with the models | ||
function ModelSelectionBox() { | ||
// model currently selected in the dropdown | ||
const [selectedModel, setSelectedModel] = useState("gpt-4"); | ||
// model in use by the app | ||
const [modelInUse, setModelInUse] = useState("gpt-4"); | ||
|
||
const [errorChangingModel, setErrorChangingModel] = useState(false); | ||
|
||
// handle button click to log the selected model | ||
const submitSelectedModel = async () => { | ||
console.log("selected model: " + selectedModel); | ||
if (await setGptModel(selectedModel)) { | ||
setModelInUse(selectedModel); | ||
setErrorChangingModel(false); | ||
} else { | ||
setErrorChangingModel(true); | ||
} | ||
}; | ||
|
||
// get the model | ||
useEffect(() => { | ||
const getModel = async () => { | ||
const model = await getGptModel(); | ||
if (model) { | ||
setModelInUse(model); | ||
} | ||
}; | ||
getModel(); | ||
}, []); | ||
|
||
const chatModelOptions = Object.values(CHAT_MODELS); | ||
|
||
// return a drop down menu with the models | ||
return ( | ||
<div id="model-selection-box"> | ||
<div id="model-selection-row"> | ||
<p>Select a model: </p> | ||
<select | ||
id="model-selection-menu" | ||
aria-label="model-select" | ||
onChange={(e) => setSelectedModel(e.target.value)} | ||
placeholder={modelInUse} | ||
> | ||
{chatModelOptions.map((model) => ( | ||
<option value={model}>{model}</option> | ||
))} | ||
; | ||
</select> | ||
<button | ||
id="model-selection-button" | ||
onClick={async () => submitSelectedModel()} | ||
> | ||
Choose | ||
</button> | ||
</div> | ||
|
||
<div id="model-selection-info"> | ||
{errorChangingModel ? ( | ||
<p id="error"> | ||
Could not change model. You are still chatting to: | ||
<b> {modelInUse} </b> | ||
</p> | ||
) : ( | ||
<p> | ||
You are chatting to model: <b> {modelInUse}</b> | ||
</p> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default ModelSelectionBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.