66
77
88def _default_extractor (json_response : Dict [str , Any ], stop_parameter_name ) -> str :
9+ """
10+ This function extracts the response from the JSON object using the default parameter name.
11+
12+ Parameters:
13+ json_response (dict): The JSON response to be extracted.
14+ stop_parameter_name (str): The name of the parameter that stops the extraction process.
15+
16+ Returns:
17+ str: The extracted response.
18+ """
919 return json_response ["response" ]
1020
1121
@@ -75,6 +85,8 @@ def ui_default_parameters():
7585
7686
7787def _response_extractor (json_response , stopping_strings ):
88+ """Extract relevant information from the given JSON response."""
89+
7890 result = json_response ["results" ][0 ]["text" ]
7991 for stop_string in stopping_strings :
8092 # The stop strings from text-generation-webui come back without the last char
@@ -88,6 +100,19 @@ def _response_extractor(json_response, stopping_strings):
88100def build_text_generation_web_ui_client_llm (
89101 prompt_url = "http://0.0.0.0:5000/api/v1/generate" , parameters = None
90102):
103+ """
104+ This function builds a text generation web UI client using LLM (Largue Language Machine) API.
105+ It takes a URL for the LLM server and optional parameters as inputs.
106+ If parameters are not provided, default ones will be used. The function returns an HTTP client that can generate text based on user input.
107+
108+ Parameters:
109+ prompt_url (str): URL of the LLM server.
110+ parameters (Optional[dict]): Optional parameters to pass to the LLM API.
111+
112+ Returns:
113+ An HTTP client object that can generate text based on user input.
114+ """
115+
91116 if parameters is None :
92117 parameters = ui_default_parameters ()
93118
@@ -98,4 +123,3 @@ def build_text_generation_web_ui_client_llm(
98123 response_extractor = _response_extractor ,
99124 )
100125
101-
0 commit comments