-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chat settings #603
Chat settings #603
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,16 @@ | |
width: 100%; | ||
} | ||
} | ||
|
||
.settings-container { | ||
position: absolute; | ||
bottom: var(--spacing-16); | ||
left: var(--spacing-16); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aw thanks. Feel free to do the minimum when it comes to CSS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I will :D |
||
.settings { | ||
padding: var(--spacing-32); | ||
margin-bottom: var(--spacing-24); | ||
flex-direction: column; | ||
gap: var(--spacing-24); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,18 @@ export type SearchResult = { | |
result: Entry | ||
} | ||
|
||
export type Mode = 'rookie' | 'concise' | 'default' | 'discord' | ||
type Model = | ||
| 'gpt-3.5-turbo' | ||
| 'gpt-4' | ||
| 'gpt-4-turbo-preview' | ||
| 'claude-3-opus-20240229' | ||
| 'claude-3-sonnet-20240229' | ||
| 'claude-3-haiku-20240307' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of these models should work, in case you want a faster/simpler model |
||
export type Mode = 'rookie' | 'concise' | 'default' | ||
export type ChatSettings = { | ||
mode?: Mode | ||
completions?: Model | ||
} | ||
|
||
const DATA_HEADER = 'data: ' | ||
const EVENT_END_HEADER = 'event: close' | ||
|
@@ -229,7 +240,8 @@ export const extractAnswer = async ( | |
const fetchLLM = async ( | ||
sessionId: string | undefined, | ||
history: HistoryEntry[], | ||
controller: AbortController | ||
controller: AbortController, | ||
settings?: ChatSettings | ||
): Promise<Response | void> => | ||
fetch(CHATBOT_URL, { | ||
signal: controller.signal, | ||
|
@@ -240,18 +252,19 @@ const fetchLLM = async ( | |
'Content-Type': 'application/json', | ||
Accept: 'text/event-stream', | ||
}, | ||
body: JSON.stringify({sessionId, history, settings: {mode: 'default'}}), | ||
body: JSON.stringify({sessionId, history, settings}), | ||
}).catch(ignoreAbort) | ||
|
||
export const queryLLM = async ( | ||
history: HistoryEntry[], | ||
setCurrent: (e: AssistantEntry) => void, | ||
sessionId: string | undefined, | ||
controller: AbortController | ||
controller: AbortController, | ||
settings?: ChatSettings | ||
): Promise<SearchResult> => { | ||
setCurrent({...makeEntry(), phase: 'started'}) | ||
// do SSE on a POST request. | ||
const res = await fetchLLM(sessionId, history, controller) | ||
const res = await fetchLLM(sessionId, history, controller, settings) | ||
|
||
if (!res) { | ||
return {result: {role: 'error', content: 'No response from server'}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,10 @@ svg { | |
cursor: pointer; | ||
} | ||
|
||
.full-height { | ||
height: 100%; | ||
} | ||
|
||
/* for troubleshooting */ | ||
|
||
.pink { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,62 @@ | ||
import {useState} from 'react' | ||
import {ShouldRevalidateFunction, useSearchParams} from '@remix-run/react' | ||
import SettingsIcon from '~/components/icons-generated/Settings' | ||
import Page from '~/components/Page' | ||
import Chatbot from '~/components/Chatbot' | ||
import {ChatSettings, Mode} from '~/hooks/useChat' | ||
import Button from '~/components/Button' | ||
|
||
export const shouldRevalidate: ShouldRevalidateFunction = () => false | ||
|
||
export default function App() { | ||
const [params] = useSearchParams() | ||
const [showSettings, setShowSettings] = useState(false) | ||
const [chatSettings, setChatSettings] = useState({mode: 'default'} as ChatSettings) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change this to e.g. |
||
const question = params.get('question') || undefined | ||
|
||
const ModeButton = ({name, mode}: {name: string; mode: Mode}) => ( | ||
<Button | ||
className={chatSettings.mode === mode ? 'primary-alt' : ''} | ||
action={() => setChatSettings({...chatSettings, mode})} | ||
> | ||
{name} | ||
</Button> | ||
) | ||
|
||
const stopBubbling = (e: any) => { | ||
e.preventDefault() | ||
e.stopPropagation() | ||
e.nativeEvent.stopImmediatePropagation() | ||
} | ||
|
||
return ( | ||
<Page noFooter> | ||
<div className="page-body"> | ||
<div className="page-body full-height" onClick={stopBubbling}> | ||
<Chatbot | ||
question={question} | ||
questions={[ | ||
'What is AI Safety?', | ||
'How would the AI even get out in the world?', | ||
'Do people seriously worry about existential risk from AI?', | ||
]} | ||
settings={chatSettings} | ||
/> | ||
<div className="settings-container" onClick={stopBubbling}> | ||
{showSettings && ( | ||
<div className="settings bordered flex-container"> | ||
<div>Answer detail</div> | ||
<ModeButton mode="default" name="Default" /> | ||
<ModeButton mode="rookie" name="Detailed" /> | ||
<ModeButton mode="concise" name="Concise" /> | ||
</div> | ||
)} | ||
<SettingsIcon | ||
width="32" | ||
height="32" | ||
className="pointer" | ||
onClick={() => setShowSettings((current) => !current)} | ||
/> | ||
</div> | ||
</div> | ||
</Page> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this icon will have to be changed, but this will suffice for styling