Skip to content

Commit

Permalink
Integration of the transform formdata function for LLMW Paid Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
tahierhussain committed Jan 30, 2025
1 parent 10f48e0 commit b9be01e
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions frontend/src/components/input-output/add-source/AddSource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let transformLlmWhispererJsonSchema;
let LLMW_V2_ID;
let PLAN_TYPES;
let unstractSubscriptionPlanStore;
let useLlmWhipererAdapterSchema;
try {
transformLlmWhispererJsonSchema =
require("../../../plugins/unstract-subscription/helper/transformLlmWhispererJsonSchema").transformLlmWhispererJsonSchema;
Expand All @@ -22,6 +23,8 @@ try {
PLAN_TYPES =
require("../../../plugins/unstract-subscription/helper/constants").PLAN_TYPES;
unstractSubscriptionPlanStore = require("../../../plugins/store/unstract-subscription-plan-store");
useLlmWhipererAdapterSchema =
require("../../../plugins/unstract-subscription/hooks/useLlmWhispererAdapterSchema.js").useLlmWhipererAdapterSchema;
} catch (err) {
// Ignore if not available
}
Expand All @@ -47,6 +50,15 @@ function AddSource({
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();
const [isLLMWPaidSchema, setIsLLMWPaidSchema] = useState(false);

let transformLlmWhispererFormData;
try {
transformLlmWhispererFormData =
useLlmWhipererAdapterSchema()?.transformLlmWhispererFormData;
} catch {
// Ignore if not available
}

let planType;
if (unstractSubscriptionPlanStore?.useUnstractSubscriptionPlanStore) {
Expand All @@ -55,6 +67,32 @@ function AddSource({
);
}

useEffect(() => {
setIsLLMWPaidSchema(
LLMW_V2_ID &&
transformLlmWhispererJsonSchema &&
PLAN_TYPES &&
selectedSourceId === LLMW_V2_ID &&
planType === PLAN_TYPES?.PAID
);
}, [
LLMW_V2_ID,
transformLlmWhispererJsonSchema,
PLAN_TYPES,
selectedSourceId,
planType,
]);

useEffect(() => {
if (!isLLMWPaidSchema || !transformLlmWhispererFormData) return;

const modifiedFormData = transformLlmWhispererFormData(formData);

if (JSON.stringify(modifiedFormData) !== JSON.stringify(formData)) {
setFormData(modifiedFormData);
}
}, [isLLMWPaidSchema, formData]);

useEffect(() => {
if (!selectedSourceId) {
setSpec({});
Expand All @@ -80,13 +118,7 @@ function AddSource({
const data = res?.data;
setFormData(metadata || {});

if (
LLMW_V2_ID &&
transformLlmWhispererJsonSchema &&
PLAN_TYPES &&
selectedSourceId === LLMW_V2_ID &&
planType === PLAN_TYPES?.PAID
) {
if (isLLMWPaidSchema) {
setSpec(transformLlmWhispererJsonSchema(data?.json_schema || {}));
} else {
setSpec(data?.json_schema || {});
Expand Down

0 comments on commit b9be01e

Please sign in to comment.