1.使用Java来测试连接本地ChatGLM3-6B模型
public class test {
public static void main(String[] args) {
try {
// 创建URL对象
URL url = new URL("http://本地模型的ip地址:8000/v1/chat/completions");
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置连接超时为30秒
connection.setConnectTimeout(300000);
// 设置读取超时为60秒
connection.setReadTimeout(600000);
// 设置请求方法为POST
connection.setRequestMethod("POST");
// 设置请求头的Content-Type为application/json
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// 设置允许输出
connection.setDoOutput(true);
// JSON参数
String jsonParams = "{\n" +
" \"model\": \"chatglm3-6b\",\n" +
" \"messages\": [\n" +
" {\n" +
" \"role\": \"system\",\n" +
" \"content\": \"You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user’s instructions carefully. Respond using markdown.\"\n" +
" },\n" +
" {\n" +
" \"role\": \"user\",\n" +
" \"content\": \"你好,给我讲一个故事,大概100字\"\n" +
" }\n" +
" ],\n" +