diff --git a/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java b/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java index c37f33d55..d292f96b3 100644 --- a/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java +++ b/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java @@ -6,7 +6,6 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.google.gson.Gson; -import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.unfbx.chatgpt.OpenAiClient; import com.unfbx.chatgpt.OpenAiStreamClient; @@ -31,21 +30,16 @@ import okhttp3.sse.EventSourceListener; import org.apache.commons.math3.linear.ArrayRealVector; import org.apache.commons.math3.linear.RealVector; -import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.DnsResolver; import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.protocol.HttpContext; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.jetbrains.annotations.NotNull; @@ -61,14 +55,12 @@ import run.mone.openai.net.MyConnectionSocketFactory; import run.mone.openai.net.MySSLConnectionSocketFactory; -import javax.net.ssl.SSLContext; -import java.io.BufferedWriter; import java.io.File; import java.io.IOException; -import java.io.OutputStreamWriter; import java.lang.reflect.Type; import java.math.BigDecimal; -import java.net.*; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; @@ -178,7 +170,7 @@ public void onEvent(String str) { public void end() { latch.countDown(); } - }); + }, ReqConfig.builder().model("gpt-4-1106-preview").build()); latch.await(); } diff --git a/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java b/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java index 8e2909bc6..4fc012660 100644 --- a/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java +++ b/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java @@ -77,7 +77,7 @@ public static String modifyCode(String filePath, String className, List newStatements = javaParser.parseBlock("{" + newCode.toString() + "}").getResult().get().getStatements(); - // 在方法的开头插入新代码 + //Insert new code at the beginning of the method. method.getBody().ifPresent(body -> { NodeList statements = body.getStatements(); statements.addAll(0, newStatements); @@ -91,7 +91,6 @@ public static String modifyCode(String filePath, String className, List readImports(String code) { CharSource source = CharSource.wrap(code); String output = null; @@ -145,6 +144,7 @@ public static String removeImports(String code) { /** * 是否是class + * * @param code * @return */ diff --git a/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java b/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java index 329160516..912c295dc 100644 --- a/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java +++ b/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java @@ -80,6 +80,18 @@ public void testParse() { System.out.println(cu.getType(0).getName().getIdentifier()); } + @SneakyThrows + @Test + public void testParseClass() { + JavaParser javaParser = new JavaParser(); + CompilationUnit cu = javaParser.parse(new File("/tmp/e")).getResult().get(); + cu.findAll(ClassOrInterfaceDeclaration.class).stream().limit(300).forEach(c->{ + System.out.println(c.getName()); + System.out.println(c); + System.out.println("-------"); + }); + } + @Test public void test0() {