add /api/v3/llm/chat/completions
This commit is contained in:
parent
f18d966123
commit
f45f55b50a
@ -1018,6 +1018,10 @@ async def llm_passthrough_v3(request: ChatRequestV3, authorization: Optional[str
|
||||
- stream: bool - whether to stream the output, default false
|
||||
- user_identifier: str - used to resolve the api_key owner
|
||||
|
||||
Authentication:
|
||||
- Authorization header is required: Bearer <token>
|
||||
- token = md5(MASTERKEY:bot_id), same scheme as the v2 API
|
||||
|
||||
Returns:
|
||||
Union[dict, StreamingResponse]: OpenAI-compatible completion or stream
|
||||
"""
|
||||
@ -1026,12 +1030,21 @@ async def llm_passthrough_v3(request: ChatRequestV3, authorization: Optional[str
|
||||
if not bot_id:
|
||||
raise HTTPException(status_code=400, detail="bot_id is required")
|
||||
|
||||
# Optional auth check (consistent with v3, non-blocking)
|
||||
if authorization:
|
||||
expected_token = generate_v2_auth_token(bot_id)
|
||||
provided_token = extract_api_key_from_auth(authorization)
|
||||
if provided_token and provided_token != expected_token:
|
||||
logger.warning("Invalid auth token provided for LLM passthrough API, but continuing anyway")
|
||||
# Authentication validation (same auth logic as v2: token = md5(MASTERKEY:bot_id))
|
||||
expected_token = generate_v2_auth_token(bot_id)
|
||||
provided_token = extract_api_key_from_auth(authorization)
|
||||
|
||||
if not provided_token:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Authorization header is required"
|
||||
)
|
||||
|
||||
if provided_token != expected_token:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail=f"Invalid authentication token. Expected: {expected_token[:8]}..., Provided: {provided_token[:8]}..."
|
||||
)
|
||||
|
||||
# Build the LLM client from db config
|
||||
llm, model_name = await build_llm_from_bot_config(bot_id, request.user_identifier)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user