Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test class #753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -178,7 +170,7 @@ public void onEvent(String str) {
public void end() {
latch.countDown();
}
});
}, ReqConfig.builder().model("gpt-4-1106-preview").build());
latch.await();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static String modifyCode(String filePath, String className, List<MethodCo
codeBlockBuilder.addStatement(mm.getCode());
CodeBlock newCode = codeBlockBuilder.build();
NodeList<Statement> newStatements = javaParser.parseBlock("{" + newCode.toString() + "}").getResult().get().getStatements();
// 在方法的开头插入新代码
//Insert new code at the beginning of the method.
method.getBody().ifPresent(body -> {
NodeList<Statement> statements = body.getStatements();
statements.addAll(0, newStatements);
Expand All @@ -91,7 +91,6 @@ public static String modifyCode(String filePath, String className, List<MethodCo
}



public static List<String> readImports(String code) {
CharSource source = CharSource.wrap(code);
String output = null;
Expand Down Expand Up @@ -145,6 +144,7 @@ public static String removeImports(String code) {

/**
* 是否是class
*
* @param code
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading