在Java项目中集成ChatGLM3-6B模型

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" +
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值