Skip to content

Commit 902f71e

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'update_llm_models' into 'master'
Assistant UI: Switch to bot_llm_models API endpoint See merge request postgres-ai/database-lab!946
2 parents f6c2887 + cc1fdc0 commit 902f71e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

ui/packages/platform/src/api/bot/getAiModels.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import {request} from "../../helpers/request";
22
import { AiModel } from "../../types/api/entities/bot";
33

4-
export const getAiModels = async (): Promise<{ response: AiModel[] | null; error: Response | null }> => {
4+
export const getAiModels = async (orgId?: number): Promise<{ response: AiModel[] | null; error: Response | null }> => {
55
const apiServer = process.env.REACT_APP_API_URL_PREFIX || '';
6-
6+
const body = {
7+
org_id: orgId
8+
}
79
try {
8-
const response = await request(`${apiServer}/llm_models`, {
9-
method: 'GET',
10+
const response = await request(`${apiServer}/rpc/bot_llm_models`, {
11+
method: 'POST',
12+
body: JSON.stringify(body),
13+
headers: {
14+
'Accept': 'application/vnd.pgrst.object+json',
15+
'Prefer': 'return=representation',
16+
}
1017
});
1118

1219
if (!response.ok) {
1320
return { response: null, error: response };
1421
}
1522

16-
const responseData: AiModel[] = await response.json();
23+
const responseData: { bot_llm_models: AiModel[] | null } = await response.json();
1724

18-
return { response: responseData, error: null };
25+
return { response: responseData?.bot_llm_models, error: null };
1926

2027
} catch (error) {
2128
return { response: null, error: error as Response };

ui/packages/platform/src/pages/Bot/hooks.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const useAiBotProviderValue = (args: UseAiBotArgs): UseAiBotReturnType =>
8989
aiModel,
9090
setAiModel,
9191
loading: aiModelsLoading
92-
} = useAiModelsList();
92+
} = useAiModelsList(orgId);
9393
let location = useLocation<{skipReloading?: boolean}>();
9494

9595
const {
@@ -567,7 +567,7 @@ type UseAiModelsList = {
567567
setAiModel: (model: AiModel) => void
568568
}
569569

570-
export const useAiModelsList = (): UseAiModelsList => {
570+
export const useAiModelsList = (orgId?: number): UseAiModelsList => {
571571
const [llmModels, setLLMModels] = useState<UseAiModelsList['aiModels']>(null);
572572
const [error, setError] = useState<Response | null>(null);
573573
const [userModel, setUserModel] = useState<AiModel | null>(null);
@@ -577,7 +577,7 @@ export const useAiModelsList = (): UseAiModelsList => {
577577
let models = null;
578578
setLoading(true);
579579
try {
580-
const { response } = await getAiModels();
580+
const { response } = await getAiModels(orgId);
581581
setLLMModels(response);
582582
const currentModel = window.localStorage.getItem('bot.ai_model');
583583
const parsedModel: AiModel = currentModel ? JSON.parse(currentModel) : null;

0 commit comments

Comments
 (0)