mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
fix(openai-api): support n8n audio alias in example
Signed-off-by: LauraGPT <[email protected]>
This commit is contained in:
@@ -32,6 +32,8 @@ app = FastAPI(title="FunASR OpenAI-Compatible API", version="1.0.0")
|
||||
|
||||
MODEL_REGISTRY = {}
|
||||
DEVICE = "cpu"
|
||||
DEFAULT_MODEL = "sensevoice"
|
||||
N8N_OPENAI_MODEL_ALIAS = "whisper-1"
|
||||
|
||||
MODEL_CONFIGS = {
|
||||
"sensevoice": {
|
||||
@@ -95,6 +97,13 @@ def clean_text(text: str) -> str:
|
||||
return re.sub(r'<\|[^|]*\|>', '', text).strip()
|
||||
|
||||
|
||||
def resolve_openai_transcription_model(requested_model: str) -> str:
|
||||
"""Map n8n's fixed OpenAI transcription model to the started model."""
|
||||
if requested_model == N8N_OPENAI_MODEL_ALIAS:
|
||||
return DEFAULT_MODEL
|
||||
return requested_model
|
||||
|
||||
|
||||
@app.post("/v1/audio/transcriptions")
|
||||
async def transcribe(
|
||||
file: UploadFile = File(...),
|
||||
@@ -111,6 +120,8 @@ async def transcribe(
|
||||
- language: Optional language hint
|
||||
- response_format: json or verbose_json
|
||||
"""
|
||||
model = resolve_openai_transcription_model(model)
|
||||
|
||||
# Validate model
|
||||
if model not in MODEL_CONFIGS:
|
||||
raise HTTPException(
|
||||
@@ -199,8 +210,9 @@ def main():
|
||||
parser.add_argument("--model", default="sensevoice", help="Pre-load model at startup")
|
||||
args = parser.parse_args()
|
||||
|
||||
global DEVICE
|
||||
global DEFAULT_MODEL, DEVICE
|
||||
DEVICE = args.device
|
||||
DEFAULT_MODEL = args.model
|
||||
|
||||
# Pre-load default model
|
||||
load_model(args.model)
|
||||
|
||||
Reference in New Issue
Block a user