Skip to content

Commit

Permalink
FIX: Modifications to Plugin Integrations Related to the LLM Whispere…
Browse files Browse the repository at this point in the history
…r Adapter (#1105)

* Integration of the transform formdata function for LLMW Paid Adapter

* Fixed sonar issue

* Code optimization in declaring  variable
  • Loading branch information
tahierhussain authored Jan 31, 2025
1 parent 33978af commit 27e3330
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions frontend/src/components/input-output/add-source/AddSource.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Typography } from "antd";
import PropTypes from "prop-types";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";

import { sourceTypes } from "../../../helpers/GetStaticData";
import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
Expand All @@ -14,6 +14,7 @@ let transformLlmWhispererJsonSchema;
let LLMW_V2_ID;
let PLAN_TYPES;
let unstractSubscriptionPlanStore;
let llmWhipererAdapterSchema;
try {
transformLlmWhispererJsonSchema =
require("../../../plugins/unstract-subscription/helper/transformLlmWhispererJsonSchema").transformLlmWhispererJsonSchema;
Expand All @@ -22,6 +23,7 @@ try {
PLAN_TYPES =
require("../../../plugins/unstract-subscription/helper/constants").PLAN_TYPES;
unstractSubscriptionPlanStore = require("../../../plugins/store/unstract-subscription-plan-store");
llmWhipererAdapterSchema = require("../../../plugins/unstract-subscription/hooks/useLlmWhispererAdapterSchema.js");
} catch (err) {
// Ignore if not available
}
Expand All @@ -48,13 +50,48 @@ function AddSource({
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();

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

let planType;
if (unstractSubscriptionPlanStore?.useUnstractSubscriptionPlanStore) {
planType = unstractSubscriptionPlanStore?.useUnstractSubscriptionPlanStore(
(state) => state?.unstractSubscriptionPlan?.planType
);
}

const isLLMWPaidSchema = useMemo(() => {
return (
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 +117,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 27e3330

Please sign in to comment.