@@ -25,32 +25,52 @@ def __init__(
2525 tool (AbstractTool): Instance of AbstractTool
2626 prompt_host (str): Host of platform service
2727 prompt_host (str): Port of platform service
28-
2928 """
3029 self .tool = tool
3130 self .base_url = SdkHelper .get_platform_base_url (prompt_host , prompt_port )
3231 self .bearer_token = tool .get_env_or_die (ToolEnv .PLATFORM_API_KEY )
3332
34- def answer_prompt (self , payload : dict [str , Any ]) -> dict [str , Any ]:
35- return self ._post_call ("answer-prompt" , payload )
36-
37- def single_pass_extraction (self , payload : dict [str , Any ]) -> dict [str , Any ]:
38- return self ._post_call ("single-pass-extraction" , payload )
39-
40- def summarize (self , payload : dict [str , Any ]) -> dict [str , Any ]:
41- return self ._post_call ("summarize" , payload )
42-
43- def _post_call (self , url_path : str , payload : dict [str , Any ]) -> dict [str , Any ]:
33+ def answer_prompt (
34+ self , payload : dict [str , Any ], params : Optional [dict [str , str ]] = None
35+ ) -> dict [str , Any ]:
36+ return self ._post_call (
37+ url_path = "answer-prompt" ,
38+ payload = payload ,
39+ params = params ,
40+ )
41+
42+ def single_pass_extraction (
43+ self , payload : dict [str , Any ], params : Optional [dict [str , str ]] = None
44+ ) -> dict [str , Any ]:
45+ return self ._post_call (
46+ url_path = "single-pass-extraction" ,
47+ payload = payload ,
48+ params = params ,
49+ )
50+
51+ def summarize (
52+ self , payload : dict [str , Any ], params : Optional [dict [str , str ]] = None
53+ ) -> dict [str , Any ]:
54+ return self ._post_call (url_path = "summarize" , payload = payload , params = params )
55+
56+ def _post_call (
57+ self ,
58+ url_path : str ,
59+ payload : dict [str , Any ],
60+ params : Optional [dict [str , str ]] = None ,
61+ ) -> dict [str , Any ]:
4462 """Invokes and communicates to prompt service to fetch response for the
4563 prompt.
4664
4765 Args:
48- file_name (str): File in which the prompt is processed
49- outputs (dict): dict of all input data for the tool
50- tool_id (str ): Unique ID of the tool to be processed
66+ url_path (str): URL path to the service endpoint
67+ payload (dict): Payload to send in the request body
68+ params (dict, optional ): Query parameters to include in the request
5169
5270 Returns:
53- Sample return dict:
71+ dict: Response from the prompt service
72+
73+ Sample Response:
5474 {
5575 "status": "OK",
5676 "error": "",
@@ -68,7 +88,12 @@ def _post_call(self, url_path: str, payload: dict[str, Any]) -> dict[str, Any]:
6888 headers : dict [str , str ] = {"Authorization" : f"Bearer { self .bearer_token } " }
6989 response : Response = Response ()
7090 try :
71- response = requests .post (url , json = payload , headers = headers )
91+ response = requests .post (
92+ url = url ,
93+ json = payload ,
94+ headers = headers ,
95+ params = params ,
96+ )
7297 response .raise_for_status ()
7398 result ["status" ] = "OK"
7499 result ["structure_output" ] = response .text
0 commit comments