mirror of
https://gitee.com/agents-flex/agents-flex.git
synced 2024-12-02 03:48:11 +08:00
refactor: optimize ...
This commit is contained in:
parent
d2ef347d5d
commit
4b4fb420c5
@ -15,8 +15,12 @@
|
||||
*/
|
||||
package com.agentsflex.convert;
|
||||
|
||||
import com.agentsflex.util.ArrayUtil;
|
||||
import com.agentsflex.util.StringUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -30,6 +34,14 @@ public class ConvertService {
|
||||
register(new LongConverter(), Long.class, long.class);
|
||||
register(new DoubleConverter(), Double.class, double.class);
|
||||
register(new FloatConverter(), Float.class, float.class);
|
||||
register(new ShortConverter(), Short.class, short.class);
|
||||
|
||||
register(new BigDecimalConverter(), BigDecimal.class);
|
||||
register(new BigIntegerConverter(), BigInteger.class);
|
||||
register(new ByteConverter(), byte.class);
|
||||
register(new ByteArrayConverter(), byte[].class);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void register(IConverter<?> converter, Class<?>... classes) {
|
||||
@ -48,11 +60,11 @@ public class ConvertService {
|
||||
return value;
|
||||
}
|
||||
|
||||
String valueString = value.toString();
|
||||
if (valueString == null) {
|
||||
return null;
|
||||
if (toType == Serializable.class && ArrayUtil.contains(value.getClass().getInterfaces(), Serializable.class)) {
|
||||
return value;
|
||||
}
|
||||
valueString = valueString.trim();
|
||||
|
||||
String valueString = value.toString().trim();
|
||||
if (valueString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@ -61,6 +73,7 @@ public class ConvertService {
|
||||
if (converter != null) {
|
||||
return converter.convert(valueString);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,10 @@ public class Functions<T> extends ArrayList<Function<T>> {
|
||||
|
||||
public static <R> Functions<R> from(Class<?> clazz, String... methodNames) {
|
||||
List<Method> methodList = ClassUtil.getAllMethods(clazz, method -> {
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (!resultType.isAssignableFrom(method.getReturnType())) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (method.getAnnotation(FunctionDef.class) == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class OpenAiLlmTest {
|
||||
|
||||
OpenAiLlm llm = new OpenAiLlm(config);
|
||||
|
||||
FunctionPrompt prompt = new FunctionPrompt("今天北京的天气怎么样", WeatherUtil.class);
|
||||
FunctionPrompt prompt = new FunctionPrompt("今天北京的天气怎么样", WeatherFunctions.class);
|
||||
FunctionMessageResponse response = llm.chat(prompt);
|
||||
|
||||
Object result = response.invoke();
|
||||
|
@ -3,7 +3,7 @@ package com.agentsflex.llm.openai;
|
||||
import com.agentsflex.functions.annotation.FunctionDef;
|
||||
import com.agentsflex.functions.annotation.FunctionParam;
|
||||
|
||||
public class WeatherUtil {
|
||||
public class WeatherFunctions {
|
||||
|
||||
@FunctionDef(name = "get_the_weather_info", description = "get the weather info")
|
||||
public static String getWeatherInfo(
|
Loading…
Reference in New Issue
Block a user