Skip to content

Commit 8d21cb1

Browse files
[FIX] Fixes for v0.81.0 (#592)
* Fixes for v0.81.0 Signed-off-by: Deepak <89829542+Deepak-Kesavan@users.noreply.github.com> * Minor refactor Signed-off-by: Deepak <89829542+Deepak-Kesavan@users.noreply.github.com> * Improvements in the code Signed-off-by: Deepak <89829542+Deepak-Kesavan@users.noreply.github.com> --------- Signed-off-by: Deepak <89829542+Deepak-Kesavan@users.noreply.github.com>
1 parent 830e563 commit 8d21cb1

10 files changed

Lines changed: 51 additions & 36 deletions

File tree

backend/api/api_deployment_views.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,28 @@ def get(
7474
self, request: Request, org_name: str, api_name: str, api: APIDeployment
7575
) -> Response:
7676
execution_id = request.query_params.get("execution_id")
77-
include_metadata = request.query_params.get("include_metadata", False)
77+
include_metadata = (
78+
request.query_params.get(ApiExecution.INCLUDE_METADATA, "false").lower()
79+
== "true"
80+
)
7881
if not execution_id:
7982
raise InvalidAPIRequest("execution_id shouldn't be empty")
8083
response: ExecutionResponse = DeploymentHelper.get_execution_status(
8184
execution_id=execution_id
8285
)
83-
if response.execution_status != CeleryTaskState.SUCCESS.value:
84-
return Response(
85-
{
86-
"status": response.execution_status,
87-
"message": response.result,
88-
},
89-
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
90-
)
91-
if (
92-
response.execution_status == CeleryTaskState.SUCCESS.value
93-
and not include_metadata
94-
):
95-
response.remove_result_metadata_keys()
86+
response_status = status.HTTP_422_UNPROCESSABLE_ENTITY
87+
if response.execution_status == CeleryTaskState.COMPLETED.value:
88+
response_status = status.HTTP_200_OK
89+
if include_metadata:
90+
response.remove_result_metadata_keys(keys_to_remove=["highlight_data"])
91+
else:
92+
response.remove_result_metadata_keys()
9693
return Response(
97-
{"status": response.execution_status, "message": response.result},
98-
status=status.HTTP_200_OK,
94+
data={
95+
"status": response.execution_status,
96+
"message": response.result,
97+
},
98+
status=response_status,
9999
)
100100

101101

backend/api/deployment_helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def execute_workflow(
178178
result.status_api = DeploymentHelper.construct_status_endpoint(
179179
api_endpoint=api.api_endpoint, execution_id=execution_id
180180
)
181-
if not include_metadata:
181+
if include_metadata:
182+
result.remove_result_metadata_keys(keys_to_remove=["highlight_data"])
183+
else:
182184
result.remove_result_metadata_keys()
183-
cls._send_notification(api=api, result=result)
184185
except Exception as error:
185186
DestinationConnector.delete_api_storage_dir(
186187
workflow_id=workflow_id, execution_id=execution_id

backend/api/postman_collection/dto.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def get_api_endpoint(self) -> str:
136136

137137
def _get_status_api_request(self) -> RequestItem:
138138
header_list = [HeaderItem(key="Authorization", value=f"Bearer {self.api_key}")]
139-
status_query_param = {"execution_id": CollectionKey.STATUS_EXEC_ID_DEFAULT}
139+
status_query_param = {
140+
"execution_id": CollectionKey.STATUS_EXEC_ID_DEFAULT,
141+
ApiExecution.INCLUDE_METADATA: "False",
142+
}
140143
status_query_str = urlencode(status_query_param)
141144
abs_api_endpoint = urljoin(settings.WEB_APP_ORIGIN_URL, self.api_endpoint)
142145
status_url = urljoin(abs_api_endpoint, "?" + status_query_str)

backend/prompt_studio/prompt_studio_core/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ToolStudioPromptKeys:
8989
METADATA = "metadata"
9090
INCLUDE_METADATA = "include_metadata"
9191
PLATFORM_POSTAMBLE = "platform_postamble"
92+
SUMMARIZE_AS_SOURCE = "summarize_as_source"
9293

9394

9495
class FileViewTypes:

backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
IndexingAPIError,
3030
NoPromptsFound,
3131
PermissionError,
32-
ToolNotValid,
3332
)
3433
from prompt_studio.prompt_studio_core.models import CustomTool
3534
from prompt_studio.prompt_studio_core.prompt_ide_base_tool import PromptIdeBaseTool
@@ -324,10 +323,6 @@ def index_document(
324323
)
325324
file_path = str(Path(file_path) / file_name)
326325

327-
if not tool:
328-
logger.error(f"No tool instance found for the ID {tool_id}")
329-
raise ToolNotValid()
330-
331326
logger.info(f"[{tool_id}] Indexing started for doc: {file_name}")
332327
PromptStudioHelper._publish_log(
333328
{"tool_id": tool_id, "run_id": run_id, "doc_name": file_name},
@@ -751,6 +746,7 @@ def _fetch_response(
751746
tool_settings[TSPKeys.SINGLE_PASS_EXTRACTION_MODE] = (
752747
tool.single_pass_extraction_mode
753748
)
749+
tool_settings[TSPKeys.SUMMARIZE_AS_SOURCE] = tool.summarize_as_source
754750
tool_settings[TSPKeys.PREAMBLE] = tool.preamble
755751
tool_settings[TSPKeys.POSTAMBLE] = tool.postamble
756752
tool_settings[TSPKeys.GRAMMAR] = grammar_list

backend/utils/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ class CeleryTaskState(Enum):
99
REVOKED = "REVOKED"
1010
STARTED = "STARTED"
1111
SUCCESS = "SUCCESS"
12+
COMPLETED = "COMPLETED"

frontend/src/components/deployments/display-code/DisplayCode.jsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ import CodeSnippet from "./CodeSnippet.jsx";
88
import "./DisplayCode.css";
99

1010
const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
11-
const handleCloseDialog = () => {
12-
setDialogOpen(false);
13-
};
1411
const [copied, setCopied] = useState(false);
1512
const [language, setLanguage] = useState("python");
1613
const [code, setCode] = useState("");
1714
const [activeTabKey, setActiveTabKey] = useState("POST");
15+
const params =
16+
"?execution_id=REPLACE_WITH_EXECUTION_ID&include_metadata=False";
1817

19-
useEffect(() => {
20-
generateCode();
21-
}, [url, language, activeTabKey]);
18+
const handleCloseDialog = () => {
19+
setDialogOpen(false);
20+
};
2221

2322
const generateCode = () => {
2423
if (language === "python") {
@@ -51,7 +50,7 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
5150
files=[('files',('file',open(filepath,'rb'),'application/octet-stream'))]
5251
response = requests.request("POST", api_url, headers=headers, data=payload, files=files)
5352
{{else}}
54-
api_url = '{{url}}?execution_id=REPLACE_WITH_EXECUTION_ID'
53+
api_url = '{{url}}{{{params}}}'
5554
headers = {
5655
'Authorization': 'Bearer REPLACE_WITH_API_KEY'
5756
}
@@ -62,7 +61,11 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
6261
code = trimIndent(code);
6362
const template = Handlebars.compile(code);
6463

65-
const pythonCode = template({ url, isPost: activeTabKey === "POST" });
64+
const pythonCode = template({
65+
url,
66+
params,
67+
isPost: activeTabKey === "POST",
68+
});
6669
setCode(pythonCode);
6770
};
6871

@@ -74,14 +77,15 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
7477
--form 'timeout=300' \\
7578
--form 'include_metadata=false'
7679
{{else}}
77-
curl --location '{{url}}?execution_id=REPLACE_WITH_EXECUTION_ID' \\
80+
curl --location '{{url}}{{{params}}}' \\
7881
--header 'Authorization: Bearer REPLACE_WITH_API_KEY'
7982
{{/if}}
8083
`;
8184
code = trimIndent(code);
8285
const template = Handlebars.compile(code);
8386
const curlCode = template({
8487
url,
88+
params,
8589
isPost: activeTabKey === "POST",
8690
pathToFile: "/path/to/file",
8791
});
@@ -100,7 +104,7 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
100104
fetch("{{url}}", requestOptions)
101105
{{else}}
102106
var requestOptions = { method: 'GET', redirect: 'follow', headers: myHeaders};
103-
fetch("{{url}}?execution_id=REPLACE_WITH_EXECUTION_ID", requestOptions)
107+
fetch("{{url}}{{{params}}}", requestOptions)
104108
{{/if}}
105109
.then(response => response.text())
106110
.then(result => console.log(result))
@@ -109,7 +113,7 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
109113
code = trimIndent(code);
110114
const template = Handlebars.compile(code);
111115

112-
const jsCode = template({ url, isPost: activeTabKey === "POST" });
116+
const jsCode = template({ url, params, isPost: activeTabKey === "POST" });
113117
setCode(jsCode);
114118
};
115119

@@ -155,6 +159,10 @@ const DisplayCode = ({ isDialogOpen, setDialogOpen, url }) => {
155159
},
156160
];
157161

162+
useEffect(() => {
163+
generateCode();
164+
}, [url, language, activeTabKey]);
165+
158166
return (
159167
<Modal
160168
title="Code Snippets"

prompt-service/src/unstract/prompt_service/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class PromptServiceContants:
6262
PLATFORM_POSTAMBLE = "platform_postamble"
6363
EXTRACT_EPILOGUE = "extract-epilogue"
6464
CLEAN_CONTEXT = "clean-context"
65+
SUMMARIZE_AS_SOURCE = "summarize_as_source"
6566

6667

6768
class LogLevel(Enum):

prompt-service/src/unstract/prompt_service/helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,16 @@ def construct_and_run_prompt(
212212
prompt: str,
213213
metadata: dict[str, Any],
214214
) -> str:
215+
platform_postamble = tool_settings.get(PSKeys.PLATFORM_POSTAMBLE, "")
216+
if tool_settings.get(PSKeys.SUMMARIZE_AS_SOURCE):
217+
platform_postamble = ""
215218
prompt = construct_prompt(
216219
preamble=tool_settings.get(PSKeys.PREAMBLE, ""),
217220
prompt=output[prompt],
218221
postamble=tool_settings.get(PSKeys.POSTAMBLE, ""),
219222
grammar_list=tool_settings.get(PSKeys.GRAMMAR, []),
220223
context=context,
221-
platform_postamble=tool_settings.get(PSKeys.PLATFORM_POSTAMBLE, ""),
224+
platform_postamble=platform_postamble,
222225
)
223226
return run_completion(
224227
llm=llm,

tools/structure/src/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def run(
6363
tool_settings[SettingsKeys.ENABLE_SINGLE_PASS_EXTRACTION] = (
6464
single_pass_extraction_mode
6565
)
66+
tool_settings[SettingsKeys.SUMMARIZE_AS_SOURCE] = summarize_as_source
6667

6768
prompt_service_resp = None
6869
_, file_name = os.path.split(input_file)

0 commit comments

Comments
 (0)