ccproxy.claude_sdk.converter¶
ccproxy.claude_sdk.converter
¶
Message format converter for Claude SDK interactions.
MessageConverter
¶
Handles conversion between Anthropic API format and Claude SDK format.
format_messages_to_prompt
staticmethod
¶
Convert Anthropic messages format to a single prompt string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[dict[str, Any]]
|
List of messages in Anthropic format |
required |
Returns:
Type | Description |
---|---|
str
|
Single prompt string formatted for Claude SDK |
Source code in ccproxy/claude_sdk/converter.py
convert_to_anthropic_response
staticmethod
¶
convert_to_anthropic_response(
assistant_message,
result_message,
model,
mode=FORWARD,
pretty_format=True,
)
Convert Claude SDK messages to Anthropic API response format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assistant_message
|
AssistantMessage
|
The assistant message from Claude SDK |
required |
result_message
|
ResultMessage
|
The result message from Claude SDK |
required |
model
|
str
|
The model name used |
required |
mode
|
SDKMessageMode
|
System message handling mode (forward, ignore, formatted) |
FORWARD
|
pretty_format
|
bool
|
Whether to use pretty formatting (true: indented JSON with newlines, false: compact with escaped content) |
True
|
Returns:
Type | Description |
---|---|
MessageResponse
|
Response in Anthropic API format |
Source code in ccproxy/claude_sdk/converter.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
create_streaming_start_chunks
staticmethod
¶
Create the initial streaming chunks for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message_id
|
str
|
The message ID |
required |
model
|
str
|
The model name |
required |
input_tokens
|
int
|
Number of input tokens for the request |
0
|
Returns:
Type | Description |
---|---|
list[tuple[str, dict[str, Any]]]
|
List of tuples (event_type, chunk) for initial streaming chunks |
Source code in ccproxy/claude_sdk/converter.py
create_streaming_delta_chunk
staticmethod
¶
Create a streaming delta chunk for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content to include |
required |
Returns:
Type | Description |
---|---|
tuple[str, dict[str, Any]]
|
Tuple of (event_type, chunk) |
Source code in ccproxy/claude_sdk/converter.py
create_streaming_end_chunks
staticmethod
¶
Create the final streaming chunks for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_reason
|
str
|
The reason for stopping |
'end_turn'
|
stop_sequence
|
str | None
|
The stop sequence used (if any) |
None
|
Returns:
Type | Description |
---|---|
list[tuple[str, dict[str, Any]]]
|
List of tuples (event_type, chunk) for final streaming chunks |