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

Method streaming

config/claude_code_handler.py:951–987  ·  view source on GitHub ↗

Sync token streaming, straight off the Anthropic SSE response.

(
        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

949 return chunks
950
951 def streaming(
952 self,
953 model: str,
954 messages: list[dict[str, Any]],
955 api_base: str | None = None,
956 custom_prompt_dict: dict[str, Any] | None = None,
957 model_response: ModelResponse | None = None,
958 print_verbose: Any = None,
959 encoding: Any = None,
960 logging_obj: Any = None,
961 optional_params: dict[str, Any] | None = None,
962 acompletion: bool | None = None,
963 timeout: float | None = None,
964 litellm_params: dict[str, Any] | None = None,
965 logger_fn: Any = None,
966 headers: dict[str, str] | None = None,
967 **kwargs: Any,
968 ) -> Iterator[dict[str, Any]]:
969 """Sync token streaming, straight off the Anthropic SSE response."""
970 body_str, api_url, _ = self._build_anthropic_request(
971 model, messages, optional_params, api_base, stream=True
972 )
973 with sync_client(timeout=timeout or 600) as client:
974 for force_refresh in (False, True):
975 req_headers = _build_headers(get_access_token(force_refresh=force_refresh))
976 with client.stream(
977 "POST",
978 f"{api_url}/v1/messages?beta=true",
979 content=body_str,
980 headers=req_headers,
981 ) as resp:
982 if resp.status_code == 401 and not force_refresh:
983 resp.read()
984 continue
985 _raise_for_stream_status(resp, model)
986 yield from _anthropic_sse_to_chunks(resp.iter_lines())
987 return
988
989 async def astreaming(
990 self,

Callers

nothing calls this directly

Calls 8

sync_clientFunction · 0.90
_build_headersFunction · 0.85
get_access_tokenFunction · 0.85
_anthropic_sse_to_chunksFunction · 0.85
_raise_for_stream_statusFunction · 0.70
streamMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected