增加注入提示词功能

This commit is contained in:
h88782481 2026-03-13 17:22:28 +08:00
parent f193c48ce1
commit ae059ffcb8
10 changed files with 160 additions and 20 deletions

View file

@ -13,6 +13,7 @@ from flask import Blueprint, request, jsonify
import settings
from config import Config
from routes.common import inject_instructions_anthropic
from utils.http import build_anthropic_headers, forward_request, sse_response
logger = logging.getLogger(__name__)
@ -29,11 +30,16 @@ def messages_passthrough():
logger.info(f'[透传] model={model} 流式={is_stream}')
url_base = settings.get_url()
api_key = settings.get_key()
mapping = settings.resolve_model(model)
url_base = mapping['target_url']
api_key = mapping['api_key']
custom_instructions = mapping.get('custom_instructions', '')
instructions_position = mapping.get('instructions_position', 'prepend')
headers = build_anthropic_headers(api_key)
url = f'{url_base.rstrip("/")}/v1/messages'
payload = inject_instructions_anthropic(payload, custom_instructions, instructions_position)
if not is_stream:
resp, err = forward_request(url, headers, payload)
if err: