| | |
| | | private final GenericApplicationContext applicationContext; |
| | | private final ObservationRegistry observationRegistry; |
| | | |
| | | /** |
| | | * 对一份 AI 参数草稿做真实连通性校验。 |
| | | * 校验方式不是简单判断字段非空,而是直接构造聊天模型并发起一次最小探测调用, |
| | | * 用返回结果和耗时生成前端可展示的校验报告。 |
| | | */ |
| | | public AiParamValidateResultDto validate(AiParam aiParam) { |
| | | long startedAt = System.currentTimeMillis(); |
| | | try { |
| | |
| | | } |
| | | |
| | | private OpenAiChatModel createChatModel(AiParam aiParam) { |
| | | /** |
| | | * 构造仅用于校验的轻量聊天模型。 |
| | | * 这里沿用正式链路的 Observation 和 ToolCalling 依赖, |
| | | * 保证校验结论与真实运行环境尽量一致。 |
| | | */ |
| | | OpenAiApi openAiApi = buildOpenAiApi(aiParam); |
| | | ToolCallingManager toolCallingManager = DefaultToolCallingManager.builder() |
| | | .observationRegistry(observationRegistry) |
| | |
| | | } |
| | | |
| | | private OpenAiApi buildOpenAiApi(AiParam aiParam) { |
| | | /** |
| | | * 根据表单里的 Base URL、API Key 和超时参数构造 OpenAI 兼容客户端。 |
| | | * 该方法被显式拆出来,是为了让“网络连接参数”和“模型选项”职责分离。 |
| | | */ |
| | | int timeoutMs = aiParam.getTimeoutMs() == null ? AiDefaults.DEFAULT_TIMEOUT_MS : aiParam.getTimeoutMs(); |
| | | SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| | | requestFactory.setConnectTimeout(timeoutMs); |
| | |
| | | } |
| | | |
| | | private String formatDate(Date date) { |
| | | /** 统一输出给前端的校验时间格式。 */ |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); |
| | | } |
| | | } |