Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Prompt Studio Public Share & Clone #429

Merged
merged 45 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d6a104b
Cloud URLs for public share
harini-venkataraman Jun 28, 2024
960cfaf
Adding public share cloud routes
harini-venkataraman Jun 28, 2024
6495537
Public share OSS components
harini-venkataraman Jun 28, 2024
e0a23fc
Fixing linting issues
harini-venkataraman Jul 1, 2024
1e14d82
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 1, 2024
18e5a48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 1, 2024
c25e72d
Import fixes
harini-venkataraman Jul 1, 2024
102ff8c
Fixing path for FE Plugins
harini-venkataraman Jul 2, 2024
3081c82
Exposing URLs
harini-venkataraman Jul 2, 2024
85585ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 2, 2024
8590e60
Sonar issue fixes
harini-venkataraman Jul 2, 2024
7edd2d6
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 2, 2024
54932da
Fixing prettier issues
harini-venkataraman Jul 2, 2024
117eb22
Fixing prettier issues
harini-venkataraman Jul 2, 2024
14335cd
Resolving conflicts with SPS
harini-venkataraman Jul 4, 2024
12793cc
Removing console logs
harini-venkataraman Jul 4, 2024
19ef95a
Optimising code block
harini-venkataraman Jul 4, 2024
e62cf9d
Fixing Cloud Import URLs
harini-venkataraman Jul 4, 2024
d026af9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
c153458
Seperating clone and Share components
harini-venkataraman Jul 4, 2024
0dc7eb0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
fc09b7b
Resolving conflicts
harini-venkataraman Jul 4, 2024
7feceac
Moving URLs to Cloud
harini-venkataraman Jul 4, 2024
d237a8e
Fixing headers
harini-venkataraman Jul 4, 2024
0e2fa74
Fixing linting issues
harini-venkataraman Jul 4, 2024
6be46a7
Resolving multi llm conflicts
harini-venkataraman Jul 8, 2024
53d0649
Disabling Multi LLM runs for Public sharing
harini-venkataraman Jul 8, 2024
603b2d3
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 8, 2024
931eb58
Adding URLs
harini-venkataraman Jul 8, 2024
f6df10c
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 8, 2024
827b582
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2024
53b75c2
Pre-commit fixes
harini-venkataraman Jul 8, 2024
eee2486
Adding prompt studio helper
harini-venkataraman Jul 10, 2024
39c2ea8
Resolving conflicts
harini-venkataraman Jul 11, 2024
415327c
Condition optimization
harini-venkataraman Jul 11, 2024
e097f64
Adapter null fixes
harini-venkataraman Jul 11, 2024
45219d3
Fixing prompt_id key
harini-venkataraman Jul 11, 2024
051f963
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 11, 2024
b1be8ba
Linting issues
harini-venkataraman Jul 11, 2024
5032a28
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 11, 2024
a3d23b5
Disabling checkboxes
harini-venkataraman Jul 11, 2024
0fc7589
Merge branch 'main' into feat/public-share-oss
harini-venkataraman Jul 11, 2024
63e21a8
Fixing sonar issues
harini-venkataraman Jul 11, 2024
c9c4530
Merge branch 'main' into feat/public-share-oss
hari-kuriakose Jul 12, 2024
f00fb3d
Merge branch 'main' into feat/public-share-oss
hari-kuriakose Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -968,3 +968,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 @@ -135,7 +135,6 @@ function CombinedOutput({ docId, setFilledFields }) {
"X-CSRFToken": sessionDetails?.csrfToken,
},
};

return axiosPrivate(requestOptions)
.then((res) => res)
.catch((err) => {
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 };
63 changes: 36 additions & 27 deletions frontend/src/components/custom-tools/header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
ArrowLeftOutlined,
EditOutlined,
SettingOutlined,
} from "@ant-design/icons";
import { SettingOutlined } from "@ant-design/icons";
import { Button, Tooltip, Typography } from "antd";
import PropTypes from "prop-types";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import "./Header.css";

import { HeaderTitle } from "../header-title/HeaderTitle.jsx";
import { ExportToolIcon } from "../../../assets";
import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
Expand All @@ -18,21 +13,36 @@ import { useSessionStore } from "../../../store/session-store";
import { CustomButton } from "../../widgets/custom-button/CustomButton";
import { ExportTool } from "../export-tool/ExportTool";
import usePostHogEvents from "../../../hooks/usePostHogEvents";
import "./Header.css";

let SinglePassToggleSwitch;
let CloneButton;
let PromptShareButton;
try {
SinglePassToggleSwitch =
require("../../../plugins/single-pass-toggle-switch/SinglePassToggleSwitch").SinglePassToggleSwitch;
} catch {
// The variable will remain undefined if the component is not available.
}
function Header({ setOpenSettings, handleUpdateTool }) {
try {
PromptShareButton =
require("../../../plugins/prompt-studio-public-share/public-share-btn/PromptShareButton.jsx").PromptShareButton;
CloneButton =
require("../../../plugins/prompt-studio-clone/clone-btn/CloneButton.jsx").CloneButton;
} catch {
// The variable will remain undefined if the component is not available.
}
function Header({
setOpenSettings,
handleUpdateTool,
setOpenShareModal,
setOpenCloneModal,
}) {
const [isExportLoading, setIsExportLoading] = useState(false);
const { details } = useCustomToolStore();
const { details, isPublicSource } = useCustomToolStore();
const { sessionDetails } = useSessionStore();
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const navigate = useNavigate();
const handleException = useExceptionHandler();
const [userList, setUserList] = useState([]);
const [openExportToolModal, setOpenExportToolModal] = useState(false);
Expand Down Expand Up @@ -138,23 +148,15 @@ function Header({ setOpenSettings, handleUpdateTool }) {

return (
<div className="custom-tools-header-layout">
<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>
</div>
<div>
<Button size="small" type="text" disabled>
<EditOutlined />
</Button>
</div>
{isPublicSource ? (
<div>
<Typography.Text className="custom-tools-name" strong>
{details?.tool_name}
</Typography.Text>
</div>
) : (
<HeaderTitle />
)}
<div className="custom-tools-header-btns">
{SinglePassToggleSwitch && (
<SinglePassToggleSwitch handleUpdateTool={handleUpdateTool} />
Expand All @@ -167,13 +169,18 @@ function Header({ setOpenSettings, handleUpdateTool }) {
/>
</Tooltip>
</div>
{CloneButton && <CloneButton setOpenCloneModal={setOpenCloneModal} />}
{PromptShareButton && (
<PromptShareButton setOpenShareModal={setOpenShareModal} />
)}
<div className="custom-tools-header-v-divider" />
<div>
<Tooltip title="Export as tool">
<CustomButton
type="primary"
onClick={() => handleShare(true)}
loading={isExportLoading}
disabled={isPublicSource}
>
<ExportToolIcon />
</CustomButton>
Expand All @@ -195,6 +202,8 @@ function Header({ setOpenSettings, handleUpdateTool }) {
Header.propTypes = {
setOpenSettings: PropTypes.func.isRequired,
handleUpdateTool: PropTypes.func.isRequired,
setOpenCloneModal: PropTypes.func.isRequired,
setOpenShareModal: PropTypes.func.isRequired,
};

export { Header };
Loading
Loading