Skip to content

Commit 492fbfe

Browse files
committed
create reroute for ohtu-test sandbox
1 parent 98fed36 commit 492fbfe

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/client/Router.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const router = createBrowserRouter(
2121
<Route path="/" element={<App />}>
2222
<Route index element={<Chat />} />
2323
<Route path="/v2" element={<ChatV2 />} />
24+
<Route path="/v2/:courseId" element={<ChatV2 />} />
2425
<Route path="/:courseId" element={<Chat />} />
2526
<Route path="/courses" element={<Courses />} />
2627
<Route path="/courses/:id" element={<Course />} />

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ import { Close, Settings } from '@mui/icons-material'
2121
import { SettingsModal } from './SettingsModal'
2222

2323
export const ChatV2 = () => {
24-
const [settingsModalOpen, setSettingsModalOpen] = useState(false)
2524
const { courseId } = useParams()
26-
2725
const { course } = useCourse(courseId)
26+
const { infoTexts, isLoading: infoTextsLoading } = useInfoTexts()
27+
2828
const { userStatus, isLoading: statusLoading, refetch: refetchStatus } = useUserStatus(courseId)
2929
const [model, setModel] = useLocalStorageState<{ name: string }>('model-v2', {
3030
name: DEFAULT_MODEL,
3131
})
32-
const { infoTexts, isLoading: infoTextsLoading } = useInfoTexts()
33-
const [activePromptId, setActivePromptId] = useState('')
3432
const [system, setSystem] = useLocalStorageState<{ content: string }>('general-chat-system', { content: '' })
3533
const [message, setMessage] = useLocalStorageState<{ content: string }>('general-chat-current', { content: '' })
3634
const [messages, setMessages] = useLocalStorageState<Message[]>('general-chat-messages', [])
3735
const [prevResponse, setPrevResponse] = useLocalStorageState<{
3836
id: string
3937
}>('general-prev-response', { id: '' })
40-
38+
4139
const appContainerRef = useContext(AppContext)
4240
const chatContainerRef = useRef<HTMLDivElement>(null)
43-
4441
const inputFileRef = useRef<HTMLInputElement>(null)
42+
43+
const [settingsModalOpen, setSettingsModalOpen] = useState(false)
44+
const [activePromptId, setActivePromptId] = useState('')
4545
const [fileName, setFileName] = useState<string>('')
4646
const [completion, setCompletion] = useState('')
4747
const [streamController, setStreamController] = useState<AbortController>()
@@ -50,8 +50,9 @@ export const ChatV2 = () => {
5050
const [tokenUsageWarning, setTokenUsageWarning] = useState('')
5151
const [tokenWarningVisible, setTokenWarningVisible] = useState(false)
5252
const [modelTemperature, setModelTemperature] = useState(0.5)
53-
const [setRetryTimeout, clearRetryTimeout] = useRetryTimeout()
5453
const [saveConsent, setSaveConsent] = useState(true)
54+
55+
const [setRetryTimeout, clearRetryTimeout] = useRetryTimeout()
5556

5657
const { t, i18n } = useTranslation()
5758
const { language } = i18n
@@ -197,6 +198,8 @@ export const ChatV2 = () => {
197198
}}
198199
>
199200
<SettingsModal open={settingsModalOpen} setOpen={setSettingsModalOpen}></SettingsModal>
201+
<Box sx={{ display: 'flex', justifyContent: 'space-between'}}>
202+
200203
<Box sx={{ display: 'flex', gap: '1rem' }}>
201204
{disclaimerInfo && <Disclaimer disclaimer={disclaimerInfo} />}
202205
<SystemPrompt content={system.content} setContent={(content) => setSystem({ content })} />
@@ -205,6 +208,8 @@ export const ChatV2 = () => {
205208
<Settings></Settings>
206209
</IconButton>
207210
</Box>
211+
<Button variant='outlined' size='small'>Ohtu sandbox</Button>
212+
</Box>
208213
<Box ref={chatContainerRef}>
209214
<Conversation messages={messages} completion={completion} />
210215
<ChatBox

src/client/components/ChatV2/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ export const getCourseCompletionStream = async ({ id, system, messages, model, c
7878
const formData = new FormData()
7979
formData.set('data', JSON.stringify(data))
8080

81-
return postAbortableStream(`/ai/stream/v2`, formData, abortController)
81+
return postAbortableStream(`/ai/stream/${courseId}/v2`, formData, abortController)
8282
}

src/server/routes/openai.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { CourseChatRequest, RequestWithUser } from '../types'
55
import { isError } from '../util/parser'
66
import { calculateUsage, incrementUsage, checkUsage, checkCourseUsage, incrementCourseUsage } from '../services/chatInstances/usage'
77
import { getCompletionEvents, streamCompletion } from '../util/azure/client'
8-
import { ResponsesClient } from '../util/azure/ResponsesAPI'
98
import { getMessageContext, getModelContextLimit, getCourseModel, getAllowedModels } from '../util/util'
109
import getEncoding from '../util/tiktoken'
1110
import logger from '../util/logger'
1211
import { inProduction, DEFAULT_TOKEN_LIMIT, FREE_MODEL } from '../../config'
1312
import { pdfToText } from '../util/pdfToText'
1413
import { Discussion, ChatInstance } from '../db/models'
1514

15+
import { ResponsesClient } from '../util/azure/ResponsesAPI'
16+
1617
const openaiRouter = express.Router()
1718

1819
const storage = multer.memoryStorage()

src/server/util/azure/courseAssistants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const courseAssistants = [
1414
vector_store_id: null,
1515
},
1616
{
17-
course_id: '123',
17+
course_id: 'ohtu-test',
1818
name: 'ohtu-kurssi',
1919
assistant_instruction:
2020
'Olet ohjelmistotuotanto kurssin avustaja. Jos käyttäjä kysyy jotain, niin arvioi ensin liittyykö se ohjelmistotuotannon kurssiin. Jos liittyy, niin toteuta file_search. jos et löydä sopivia tiedostoja, niin sano että haulla ei löytynyt mitään. Jos käyttäjän viesti ei liittynyt ohjelmistotuotannon kurssiin, niin kysy ystävällisesti voitko auttaa jotenkin muuten kurssimateriaalien suhteen.',

0 commit comments

Comments
 (0)