Skip to content

Commit

Permalink
[FEAT] Prompt Studio Public Share & Clone (#429)
Browse files Browse the repository at this point in the history
* Cloud URLs for public share

* Adding public share cloud routes

* Public share OSS components

* Fixing linting issues

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Import fixes

* Fixing path for FE Plugins

* Exposing URLs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Sonar issue fixes

* Fixing prettier issues

* Fixing prettier issues

* Removing console logs

* Optimising code block

* Fixing Cloud Import URLs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Seperating clone and Share components

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolving conflicts

* Moving URLs to Cloud

* Fixing headers

* Fixing linting issues

* Disabling Multi LLM runs for Public sharing

* Adding URLs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Pre-commit fixes

* Adding prompt studio helper

* Resolving conflicts

* Condition optimization

Co-authored-by: jagadeeswaran-zipstack <[email protected]>
Signed-off-by: harini-venkataraman <[email protected]>

* Adapter null fixes

Signed-off-by: harini-venkataraman <[email protected]>

* Fixing prompt_id key

Signed-off-by: harini-venkataraman <[email protected]>

* Linting issues

* Disabling checkboxes

* Fixing sonar issues

---------

Signed-off-by: harini-venkataraman <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: jagadeeswaran-zipstack <[email protected]>
Co-authored-by: Hari John Kuriakose <[email protected]>
  • Loading branch information
4 people authored Jul 15, 2024
1 parent f88acbb commit 047aed2
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 74 deletions.
9 changes: 8 additions & 1 deletion backend/backend/public_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

path_prefix = settings.PATH_PREFIX
api_path_prefix = settings.API_DEPLOYMENT_PATH_PREFIX
share_path_prefix = settings.PUBLIC_PATH_PREFIX

urlpatterns = [
path(f"{path_prefix}/", include("account.urls")),
Expand All @@ -47,10 +48,16 @@


try:
import pluggable_apps.platform_admin.urls # noqa: F401
import pluggable_apps.platform_admin.urls # noqa # pylint: disable=unused-import
import pluggable_apps.public_shares_share_controller.urls # noqa # pylint: disable=unused-import

urlpatterns += [
path(f"{path_prefix}/", include("pluggable_apps.platform_admin.urls")),
# Public Sharing
path(
f"{share_path_prefix}/",
include("pluggable_apps.public_shares.share_controller.urls"),
),
]
except ImportError:
pass
26 changes: 24 additions & 2 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# Subscription urls
try:

import pluggable_apps.subscription.urls # noqa # pylint: disable=unused-import
import pluggable_apps.subscription.urls # noqa # pylint: disable=unused-import

urlpatterns += [
path("", include("pluggable_apps.subscription.urls")),
Expand All @@ -93,10 +93,32 @@
pass

try:
import pluggable_apps.manual_review.urls # noqa: F401
import pluggable_apps.manual_review.urls # noqa # pylint: disable=unused-import

urlpatterns += [
path("manual_review/", include("pluggable_apps.manual_review.urls")),
]
except ImportError:
pass

# Public share urls
try:

import pluggable_apps.public_shares.share_manager.urls # noqa # pylint: disable=unused-import

urlpatterns += [
path("", include("pluggable_apps.public_shares.share_manager.urls")),
]
except ImportError:
pass

# Clone urls
try:

import pluggable_apps.clone.urls # noqa # pylint: disable=unused-import

urlpatterns += [
path("", include("pluggable_apps.clone.urls")),
]
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,11 @@ def _fetch_single_pass_response(
)
output_response = json.loads(answer["structure_output"])
return output_response

@staticmethod
def get_tool_from_tool_id(tool_id: str) -> Optional[CustomTool]:
try:
tool: CustomTool = CustomTool.objects.get(tool_id=tool_id)
return tool
except CustomTool.DoesNotExist:
return None
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
import "./CombinedOutput.css";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
import { JsonView } from "./JsonView";
import { useParams } from "react-router-dom";

let TableView;
let promptOutputApiSps;
Expand All @@ -29,18 +30,30 @@ try {
} catch {
// The component will remain null of it is not available
}
let publicOutputsDocApi;
let publicAdapterApi;
try {
publicOutputsDocApi =
require("../../../plugins/prompt-studio-public-share/helpers/PublicShareAPIs").publicOutputsDocApi;
publicAdapterApi =
require("../../../plugins/prompt-studio-public-share/helpers/PublicShareAPIs").publicAdapterApi;
} catch {
// The component will remain null of it is not available
}
function CombinedOutput({ docId, setFilledFields }) {
const [combinedOutput, setCombinedOutput] = useState({});
const [isOutputLoading, setIsOutputLoading] = useState(false);
const [adapterData, setAdapterData] = useState([]);
const [activeKey, setActiveKey] = useState("0");
const { id } = useParams();
const {
details,
defaultLlmProfile,
singlePassExtractMode,
isSinglePassExtractLoading,
llmProfiles,
isSimplePromptStudio,
isPublicSource,
} = useCustomToolStore();
const { sessionDetails } = useSessionStore();
const { setAlertDetails } = useAlertStore();
Expand Down Expand Up @@ -119,6 +132,13 @@ function CombinedOutput({ docId, setFilledFields }) {
let url;
if (isSimplePromptStudio) {
url = promptOutputApiSps(details?.tool_id, null, docId);
} else if (isPublicSource) {
url = publicOutputsDocApi(
id,
docId,
selectedProfile || defaultLlmProfile,
singlePassExtractMode
);
} else {
url = `/api/v1/unstract/${
sessionDetails?.orgId
Expand All @@ -135,7 +155,6 @@ function CombinedOutput({ docId, setFilledFields }) {
"X-CSRFToken": sessionDetails?.csrfToken,
},
};

return axiosPrivate(requestOptions)
.then((res) => res)
.catch((err) => {
Expand All @@ -144,14 +163,14 @@ function CombinedOutput({ docId, setFilledFields }) {
};

const getAdapterInfo = () => {
axiosPrivate
.get(
`/api/v1/unstract/${sessionDetails?.orgId}/adapter/?adapter_type=LLM`
)
.then((res) => {
const adapterList = res?.data;
setAdapterData(getLLMModelNamesForProfiles(llmProfiles, adapterList));
});
let url = `/api/v1/unstract/${sessionDetails?.orgId}/adapter/?adapter_type=LLM`;
if (isPublicSource) {
url = publicAdapterApi(id, "LLM");
}
axiosPrivate.get(url).then((res) => {
const adapterList = res?.data;
setAdapterData(getLLMModelNamesForProfiles(llmProfiles, adapterList));
});
};

if (isOutputLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function JsonView({
<div className="combined-op-header">
<Tabs activeKey={activeKey} onChange={handleTabChange} moreIcon={<></>}>
<TabPane tab={<span>Default</span>} key={"0"}></TabPane>
{adapterData.map((adapter, index) => (
{[...(adapterData || [])].map((adapter, index) => (
<TabPane
tab={<span>{adapter.llm_model}</span>}
key={(index + 1)?.toString()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function CustomSynonyms() {
const [rows, setRows] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const { sessionDetails } = useSessionStore();
const { details, updateCustomTool } = useCustomToolStore();
const { details, updateCustomTool, isPublicSource } = useCustomToolStore();
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();
Expand Down Expand Up @@ -96,7 +96,7 @@ function CustomSynonyms() {
handleConfirm={() => handleDelete(index)}
content="The word, along with its corresponding synonyms, will be permanently deleted."
>
<Button size="small" type="text">
<Button size="small" disabled={isPublicSource} type="text">
<DeleteOutlined className="cus-syn-del" />
</Button>
</ConfirmModal>
Expand Down Expand Up @@ -213,6 +213,7 @@ function CustomSynonyms() {
type="primary"
icon={<PlusOutlined />}
onClick={handleAddRow}
disabled={isPublicSource}
>
Rows
</CustomButton>
Expand All @@ -223,6 +224,7 @@ function CustomSynonyms() {
type="primary"
onClick={handleSave}
loading={isLoading}
disabled={isPublicSource}
>
Save
</CustomButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ManageDocsModal } from "../manage-docs-modal/ManageDocsModal";
import { PdfViewer } from "../pdf-viewer/PdfViewer";
import { TextViewerPre } from "../text-viewer-pre/TextViewerPre";
import usePostHogEvents from "../../../hooks/usePostHogEvents";
import { useParams } from "react-router-dom";

const items = [
{
Expand Down Expand Up @@ -63,7 +64,13 @@ try {
} catch {
// The component will remain null of it is not available
}

let publicDocumentApi;
try {
publicDocumentApi =
require("../../../plugins/prompt-studio-public-share/helpers/PublicShareAPIs").publicDocumentApi;
} catch {
// The component will remain null of it is not available
}
function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
const [openManageDocsModal, setOpenManageDocsModal] = useState(false);
const [page, setPage] = useState(1);
Expand All @@ -85,10 +92,12 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
indexDocs,
isSinglePassExtractLoading,
isSimplePromptStudio,
isPublicSource,
} = useCustomToolStore();
const { sessionDetails } = useSessionStore();
const axiosPrivate = useAxiosPrivate();
const { setPostHogCustomEvent } = usePostHogEvents();
const { id } = useParams();

useEffect(() => {
if (isSimplePromptStudio) {
Expand Down Expand Up @@ -186,11 +195,14 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
};

const getDocuments = async (viewType) => {
let url = `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/file/${details?.tool_id}?document_id=${selectedDoc?.document_id}&view_type=${viewType}`;
if (isPublicSource) {
url = publicDocumentApi(id, selectedDoc?.document_id, viewType);
}
const requestOptions = {
url,
method: "GET",
url: `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/file/${details?.tool_id}?document_id=${selectedDoc?.document_id}&view_type=${viewType}`,
};

return axiosPrivate(requestOptions)
.then((res) => res)
.catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function EditableText({
indexDocs,
selectedDoc,
isSinglePassExtractLoading,
isPublicSource,
} = useCustomToolStore();

useEffect(() => {
Expand Down Expand Up @@ -90,7 +91,9 @@ function EditableText({
onBlur={handleBlur}
onClick={() => setIsEditing(true)}
disabled={
disableLlmOrDocChange.includes(promptId) || isSinglePassExtractLoading
disableLlmOrDocChange.includes(promptId) ||
isSinglePassExtractLoading ||
isPublicSource
}
/>
);
Expand All @@ -114,7 +117,8 @@ function EditableText({
disabled={
disableLlmOrDocChange.includes(promptId) ||
indexDocs.includes(selectedDoc?.document_id) ||
isSinglePassExtractLoading
isSinglePassExtractLoading ||
isPublicSource
}
/>
);
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/custom-tools/header-title/HeaderTitle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.custom-tools-name {
padding: 0px 8px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-left:auto;
}
.custom-tools-header {
display: flex;
justify-content: space-between;
margin-right: auto;
}
34 changes: 34 additions & 0 deletions frontend/src/components/custom-tools/header-title/HeaderTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ArrowLeftOutlined, EditOutlined } from "@ant-design/icons";
import { Button, Typography } from "antd";
import { useNavigate } from "react-router-dom";

import { useCustomToolStore } from "../../../store/custom-tool-store";
import { useSessionStore } from "../../../store/session-store";
import "./HeaderTitle.css";

function HeaderTitle() {
const navigate = useNavigate();
const { details } = useCustomToolStore();
const { sessionDetails } = useSessionStore();

return (
<div className="custom-tools-header">
<div>
<Button
size="small"
type="text"
onClick={() => navigate(`/${sessionDetails?.orgName}/tools`)}
>
<ArrowLeftOutlined />
</Button>
</div>
<div className="custom-tools-name">
<Typography.Text strong>{details?.tool_name}</Typography.Text>
<Button size="small" type="text" disabled>
<EditOutlined />
</Button>
</div>
</div>
);
}
export { HeaderTitle };
Loading

0 comments on commit 047aed2

Please sign in to comment.