-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* update * The vertices of the graph support the map data structure clsoe(#810) * ai support Use local LLM(claude3) close #827 * Official and Stable ORM Framework for MongoDB close(#829)
- Loading branch information
Showing
10 changed files
with
162 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package run.mone; | ||
|
||
import com.google.gson.Gson; | ||
import org.json.JSONObject; | ||
import software.amazon.awssdk.core.SdkBytes; | ||
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; | ||
import software.amazon.awssdk.identity.spi.IdentityProvider; | ||
import software.amazon.awssdk.identity.spi.ResolveIdentityRequest; | ||
import software.amazon.awssdk.identity.spi.internal.DefaultAwsCredentialsIdentity; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; | ||
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest; | ||
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/4/12 13:35 | ||
*/ | ||
public class AwsClient { | ||
|
||
private static final Gson gson = new Gson(); | ||
|
||
|
||
public static ResponsePayload call(JSONObject payload, Region region, String modelId, Key key) { | ||
BedrockRuntimeClient client = BedrockRuntimeClient.builder() | ||
.credentialsProvider(new IdentityProvider<>() { | ||
@Override | ||
public Class<AwsCredentialsIdentity> identityType() { | ||
return AwsCredentialsIdentity.class; | ||
} | ||
|
||
public CompletableFuture<AwsCredentialsIdentity> resolveIdentity(ResolveIdentityRequest request) { | ||
return CompletableFuture.completedFuture(DefaultAwsCredentialsIdentity.builder().accessKeyId(key.getKeyId()).secretAccessKey(key.getKey()).build()); | ||
} | ||
}) | ||
.region(region) | ||
.build(); | ||
|
||
InvokeModelRequest request = InvokeModelRequest.builder() | ||
.contentType("application/json") | ||
.body(SdkBytes.fromUtf8String(payload.toString())) | ||
.modelId(modelId) | ||
.build(); | ||
|
||
InvokeModelResponse resp = client.invokeModel(request); | ||
String str = new String(resp.body().asByteArray()); | ||
return gson.fromJson(str, ResponsePayload.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.xiaomi.youpin.docean; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import com.xiaomi.youpin.docean.anno.RequestMapping; | ||
|
@@ -41,10 +42,12 @@ | |
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -138,11 +141,32 @@ private void registerControllerMethods(Bean bean) { | |
hrm.setObj(bean.getObj()); | ||
hrm.setMethod(m); | ||
hrm.setHttpMethod(rm.method()); | ||
hrm.setGenericSuperclassTypeArguments(getGenericSuperclassTypeArguments(bean.getClazz())); | ||
ioc.publishEvent(new Event(EventType.initController, path)); | ||
requestMethodMap.put(path, hrm); | ||
})); | ||
} | ||
|
||
public static Map<String, Class> getGenericSuperclassTypeArguments(Class clazz) { | ||
List<String> list = Arrays.stream(clazz.getSuperclass().getTypeParameters()).map(it -> it.getName()).collect(Collectors.toList()); | ||
if (list.size() == 0) { | ||
return Maps.newHashMap(); | ||
} | ||
Map<String, Class> map = new HashMap<>(); | ||
Type genericSuperclass = clazz.getGenericSuperclass(); | ||
if (genericSuperclass instanceof ParameterizedType) { | ||
ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass; | ||
Type[] typeArguments = parameterizedType.getActualTypeArguments(); | ||
for (int i = 0; i < typeArguments.length; i++) { | ||
Type argument = typeArguments[i]; | ||
if (argument instanceof Class<?>) { | ||
map.put(list.get(i), (Class) argument); | ||
} | ||
} | ||
} | ||
return map; | ||
} | ||
|
||
|
||
private static final class LazyHolder { | ||
private static final Mvc ins = new Mvc(Ioc.ins()); | ||
|
@@ -187,6 +211,16 @@ public void callService(MvcContext context, MvcRequest request, MvcResponse resp | |
response.writeAndFlush(context, new Gson().toJson(mr)); | ||
} | ||
|
||
public List<Class> mapMethodParametersToClasses(Method method, Map<String, Class> map) { | ||
return Arrays.stream(method.getParameters()).map(it -> { | ||
String name = it.getParameterizedType().getTypeName(); | ||
if ((it.getType() instanceof Object) && map.containsKey(name)) { | ||
return map.get(name); | ||
} | ||
return it.getType(); | ||
}).collect(Collectors.toList()); | ||
} | ||
|
||
public void callMethod(MvcContext context, MvcRequest request, MvcResponse response, MvcResult<Object> result, HttpRequestMethod method) { | ||
Safe.run(() -> { | ||
Object[] params = new Object[]{null}; | ||
|
@@ -199,7 +233,10 @@ public void callMethod(MvcContext context, MvcRequest request, MvcResponse respo | |
params[0] = context; | ||
} else { | ||
try { | ||
params = methodInvoker.getMethodParams(method.getMethod(), args); | ||
//可能方法中有泛型,这里给fix调,用实际的Class | ||
List<Class> list = mapMethodParametersToClasses(method.getMethod(), method.getGenericSuperclassTypeArguments()); | ||
Class[] types = list.toArray(new Class[]{}); | ||
params = methodInvoker.getMethodParams(args, types); | ||
} catch (Exception e) { | ||
log.error("getMethodParams error,path:{},params:{},method:{}", context.getPath(), | ||
GsonUtils.gson.toJson(context.getParams()), request.getMethod().toLowerCase(Locale.ROOT), e); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import lombok.Data; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -36,5 +37,7 @@ public class HttpRequestMethod { | |
|
||
private long timeout; | ||
|
||
private Map<String, Class> genericSuperclassTypeArguments; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters