Refactor models and logging for nexus-claude-api

- Update default models in config to use `claude-opus-4.6`.
- Introduce logging configuration to write logs to a file.
- Add correlation ID to error responses for better traceability.
- Implement diagnostics for summarizing message requests.
- Normalize legacy system messages in the API.
- Enhance tests to cover new logging and error handling features.
- Update README and documentation to reflect changes in model defaults and logging behavior.
This commit is contained in:
2026-06-26 22:36:09 +08:00
parent 2851fa01cf
commit 0e98ce57d4
21 changed files with 573 additions and 78 deletions

View File

@@ -11,7 +11,7 @@ from nexus_claude_api.translators.stream import bedrock_stream_to_anthropic_even
def test_text_request_translation() -> None:
payload = AnthropicMessagesRequest.model_validate(
{
"model": "claude-sonnet-4.6",
"model": "claude-opus-4.6",
"messages": [{"role": "user", "content": "Hello"}],
"system": "You are helpful.",
"max_tokens": 100,
@@ -21,7 +21,7 @@ def test_text_request_translation() -> None:
request = anthropic_to_bedrock_request(payload)
assert request["modelId"] == "claude-sonnet-4.6"
assert request["modelId"] == "claude-opus-4.6"
assert request["messages"] == [{"role": "user", "content": [{"text": "Hello"}]}]
assert request["system"] == [{"text": "You are helpful."}]
assert request["inferenceConfig"]["maxTokens"] == 100
@@ -32,7 +32,7 @@ def test_image_request_translation() -> None:
image_data = base64.b64encode(b"image-bytes").decode("ascii")
payload = AnthropicMessagesRequest.model_validate(
{
"model": "claude-sonnet-4.6",
"model": "claude-opus-4.6",
"messages": [
{
"role": "user",
@@ -63,7 +63,7 @@ def test_image_request_translation() -> None:
def test_tool_translation() -> None:
payload = AnthropicMessagesRequest.model_validate(
{
"model": "claude-sonnet-4.6",
"model": "claude-opus-4.6",
"messages": [
{"role": "user", "content": "Use a tool"},
{
@@ -119,7 +119,7 @@ def test_bedrock_response_translation() -> None:
"usage": {"inputTokens": 10, "outputTokens": 3},
}
translated = bedrock_to_anthropic_response(response, model="claude-sonnet-4.6")
translated = bedrock_to_anthropic_response(response, model="claude-opus-4.6")
assert translated.id == "req-1"
assert translated.content[0].type == "text"
@@ -137,7 +137,7 @@ def test_stream_translation() -> None:
]
translated = list(
bedrock_stream_to_anthropic_events(events, model="claude-sonnet-4.6")
bedrock_stream_to_anthropic_events(events, model="claude-opus-4.6")
)
assert translated[0]["type"] == "message_start"