适配jdk8 - 2,这个地方不会改

This commit is contained in:
cherishsince 2024-03-16 21:42:31 +08:00
parent c71b8b3c0b
commit 6a3cafb41e

View File

@ -1,113 +1,115 @@
///* /*
// * Copyright 2024-2024 the original author or authors. * Copyright 2024-2024 the original author or authors.
// * *
// * Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at * You may obtain a copy of the License at
// * *
// * https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
// * *
// * Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
// * limitations under the License. * limitations under the License.
// */ */
//package cn.iocoder.yudao.framework.ai.model.function; package cn.iocoder.yudao.framework.ai.model.function;
//
//import com.fasterxml.jackson.annotation.JsonClassDescription; import com.fasterxml.jackson.annotation.JsonClassDescription;
//import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
//import org.springframework.cloud.function.context.catalog.FunctionTypeUtils; import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
//import org.springframework.cloud.function.context.config.FunctionContextUtils; import org.springframework.cloud.function.context.config.FunctionContextUtils;
//import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
//import org.springframework.context.annotation.Description; import org.springframework.context.annotation.Description;
//import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
//import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
//import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
//import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
//
//import java.lang.reflect.Type; import java.lang.reflect.Type;
//import java.util.function.Function; import java.util.function.Function;
//
///** /**
// * A Spring {@link ApplicationContextAware} implementation that provides a way to retrieve * A Spring {@link ApplicationContextAware} implementation that provides a way to retrieve
// * a {@link Function} from the Spring context and wrap it into a {@link FunctionCallback}. * a {@link Function} from the Spring context and wrap it into a {@link FunctionCallback}.
// * *
// * The name of the function is determined by the bean name. * The name of the function is determined by the bean name.
// * *
// * The description of the function is determined by the following rules: * The description of the function is determined by the following rules:
// * <ul> * <ul>
// * <li>Provided as a default description</li> * <li>Provided as a default description</li>
// * <li>Provided as a {@code @Description} annotation on the bean</li> * <li>Provided as a {@code @Description} annotation on the bean</li>
// * <li>Provided as a {@code @JsonClassDescription} annotation on the input class</li> * <li>Provided as a {@code @JsonClassDescription} annotation on the input class</li>
// * </ul> * </ul>
// * *
// * @author Christian Tzolov * @author Christian Tzolov
// * @author Christopher Smith * @author Christopher Smith
// */ */
//public class FunctionCallbackContext implements ApplicationContextAware { public class FunctionCallbackContext implements ApplicationContextAware {
//
// private GenericApplicationContext applicationContext; private GenericApplicationContext applicationContext;
//
// private FunctionCallbackWrapper.Builder.SchemaType schemaType = FunctionCallbackWrapper.Builder.SchemaType.JSON_SCHEMA; private FunctionCallbackWrapper.Builder.SchemaType schemaType = FunctionCallbackWrapper.Builder.SchemaType.JSON_SCHEMA;
//
// public void setSchemaType(FunctionCallbackWrapper.Builder.SchemaType schemaType) { public void setSchemaType(FunctionCallbackWrapper.Builder.SchemaType schemaType) {
// this.schemaType = schemaType; this.schemaType = schemaType;
// } }
//
// @Override @Override
// public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
// this.applicationContext = (GenericApplicationContext) applicationContext; this.applicationContext = (GenericApplicationContext) applicationContext;
// } }
//
// @SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
// public FunctionCallback getFunctionCallback(@NonNull String beanName, @Nullable String defaultDescription) { public FunctionCallback getFunctionCallback(@NonNull String beanName, @Nullable String defaultDescription) {
//
// Type beanType = FunctionContextUtils.findType(this.applicationContext.getBeanFactory(), beanName); Type beanType = FunctionContextUtils.findType(this.applicationContext.getBeanFactory(), beanName);
//
// if (beanType == null) { if (beanType == null) {
// throw new IllegalArgumentException( throw new IllegalArgumentException(
// "Functional bean with name: " + beanName + " does not exist in the context."); "Functional bean with name: " + beanName + " does not exist in the context.");
// } }
//
// if (!Function.class.isAssignableFrom(FunctionTypeUtils.getRawType(beanType))) { if (!Function.class.isAssignableFrom(FunctionTypeUtils.getRawType(beanType))) {
// throw new IllegalArgumentException( throw new IllegalArgumentException(
// "Function call Bean must be of type Function. Found: " + beanType.getTypeName()); "Function call Bean must be of type Function. Found: " + beanType.getTypeName());
// } }
//
// Type functionInputType = TypeResolverHelper.getFunctionArgumentType(beanType, 0); Type functionInputType = TypeResolverHelper.getFunctionArgumentType(beanType, 0);
//
// Class<?> functionInputClass = FunctionTypeUtils.getRawType(functionInputType); Class<?> functionInputClass = FunctionTypeUtils.getRawType(functionInputType);
// String functionName = beanName; String functionName = beanName;
// String functionDescription = defaultDescription; String functionDescription = defaultDescription;
//
// if (!StringUtils.hasText(functionDescription)) { if (!StringUtils.hasText(functionDescription)) {
// // Look for a Description annotation on the bean // Look for a Description annotation on the bean
// Description descriptionAnnotation = applicationContext.findAnnotationOnBean(beanName, Description.class); Description descriptionAnnotation = applicationContext.findAnnotationOnBean(beanName, Description.class);
//
// if (descriptionAnnotation != null) { if (descriptionAnnotation != null) {
// functionDescription = descriptionAnnotation.value(); functionDescription = descriptionAnnotation.value();
// } }
//
// if (!StringUtils.hasText(functionDescription)) { if (!StringUtils.hasText(functionDescription)) {
// // Look for a JsonClassDescription annotation on the input class // Look for a JsonClassDescription annotation on the input class
// JsonClassDescription jsonClassDescriptionAnnotation = functionInputClass JsonClassDescription jsonClassDescriptionAnnotation = functionInputClass
// .getAnnotation(JsonClassDescription.class); .getAnnotation(JsonClassDescription.class);
// if (jsonClassDescriptionAnnotation != null) { if (jsonClassDescriptionAnnotation != null) {
// functionDescription = jsonClassDescriptionAnnotation.value(); functionDescription = jsonClassDescriptionAnnotation.value();
// } }
// } }
//
// if (!StringUtils.hasText(functionDescription)) { if (!StringUtils.hasText(functionDescription)) {
// throw new IllegalStateException("Could not determine function description." throw new IllegalStateException("Could not determine function description."
// + "Please provide a description either as a default parameter, via @Description annotation on the bean " + "Please provide a description either as a default parameter, via @Description annotation on the bean "
// + "or @JsonClassDescription annotation on the input class."); + "or @JsonClassDescription annotation on the input class.");
// } }
// } }
//
// Object bean = this.applicationContext.getBean(beanName); Object bean = this.applicationContext.getBean(beanName);
//
// TODO: 2024/3/16 fansili 适配jdk8
return null;
// if (bean instanceof Function<?, ?> function) { // if (bean instanceof Function<?, ?> function) {
// return FunctionCallbackWrapper.builder(function) // return FunctionCallbackWrapper.builder(function)
// .withName(functionName) // .withName(functionName)
@ -119,6 +121,6 @@
// else { // else {
// throw new IllegalArgumentException("Bean must be of type Function"); // throw new IllegalArgumentException("Bean must be of type Function");
// } // }
// } }
//
//} }