MCPcopy Create free account
hub / github.com/BitterSecurity/Decepticon / completion

Method completion

config/perplexity_handler.py:156–250  ·  view source on GitHub ↗
(
        self,
        model: str,
        messages: list[dict[str, Any]],
        api_base: str | None = None,
        custom_prompt_dict: dict[str, Any] | None = None,
        model_response: ModelResponse | None = None,
        print_verbose: Any = None,
        encoding: Any = None,
        logging_obj: Any = None,
        optional_params: dict[str, Any] | None = None,
        acompletion: bool | None = None,
        timeout: float | None = None,
        litellm_params: dict[str, Any] | None = None,
        logger_fn: Any = None,
        headers: dict[str, str] | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

154 """
155
156 def completion(
157 self,
158 model: str,
159 messages: list[dict[str, Any]],
160 api_base: str | None = None,
161 custom_prompt_dict: dict[str, Any] | None = None,
162 model_response: ModelResponse | None = None,
163 print_verbose: Any = None,
164 encoding: Any = None,
165 logging_obj: Any = None,
166 optional_params: dict[str, Any] | None = None,
167 acompletion: bool | None = None,
168 timeout: float | None = None,
169 litellm_params: dict[str, Any] | None = None,
170 logger_fn: Any = None,
171 headers: dict[str, str] | None = None,
172 **kwargs: Any,
173 ) -> ModelResponse:
174 actual_model = model.split("/", 1)[-1] if "/" in model else model
175
176 opts = optional_params or {}
177 request_body: dict[str, Any] = {"model": actual_model, "messages": messages}
178
179 if "temperature" in opts:
180 request_body["temperature"] = opts["temperature"]
181 if "max_tokens" in opts:
182 request_body["max_tokens"] = opts["max_tokens"]
183
184 api_url = api_base or PERPLEXITY_API_BASE
185
186 def _send(force_refresh: bool) -> httpx.Response:
187 access_token = get_perplexity_access_token(force_refresh=force_refresh)
188 req_headers = {
189 "authorization": f"Bearer {access_token}",
190 "content-type": "application/json",
191 "accept": "application/json",
192 }
193 return _http_post(
194 f"{api_url}/chat/completions",
195 json=request_body,
196 headers=req_headers,
197 timeout=timeout or 600,
198 )
199
200 resp = with_retry_on_401(_send)
201
202 if resp.status_code == 401:
203 _pplx_file_cache.invalidate()
204 raise litellm.AuthenticationError(
205 message=(
206 "Perplexity Pro authentication was rejected. Re-extract the "
207 f"PERPLEXITY_SESSION_TOKEN cookie. Underlying: {resp.text}"
208 ),
209 model=model,
210 llm_provider="pplx-sub",
211 )
212
213 if resp.status_code == 429:

Callers 1

streamingMethod · 0.95

Calls 4

with_retry_on_401Function · 0.90
invalidateMethod · 0.80
jsonMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected