Bump version to 0.1.2; update logging paths and enhance CLI with version command
This commit is contained in:
@@ -2,7 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
from typing import Annotated
|
||||
from collections.abc import Iterable, Iterator
|
||||
from typing import Annotated, Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import JSONResponse, Response, StreamingResponse
|
||||
@@ -60,6 +61,46 @@ def normalize_legacy_system_messages(raw: object) -> object:
|
||||
return normalized
|
||||
|
||||
|
||||
def anthropic_sse_stream(
|
||||
stream: Iterable[dict[str, Any]],
|
||||
*,
|
||||
model: str,
|
||||
correlation_id: str,
|
||||
) -> Iterator[str]:
|
||||
try:
|
||||
for event in bedrock_stream_to_anthropic_events(stream, model=model):
|
||||
yield sse_frame(event)
|
||||
except NexusClaudeError as exc:
|
||||
yield sse_frame(
|
||||
{
|
||||
"type": "error",
|
||||
"error": {
|
||||
"type": exc.error_type,
|
||||
"message": f"{exc.message} [correlation_id={correlation_id}]",
|
||||
"correlation_id": correlation_id,
|
||||
},
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"anthropic_messages_stream_error correlation_id=%s",
|
||||
correlation_id,
|
||||
)
|
||||
yield sse_frame(
|
||||
{
|
||||
"type": "error",
|
||||
"error": {
|
||||
"type": "api_error",
|
||||
"message": (
|
||||
"Unexpected error while streaming response "
|
||||
f"[correlation_id={correlation_id}]"
|
||||
),
|
||||
"correlation_id": correlation_id,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/v1/messages", response_model=None)
|
||||
async def create_message(
|
||||
request: Request,
|
||||
@@ -85,12 +126,10 @@ async def create_message(
|
||||
correlation_id=correlation_id,
|
||||
)
|
||||
return StreamingResponse(
|
||||
(
|
||||
sse_frame(event)
|
||||
for event in bedrock_stream_to_anthropic_events(
|
||||
stream,
|
||||
model=payload.model,
|
||||
)
|
||||
anthropic_sse_stream(
|
||||
stream,
|
||||
model=payload.model,
|
||||
correlation_id=correlation_id,
|
||||
),
|
||||
media_type="text/event-stream",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user