Skip to content

Commit

Permalink
Removed onload patch call in prompt studio (#475)
Browse files Browse the repository at this point in the history
* removed patch call onload prompt studio

* code clean  up

---------

Co-authored-by: Deepak K <[email protected]>
  • Loading branch information
jagadeeswaran-zipstack and Deepak-Kesavan authored Jul 11, 2024
1 parent 0af6784 commit edaac16
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
10 changes: 2 additions & 8 deletions frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ function PromptCard({
if (isSinglePassExtractLoading) {
return;
}
if (selectedLlmProfileId !== promptDetails?.profile_id) {
handleChange(
selectedLlmProfileId,
promptDetails?.prompt_id,
"profile_manager"
);
}
}, [
selectedLlmProfileId,
selectedDoc,
Expand Down Expand Up @@ -173,7 +166,7 @@ function PromptCard({

useEffect(() => {
const isProfilePresent = llmProfiles?.some(
(profile) => profile?.profile_id === selectedLlmProfileId
(profile) => profile?.profile_id === defaultLlmProfile
);

// If selectedLlmProfileId is not present, set it to null
Expand All @@ -192,6 +185,7 @@ function PromptCard({

const handleSelectDefaultLLM = (llmProfileId) => {
setSelectedLlmProfileId(llmProfileId);
handleChange(llmProfileId, promptDetails?.prompt_id, "profile_manager");
};

const handleTypeChange = (value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ import { TokenUsage } from "../token-usage/TokenUsage";
import { useCustomToolStore } from "../../../store/custom-tool-store";
import { Header } from "./Header";
import CheckableTag from "antd/es/tag/CheckableTag";
import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
import { useSessionStore } from "../../../store/session-store";
import { motion, AnimatePresence } from "framer-motion";
import { OutputForIndex } from "./OutputForIndex";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
import { useAlertStore } from "../../../store/alert-store";
import { useWindowDimensions } from "../../../hooks/useWindowDimensions";

const EvalBtn = null;
Expand Down Expand Up @@ -80,6 +76,7 @@ function PromptCardItems({
isSinglePassExtractLoading,
indexDocs,
isSimplePromptStudio,
adapters,
} = useCustomToolStore();
const [isEditingPrompt, setIsEditingPrompt] = useState(false);
const [isEditingTitle, setIsEditingTitle] = useState(false);
Expand All @@ -91,11 +88,7 @@ function PromptCardItems({
);
const [expandedProfiles, setExpandedProfiles] = useState([]); // New state for expanded profiles
const [isIndexOpen, setIsIndexOpen] = useState(false);
const privateAxios = useAxiosPrivate();
const { sessionDetails } = useSessionStore();
const { width: windowWidth } = useWindowDimensions();
const handleException = useExceptionHandler();
const { setAlertDetails } = useAlertStore();
const componentWidth = windowWidth * 0.4;

const divRef = useRef(null);
Expand Down Expand Up @@ -123,35 +116,26 @@ function PromptCardItems({
return result;
};

const getAdapterInfo = async () => {
privateAxios
.get(`/api/v1/unstract/${sessionDetails?.orgId}/adapter/`)
.then((res) => {
const adapterData = res?.data;

// Update llmProfiles with additional fields
const updatedProfiles = llmProfiles?.map((profile) => {
return { ...getModelOrAdapterId(profile, adapterData), ...profile };
});
setLlmProfileDetails(
updatedProfiles
.map((profile) => ({
...profile,
isDefault: profile?.profile_id === selectedLlmProfileId,
isEnabled: enabledProfiles.includes(profile?.profile_id),
}))
.sort((a, b) => {
if (a?.isDefault) return -1; // Default profile comes first
if (b?.isDefault) return 1;
if (a?.isEnabled && !b?.isEnabled) return -1; // Enabled profiles come before disabled
if (!a?.isEnabled && b?.isEnabled) return 1;
return 0;
})
);
})
.catch((err) => {
setAlertDetails(handleException(err));
});
const getAdapterInfo = async (adapterData) => {
// Update llmProfiles with additional fields
const updatedProfiles = llmProfiles?.map((profile) => {
return { ...getModelOrAdapterId(profile, adapterData), ...profile };
});
setLlmProfileDetails(
updatedProfiles
.map((profile) => ({
...profile,
isDefault: profile?.profile_id === selectedLlmProfileId,
isEnabled: enabledProfiles.includes(profile?.profile_id),
}))
.sort((a, b) => {
if (a?.isDefault) return -1; // Default profile comes first
if (b?.isDefault) return 1;
if (a?.isEnabled && !b?.isEnabled) return -1; // Enabled profiles come before disabled
if (!a?.isEnabled && b?.isEnabled) return 1;
return 0;
})
);
};

const tooltipContent = (adapterConf) => (
Expand Down Expand Up @@ -247,7 +231,7 @@ function PromptCardItems({
}, [singlePassExtractMode]);

useEffect(() => {
getAdapterInfo();
getAdapterInfo(adapters);
}, [llmProfiles, selectedLlmProfileId, enabledProfiles]);
return (
<Card className="prompt-card">
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/components/helpers/custom-tools/CustomToolsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function CustomToolsHelper() {
defaultLlmProfile: "",
llmProfiles: [],
selectedDoc: null,
adapters: [],
};

const reqOpsPromptStudio = {
Expand Down Expand Up @@ -81,6 +82,16 @@ function CustomToolsHelper() {
.then((res) => {
const data = res?.data;
updatedCusTool["llmProfiles"] = data;
const reqOpsLlmProfiles = {
method: "GET",
url: `/api/v1/unstract/${sessionDetails?.orgId}/adapter/`,
};

return handleApiRequest(reqOpsLlmProfiles);
})
.then((res) => {
const data = res?.data;
updatedCusTool["adapters"] = data;
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to load the custom tool"));
Expand Down
1 change: 1 addition & 0 deletions frontend/src/store/custom-tool-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const defaultState = {
singlePassExtractMode: false,
isSinglePassExtractLoading: false,
isSimplePromptStudio: false,
adapters: [],
};

const defaultPromptInstance = {
Expand Down

0 comments on commit edaac16

Please sign in to comment.