ccproxy.llms.streaming.processors¶
ccproxy.llms.streaming.processors
¶
Stream processing utilities for converting between different streaming formats.
This module provides stream processors that convert between different LLM streaming response formats (e.g., Anthropic to OpenAI, OpenAI to Anthropic).
AnthropicStreamProcessor
¶
Processes OpenAI streaming data into Anthropic SSE format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model name for responses |
'claude-3-5-sonnet-20241022'
|
Source code in ccproxy/llms/streaming/processors.py
process_stream
async
¶
Process OpenAI-format streaming data into Anthropic SSE format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
AsyncIterator[dict[str, Any]]
|
Async iterator of OpenAI-style response chunks |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[str]
|
Anthropic-formatted SSE strings with proper event: lines |
Source code in ccproxy/llms/streaming/processors.py
OpenAIStreamProcessor
¶
OpenAIStreamProcessor(
message_id=None,
model="claude-3-5-sonnet-20241022",
created=None,
enable_usage=True,
enable_tool_calls=True,
enable_thinking_serialization=None,
output_format="sse",
)
Processes Anthropic/Claude streaming responses into OpenAI format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str | None
|
Response ID, generated if not provided |
None
|
model
|
str
|
Model name for responses |
'claude-3-5-sonnet-20241022'
|
created
|
int | None
|
Creation timestamp, current time if not provided |
None
|
enable_usage
|
bool
|
Whether to include usage information |
True
|
enable_tool_calls
|
bool
|
Whether to process tool calls |
True
|
output_format
|
Literal['sse', 'dict']
|
Output format - "sse" for Server-Sent Events strings, "dict" for dict objects |
'sse'
|
Source code in ccproxy/llms/streaming/processors.py
process_stream
async
¶
Process a Claude/Anthropic stream into OpenAI format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
claude_stream
|
AsyncIterator[dict[str, Any]]
|
Async iterator of Claude response chunks |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[str | dict[str, Any]]
|
OpenAI-formatted SSE strings or dict objects based on output_format |
Source code in ccproxy/llms/streaming/processors.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |