添加修改模型请求头

This commit is contained in:
h88782481 2026-03-13 20:25:33 +08:00
parent 406a36af89
commit e726f11bad
9 changed files with 109 additions and 1 deletions

View file

@ -13,7 +13,7 @@ from flask import Blueprint, request, jsonify
import settings
from config import Config
from routes.common import inject_instructions_anthropic
from routes.common import apply_body_modifications, apply_header_modifications, inject_instructions_anthropic
from utils.http import build_anthropic_headers, forward_request, sse_response
logger = logging.getLogger(__name__)
@ -35,10 +35,14 @@ def messages_passthrough():
api_key = mapping['api_key']
custom_instructions = mapping.get('custom_instructions', '')
instructions_position = mapping.get('instructions_position', 'prepend')
body_mods = mapping.get('body_modifications', {})
header_mods = mapping.get('header_modifications', {})
headers = build_anthropic_headers(api_key)
headers = apply_header_modifications(headers, header_mods)
url = f'{url_base.rstrip("/")}/v1/messages'
payload = inject_instructions_anthropic(payload, custom_instructions, instructions_position)
payload = apply_body_modifications(payload, body_mods)
if not is_stream:
resp, err = forward_request(url, headers, payload)