mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
* ✨ feat(llm): 增强LLM服务,支持图片生成、响应验证与OpenRouter集成 - 【新功能】统一图片生成与编辑API `create_image`,支持文生图、图生图及多图输入 - 【新功能】引入LLM响应验证机制,通过 `validation_policy` 和 `response_validator` 确保响应内容符合预期,例如强制返回图片 - 【新功能】适配OpenRouter API,扩展LLM服务提供商支持,并添加OpenRouter特定请求头 - 【重构】将日志净化逻辑重构至 `log_sanitizer` 模块,提供统一的净化入口,并应用于NoneBot消息、LLM请求/响应日志 - 【修复】优化Gemini适配器,正确解析图片生成响应中的Base64图片数据,并更新模型能力注册表 * ✨ feat(image): 优化图片生成响应并返回完整LLMResponse * ✨ feat(llm): 为 OpenAI 兼容请求体添加日志净化 * 🐛 fix(ui): 截断UI调试HTML日志中的长base64图片数据 --------- Co-authored-by: webjoin111 <455457521@qq.com>
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
"""
|
|
OpenAI API 适配器
|
|
|
|
支持 OpenAI、DeepSeek、智谱AI 和其他 OpenAI 兼容的 API 服务。
|
|
"""
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .base import OpenAICompatAdapter
|
|
|
|
if TYPE_CHECKING:
|
|
from ..service import LLMModel
|
|
|
|
|
|
class OpenAIAdapter(OpenAICompatAdapter):
|
|
"""OpenAI兼容API适配器"""
|
|
|
|
@property
|
|
def api_type(self) -> str:
|
|
return "openai"
|
|
|
|
@property
|
|
def supported_api_types(self) -> list[str]:
|
|
return [
|
|
"openai",
|
|
"deepseek",
|
|
"zhipu",
|
|
"general_openai_compat",
|
|
"ark",
|
|
"openrouter",
|
|
]
|
|
|
|
def get_chat_endpoint(self, model: "LLMModel") -> str:
|
|
"""返回聊天完成端点"""
|
|
if model.api_type == "ark":
|
|
return "/api/v3/chat/completions"
|
|
if model.api_type == "zhipu":
|
|
return "/api/paas/v4/chat/completions"
|
|
return "/v1/chat/completions"
|
|
|
|
def get_embedding_endpoint(self, model: "LLMModel") -> str:
|
|
"""根据API类型返回嵌入端点"""
|
|
if model.api_type == "zhipu":
|
|
return "/v4/embeddings"
|
|
return "/v1/embeddings"
|