Skip to content

Commit 02bd05f

Browse files
author
Robert Koehlmoos
authored
Merge pull request #52 from RobertKoehlmoos/586-feature-multimodal-create-engine
586 feature multimodal create engine
2 parents c82f115 + 5fbb744 commit 02bd05f

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ node_modules
4141

4242
# VSCode related
4343
*.code-workspace
44+
45+
# react deployment configurations
46+
components/frontend_react/webapp/.env.production
47+
components/frontend_react/webapp/.env.development

components/frontend_react/webapp/src/components/forms/fields/BooleanField.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const BooleanField: React.FC<BooleanFieldProps> = ({
3737
type="checkbox"
3838
className="peer toggle toggle-sm sr-only"
3939
name={variable.name}
40+
onClick={() => { variable.onClick() }}
4041
/>
4142
<div className="peer-focus:ring-7 h-6 w-11 rounded-full bg-base-300 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:border-primary after:border-primary after:bg-base-100 after:transition-all after:content-[''] peer-checked:bg-primary peer-checked:after:translate-x-full peer-checked:after:border-primary peer-focus:outline-none peer-focus:ring-primary dark:peer-focus:ring-primary"></div>
4243
</label>

components/frontend_react/webapp/src/routes/QueryEngineEdit.tsx

+28-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ALERT_TYPE } from "@/utils/types"
2525
import { Link, useNavigate } from "react-router-dom"
2626
import { useQueryParams } from "@/utils/routing"
2727
import { userStore, alertStore } from "@/store"
28+
import { fetchEmbeddingTypes } from "@/utils/api"
2829

2930
interface IQueryEngineProps {
3031
token: string
@@ -45,6 +46,9 @@ const QueryEngineEdit: React.FC<IQueryEngineProps> = ({ token }) => {
4546
const [queryEngines, setQueryEngines] = useState<QueryEngine[]>([])
4647
const [queryEngine, setQueryEngine] = useState<QueryEngine | null>(null)
4748

49+
const [createEngineIsMultimodal, setCreateEngineIsMultimodal] = useState(false)
50+
const [createEngineEmbeddingOptions, setCreateEngineEmbeddingOptions] = useState<{ option: string; value: string; }[]>([])
51+
4852
const { isLoading, data: engineList } = useQuery(
4953
["QueryEngines"],
5054
fetchAllEngines(token),
@@ -166,6 +170,29 @@ const QueryEngineEdit: React.FC<IQueryEngineProps> = ({ token }) => {
166170
return <Loading />
167171
}
168172

173+
const updatedQueryEngineFormData = QUERY_ENGINE_FORM_DATA.map(
174+
(entry) => {
175+
switch (entry.name) {
176+
case "is_multimodal":
177+
return { ...entry, onClick: () => { setCreateEngineIsMultimodal(!createEngineIsMultimodal) } }
178+
case "embedding_type":
179+
return { ...entry, options: createEngineEmbeddingOptions }
180+
default:
181+
return entry
182+
}
183+
})
184+
185+
useEffect(() => {
186+
const updateEngineEmbeddings = async () => {
187+
const llmTypes = await (await fetchEmbeddingTypes(token, createEngineIsMultimodal))()
188+
console.log(llmTypes)
189+
if (llmTypes === null || llmTypes === undefined) console.error("Failed to retrieve embedding types")
190+
else setCreateEngineEmbeddingOptions(llmTypes.map((embedding) => { return { option: embedding, value: embedding } }))
191+
}
192+
updateEngineEmbeddings()
193+
},
194+
[createEngineIsMultimodal])
195+
169196
return (
170197
<div className="overflow-x-auto custom-scrollbar">
171198
<div className="min-h-screen">
@@ -204,7 +231,7 @@ const QueryEngineEdit: React.FC<IQueryEngineProps> = ({ token }) => {
204231
onFailure={onFailure}
205232
handleFiles={null}
206233
queryEngine={queryEngine}
207-
currentVarsData={QUERY_ENGINE_FORM_DATA}
234+
currentVarsData={updatedQueryEngineFormData}
208235
/>
209236
</div>
210237

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

+8
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export const resumeChat =
118118
return axios.post(url, data, { headers }).then(path(["data", "data"]))
119119
}
120120

121+
export const fetchEmbeddingTypes =
122+
(token: string, are_multimodal: boolean) => (): Promise<string[] | undefined | null> => {
123+
let url = `${endpoint}/llm/embedding_types?is_multimodal=${are_multimodal}`
124+
const headers = { Authorization: `Bearer ${token}` }
125+
return axios.get(url, { headers }).then(path(["data", "data"]))
126+
}
127+
121128
export const fetchQuery =
122129
(token: string, queryId: string | null) => (): Promise<Query | undefined | null> => {
123130
if (!queryId) return Promise.resolve(null)
@@ -168,6 +175,7 @@ export const createQueryEngine =
168175
"agents": queryEngine.agents,
169176
"associated_engines": queryEngine.child_engines,
170177
"manifest_url": queryEngine.manifest_url,
178+
"is_multimodal": queryEngine.is_multimodal ? "True" : "False",
171179
}
172180
}
173181
return axios.post(url, data, { headers }).then(path(["data", "data"]))

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const QUERY_ENGINE_FORM_DATA: IFormVariable[] = [
8888
order: 1,
8989
},
9090
{
91-
name: "type",
91+
name: "query_engine_type",
9292
display: "Query Engine Type",
9393
tooltip: "Type of Query Engine. GENIE is the native type.",
9494
type: "select",
@@ -101,6 +101,17 @@ export const QUERY_ENGINE_FORM_DATA: IFormVariable[] = [
101101
group: "queryengine",
102102
order: 1,
103103
},
104+
{
105+
name: "is_multimodal",
106+
display: "Multimodal Engine",
107+
tooltip: "Type of Query Engine. GENIE is the native type.",
108+
type: "bool",
109+
description: "",
110+
default: false,
111+
required: true,
112+
group: "queryengine",
113+
order: 1,
114+
},
104115
{
105116
name: "doc_url",
106117
display: "Data URL",
@@ -140,9 +151,7 @@ export const QUERY_ENGINE_FORM_DATA: IFormVariable[] = [
140151
display: "Embedding Type",
141152
type: "select",
142153
description: "",
143-
options: [{option: "Vertex", value: "VertexAI-Embedding"},
144-
{option: "OpenAI", value: "OpenAI-Embedding"},
145-
{option: "HuggingFace", value: "HuggingFaceEmbeddings"}],
154+
options: [],
146155
default: "Vertex",
147156
required: true,
148157
group: "queryengine",

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

+4-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 { z } from "zod"
16+
import { any, z } from "zod"
1717

1818
export type INavigationItem = {
1919
name: string
@@ -70,6 +70,7 @@ export const FormVariable = z.object({
7070
fileLabel: z.string().optional(),
7171
multiple: z.boolean().default(false).optional(),
7272
accept: z.string().optional(),
73+
onClick: z.function().optional(),
7374
})
7475

7576
export type IFormVariable = z.infer<typeof FormVariable>
@@ -189,8 +190,9 @@ export type QueryEngine = {
189190
manifest_url: string | null
190191
params: string[] | null
191192
depth_limit: number | null
192-
agents: string[] | null
193+
agents: string[] | null
193194
child_engines: string[] | null
195+
is_multimodal: boolean | null
194196
}
195197

196198
export type QueryEngineBuildParams = {

0 commit comments

Comments
 (0)