HadTavern 0.01: Gemini/Claude fixes; UI _origId reuse; docs; .bat open
This commit is contained in:
43
agentui/common/vendors.py
Normal file
43
agentui/common/vendors.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
__all__ = ["detect_vendor"]
|
||||
|
||||
|
||||
def detect_vendor(payload: Dict[str, Any] | None) -> str:
|
||||
"""
|
||||
Определение вендора по форме payload.
|
||||
Возвращает одно из: "openai" | "gemini" | "claude" | "unknown".
|
||||
|
||||
Правила (порядок важен):
|
||||
- Anthropic (Claude):
|
||||
* наличие ключа "anthropic_version" (официальный заголовок/поле)
|
||||
* явный маркер provider == "anthropic"
|
||||
- Gemini:
|
||||
* наличие "contents" или "generationConfig" (Google AI Studio / Vertex)
|
||||
- OpenAI:
|
||||
* наличие "messages" или "model"
|
||||
- Фоллбэк: "unknown"
|
||||
"""
|
||||
if not isinstance(payload, dict):
|
||||
return "unknown"
|
||||
|
||||
# Явные подсказки, если заранее указали
|
||||
hint = str(payload.get("vendor_format") or payload.get("vendor") or "").lower()
|
||||
if hint in {"openai", "gemini", "claude"}:
|
||||
return hint
|
||||
|
||||
# Anthropic (Claude)
|
||||
if "anthropic_version" in payload or payload.get("provider") == "anthropic":
|
||||
return "claude"
|
||||
|
||||
# Gemini (Google)
|
||||
if "contents" in payload or "generationConfig" in payload:
|
||||
return "gemini"
|
||||
|
||||
# OpenAI
|
||||
if "messages" in payload or "model" in payload:
|
||||
return "openai"
|
||||
|
||||
return "unknown"
|
||||
Reference in New Issue
Block a user