Bump version to 0.1.2; update logging paths and enhance CLI with version command
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
"""Local Anthropic-compatible proxy for AI Nexus Claude models."""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
||||
__version__ = "0.1.2"
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
|
||||
import uvicorn
|
||||
|
||||
from nexus_claude_api import __version__
|
||||
import nexus_claude_api.config as config
|
||||
from nexus_claude_api.config import (
|
||||
DEFAULT_ENDPOINT_URL,
|
||||
@@ -21,6 +22,7 @@ from nexus_claude_api.shell import generate_claude_code_powershell
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(prog="nexus-claude-api")
|
||||
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
|
||||
start = subparsers.add_parser("start", help="Start the local API server")
|
||||
@@ -71,16 +73,20 @@ def run_config(args: argparse.Namespace, parser: argparse.ArgumentParser) -> int
|
||||
|
||||
|
||||
def run_start(args: argparse.Namespace) -> int:
|
||||
settings = Settings.from_values(
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
endpoint_url=args.endpoint_url,
|
||||
api_key=args.api_key,
|
||||
model=args.model,
|
||||
small_model=args.small_model,
|
||||
verbose=args.verbose,
|
||||
dev=args.dev,
|
||||
)
|
||||
try:
|
||||
settings = Settings.from_values(
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
endpoint_url=args.endpoint_url,
|
||||
api_key=args.api_key,
|
||||
model=args.model,
|
||||
small_model=args.small_model,
|
||||
verbose=args.verbose,
|
||||
dev=args.dev,
|
||||
)
|
||||
except ValueError as exc:
|
||||
print(f"Invalid configuration: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
if not settings.api_key:
|
||||
print(
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.requests import Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from nexus_claude_api import __version__
|
||||
from nexus_claude_api.config import Settings
|
||||
from nexus_claude_api.errors import NexusClaudeError, anthropic_error_response
|
||||
from nexus_claude_api.nexus_client import NexusClient
|
||||
@@ -18,7 +19,7 @@ def create_app(
|
||||
nexus_client: NexusClient | None = None,
|
||||
) -> FastAPI:
|
||||
resolved_settings = settings or Settings.from_values(require_api_key=False)
|
||||
app = FastAPI(title="nexus-claude-api", version="0.1.0")
|
||||
app = FastAPI(title="nexus-claude-api", version=__version__)
|
||||
app.state.settings = resolved_settings
|
||||
app.state.nexus_client = nexus_client or NexusClient(resolved_settings)
|
||||
|
||||
|
||||
@@ -34,12 +34,11 @@ def anthropic_to_bedrock_request(payload: AnthropicMessagesRequest) -> dict[str,
|
||||
inference_config["temperature"] = payload.temperature
|
||||
if payload.top_p is not None:
|
||||
inference_config["topP"] = payload.top_p
|
||||
if payload.stop_sequences:
|
||||
inference_config["stopSequences"] = payload.stop_sequences
|
||||
if inference_config:
|
||||
request["inferenceConfig"] = inference_config
|
||||
|
||||
if payload.stop_sequences:
|
||||
request["stopSequences"] = payload.stop_sequences
|
||||
|
||||
tool_config = _tools_to_bedrock(payload)
|
||||
if tool_config:
|
||||
request["toolConfig"] = tool_config
|
||||
@@ -161,4 +160,3 @@ def _tools_to_bedrock(payload: AnthropicMessagesRequest) -> dict[str, Any] | Non
|
||||
tool_config["toolChoice"] = {"tool": {"name": choice.name}}
|
||||
|
||||
return tool_config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user