Skip to content

Commit

Permalink
Added FluentUI Slider to chat settings panel for overriding temperatu…
Browse files Browse the repository at this point in the history
…re (#54)

* Added FluentUI Slider to chat settings panel for overriding temperature

* Try to undo the prettier changes

* Try to undo the prettier changes

* Remake changes

* Add to ask as well

* Update default to 0.3 to match Python

---------

Co-authored-by: Pamela Fox <[email protected]>
Co-authored-by: Pamela Fox <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent bd7daa6 commit 51b6453
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
rev: v3.1.0
hooks:
- id: prettier
types_or: [css, javascript, ts, tsx, html]
25 changes: 24 additions & 1 deletion app/frontend/src/pages/ask/Ask.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from "react";
import { Checkbox, Panel, DefaultButton, Spinner, TextField, SpinButton, IDropdownOption, Dropdown } from "@fluentui/react";
import { Checkbox, Panel, DefaultButton, Spinner, Slider, TextField, SpinButton, IDropdownOption, Dropdown } from "@fluentui/react";

import styles from "./Ask.module.css";

Expand All @@ -21,6 +21,7 @@ export function Component(): JSX.Element {
const [promptTemplate, setPromptTemplate] = useState<string>("");
const [promptTemplatePrefix, setPromptTemplatePrefix] = useState<string>("");
const [promptTemplateSuffix, setPromptTemplateSuffix] = useState<string>("");
const [temperature, setTemperature] = useState<number>(0.3);
const [retrievalMode, setRetrievalMode] = useState<RetrievalMode>(RetrievalMode.Hybrid);
const [retrieveCount, setRetrieveCount] = useState<number>(3);
const [useSemanticRanker, setUseSemanticRanker] = useState<boolean>(true);
Expand Down Expand Up @@ -90,6 +91,7 @@ export function Component(): JSX.Element {
prompt_template_suffix: promptTemplateSuffix.length === 0 ? undefined : promptTemplateSuffix,
exclude_category: excludeCategory.length === 0 ? undefined : excludeCategory,
top: retrieveCount,
temperature: temperature,
retrieval_mode: retrievalMode,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
Expand Down Expand Up @@ -124,6 +126,14 @@ export function Component(): JSX.Element {
setPromptTemplateSuffix(newValue || "");
};

const onTemperatureChange = (
newValue: number,
range?: [number, number],
event?: React.MouseEvent | React.TouchEvent | MouseEvent | TouchEvent | React.KeyboardEvent
) => {
setTemperature(newValue);
};

const onRetrieveCountChange = (_ev?: React.SyntheticEvent<HTMLElement, Event>, newValue?: string) => {
setRetrieveCount(parseInt(newValue || "3"));
};
Expand Down Expand Up @@ -236,6 +246,19 @@ export function Component(): JSX.Element {
autoAdjustHeight
onChange={onPromptTemplateChange}
/>

<Slider
className={styles.chatSettingsSeparator}
label="Temperature"
min={0}
max={1}
step={0.1}
defaultValue={temperature}
onChange={onTemperatureChange}
showValue
snapToStep
/>

<SpinButton
className={styles.askSettingsSeparator}
label="Retrieve this many search results:"
Expand Down
24 changes: 23 additions & 1 deletion app/frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRef, useState, useEffect } from "react";
import { Checkbox, Panel, DefaultButton, TextField, SpinButton } from "@fluentui/react";
import { Checkbox, Panel, DefaultButton, TextField, SpinButton, Slider } from "@fluentui/react";
import { SparkleFilled } from "@fluentui/react-icons";
import readNDJSONStream from "ndjson-readablestream";

Expand Down Expand Up @@ -32,6 +32,7 @@ import { GPT4VSettings } from "../../components/GPT4VSettings";
const Chat = () => {
const [isConfigPanelOpen, setIsConfigPanelOpen] = useState(false);
const [promptTemplate, setPromptTemplate] = useState<string>("");
const [temperature, setTemperature] = useState<number>(0.3);
const [retrieveCount, setRetrieveCount] = useState<number>(3);
const [retrievalMode, setRetrievalMode] = useState<RetrievalMode>(RetrievalMode.Hybrid);
const [useSemanticRanker, setUseSemanticRanker] = useState<boolean>(true);
Expand Down Expand Up @@ -145,6 +146,7 @@ const Chat = () => {
prompt_template: promptTemplate.length === 0 ? undefined : promptTemplate,
exclude_category: excludeCategory.length === 0 ? undefined : excludeCategory,
top: retrieveCount,
temperature: temperature,
retrieval_mode: retrievalMode,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
Expand Down Expand Up @@ -202,6 +204,14 @@ const Chat = () => {
setPromptTemplate(newValue || "");
};

const onTemperatureChange = (
newValue: number,
range?: [number, number],
event?: React.MouseEvent | React.TouchEvent | MouseEvent | TouchEvent | React.KeyboardEvent
) => {
setTemperature(newValue);
};

const onRetrieveCountChange = (_ev?: React.SyntheticEvent<HTMLElement, Event>, newValue?: string) => {
setRetrieveCount(parseInt(newValue || "3"));
};
Expand Down Expand Up @@ -373,6 +383,18 @@ const Chat = () => {
onChange={onPromptTemplateChange}
/>

<Slider
className={styles.chatSettingsSeparator}
label="Temperature"
min={0}
max={1}
step={0.1}
defaultValue={temperature}
onChange={onTemperatureChange}
showValue
snapToStep
/>

<SpinButton
className={styles.chatSettingsSeparator}
label="Retrieve this many search results:"
Expand Down

0 comments on commit 51b6453

Please sign in to comment.