Skip to content

Commit f7d8128

Browse files
author
Robert Koehlmoos
authored
Merge pull request #57 from RobertKoehlmoos/604-feature-filter-llm-types
604 feature filter llm types
2 parents ca89229 + 47e0d04 commit f7d8128

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

components/frontend_react/webapp/src/components/query/Configuration.tsx

+33-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import React, { useEffect } from "react"
15+
import React, { useState, useEffect } from "react"
1616
import { fetchAllChatModels, fetchAllEngines } from "@/utils/api"
1717
import { useQuery } from "@tanstack/react-query"
1818
import Loading from "@/navigation/Loading"
@@ -25,20 +25,46 @@ interface ConfigurationProps {
2525
const QueryConfiguration: React.FC<ConfigurationProps> = ({ token }) => {
2626
const { data: engineList, isLoading: enginesLoading, error: enginesError } = useQuery(["fetchEngines"], fetchAllEngines(token))
2727
const { data: modelList, isLoading: modelsLoading, error: modelsError } = useQuery(["fetchModels"], fetchAllChatModels(token))
28+
const { data: multimodalModelList, isLoading: multimodalModelsLoading, error: multimodalModelsError } =
29+
useQuery(["fetchMultimodalModels"], fetchAllChatModels(token, true))
2830

2931
const { selectedModel, setSelectedModel, selectedEngine, setSelectedEngine } = useConfig()
32+
const [selectedEngineIsMultimodal, setSelectedEngineIsMultimodal] = useState<boolean | undefined>(undefined)
3033

3134
useEffect(() => {
3235
if (engineList && engineList.length > 0 && !selectedEngine) {
3336
setSelectedEngine(engineList[0].id)
3437
}
35-
}, [engineList, selectedEngine, setSelectedEngine])
38+
}, [engineList])
3639

37-
if (enginesError || modelsError) return <></>
38-
if (enginesLoading || modelsLoading) {
40+
// Changing if the engine is multimodal when a new one is selected
41+
useEffect(() => {
42+
if (selectedEngine && engineList) {
43+
const engineInfo = engineList.find(
44+
(engine) => engine.id == selectedEngine)
45+
// if the engine isn't in the list, reset to the first one in the list
46+
if (!engineInfo) { setSelectedEngine(engineList[0].id) }
47+
else {
48+
setSelectedEngineIsMultimodal(
49+
(engineInfo.params?.is_multimodal ?? false) === "True")
50+
}
51+
}
52+
}, [selectedEngine])
53+
54+
const displayModelList = selectedEngineIsMultimodal ? multimodalModelList : modelList
55+
// resetting the chat model if it is no longer valid when the engine changes
56+
useEffect(() => {
57+
if (displayModelList !== undefined && !displayModelList.includes(selectedModel) &&
58+
displayModelList.length > 0) {
59+
setSelectedModel(displayModelList[0])
60+
}
61+
}, [selectedEngineIsMultimodal])
62+
63+
if (enginesError || modelsError || multimodalModelsLoading) return <></>
64+
if (enginesLoading || modelsLoading || multimodalModelsError) {
3965
return <Loading />
4066
}
41-
67+
4268
return (
4369
<div className="border-primary-content mt-2 border-t p-2 py-3">
4470
<div className="text-primary-content pb-3 font-semibold">
@@ -53,8 +79,8 @@ const QueryConfiguration: React.FC<ConfigurationProps> = ({ token }) => {
5379
onChange={(e) => setSelectedModel(e.target.value)}
5480
value={selectedModel}
5581
>
56-
{modelList &&
57-
modelList.map((modelOpt) => <option key={modelOpt} value={modelOpt}>{modelOpt}</option>)
82+
{displayModelList &&
83+
displayModelList.map((modelOpt) => <option key={modelOpt} value={modelOpt}>{modelOpt}</option>)
5884
}
5985
</select>
6086
<label htmlFor="engine-select" className="label w-fit pt-3"><span className="label-text text-primary-content">Query Engine:</span></label>

components/frontend_react/webapp/src/utils/api.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ const jobsEndpoint = envOrFail(
5757
)
5858

5959
export const fetchAllChatModels =
60-
(token: string) => (): Promise<string[] | undefined> => {
61-
const url = `${endpoint}/chat/chat_types`
60+
(token: string, isMultimodal?: boolean) => (): Promise<string[] | undefined> => {
61+
let url = `${endpoint}/chat/chat_types`
62+
if (isMultimodal !== undefined) {
63+
url += `?is_multimodal=${isMultimodal}`
64+
}
6265
const headers = { Authorization: `Bearer ${token}` }
6366
return axios.get(url, { headers }).then(path(["data", "data"]))
6467
}

components/frontend_react/webapp/src/utils/types.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { ReactNode } from "react"
16-
import { any, z } from "zod"
16+
import { z } from "zod"
1717

1818
export type INavigationItem = {
1919
name: string
@@ -188,7 +188,15 @@ export type QueryEngine = {
188188
endpoint: string | null
189189
doc_url: string | null
190190
manifest_url: string | null
191-
params: string[] | null
191+
// TODO: The params field is used by the ORM object for storing
192+
// a map of possible keys and values, which is not reflected in the
193+
// current QueryEngine interface
194+
params: {
195+
is_multimodal: string
196+
// typing for an object with any fields taken from
197+
// https://stackoverflow.com/questions/42723922
198+
[key: string]: any
199+
} | null
192200
depth_limit: number | null
193201
agents: string[] | null
194202
child_engines: string[] | null

0 commit comments

Comments
 (0)