Skip to content

Commit

Permalink
Merge branch 'update_llm_models' into 'master'
Browse files Browse the repository at this point in the history
Assistant UI: Switch to bot_llm_models API endpoint

See merge request postgres-ai/database-lab!946
  • Loading branch information
Bogdan Tsechoev committed Dec 20, 2024
2 parents f6c2887 + cc1fdc0 commit 902f71e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 13 additions & 6 deletions ui/packages/platform/src/api/bot/getAiModels.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import {request} from "../../helpers/request";
import { AiModel } from "../../types/api/entities/bot";

export const getAiModels = async (): Promise<{ response: AiModel[] | null; error: Response | null }> => {
export const getAiModels = async (orgId?: number): Promise<{ response: AiModel[] | null; error: Response | null }> => {
const apiServer = process.env.REACT_APP_API_URL_PREFIX || '';

const body = {
org_id: orgId
}
try {
const response = await request(`${apiServer}/llm_models`, {
method: 'GET',
const response = await request(`${apiServer}/rpc/bot_llm_models`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Accept': 'application/vnd.pgrst.object+json',
'Prefer': 'return=representation',
}
});

if (!response.ok) {
return { response: null, error: response };
}

const responseData: AiModel[] = await response.json();
const responseData: { bot_llm_models: AiModel[] | null } = await response.json();

return { response: responseData, error: null };
return { response: responseData?.bot_llm_models, error: null };

} catch (error) {
return { response: null, error: error as Response };
Expand Down
6 changes: 3 additions & 3 deletions ui/packages/platform/src/pages/Bot/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const useAiBotProviderValue = (args: UseAiBotArgs): UseAiBotReturnType =>
aiModel,
setAiModel,
loading: aiModelsLoading
} = useAiModelsList();
} = useAiModelsList(orgId);
let location = useLocation<{skipReloading?: boolean}>();

const {
Expand Down Expand Up @@ -567,7 +567,7 @@ type UseAiModelsList = {
setAiModel: (model: AiModel) => void
}

export const useAiModelsList = (): UseAiModelsList => {
export const useAiModelsList = (orgId?: number): UseAiModelsList => {
const [llmModels, setLLMModels] = useState<UseAiModelsList['aiModels']>(null);
const [error, setError] = useState<Response | null>(null);
const [userModel, setUserModel] = useState<AiModel | null>(null);
Expand All @@ -577,7 +577,7 @@ export const useAiModelsList = (): UseAiModelsList => {
let models = null;
setLoading(true);
try {
const { response } = await getAiModels();
const { response } = await getAiModels(orgId);
setLLMModels(response);
const currentModel = window.localStorage.getItem('bot.ai_model');
const parsedModel: AiModel = currentModel ? JSON.parse(currentModel) : null;
Expand Down

0 comments on commit 902f71e

Please sign in to comment.