You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB
Java

package com.supervision.pdfqaserver.config;
import cn.hutool.core.util.StrUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class OllamaChatModelAspect {
@Value("${spring.ai.ollama.chat.model}")
private String model;
private String callStringMessage = "String org.springframework.ai.chat.model.ChatModel.call(String)";
/**
* ollamacall/no_thinkthink
* @param joinPoint joinPoint
* @return Object
* @throws Throwable
*/
@Around("execution(* org.springframework.ai.chat.model.ChatModel.call(..))")
public Object aroundMethodExecution(ProceedingJoinPoint joinPoint) throws Throwable {
String signature = joinPoint.getSignature().toString();
// 执行原方法
Object result = joinPoint.proceed();
1 month ago
if (StrUtil.equals(model,"qwen3:30b-a3b") ) {
if(StrUtil.equals(signature, callStringMessage)){
result = ((String) result).replaceAll("(?is)<think\\b[^>]*>(.*?)</think>", "").trim();
}
}
return result;
}
}