百度大模型开源,俩条命令、本地启动

百度大模型开源

本地启动手册

安装依赖:

bash 复制代码
python -m pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/

python -m pip install fastdeploy-gpu -i https://www.paddlepaddle.org.cn/packages/stable/fastdeploy-gpu-80_90/ --extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

apt install libgomp1

启动 API

bash 复制代码
python -m fastdeploy.entrypoints.openai.api_server \
       --model baidu/ERNIE-4.5-0.3B-Paddle \
       --port 8180 \
       --metrics-port 8181 \
       --engine-worker-queue-port 8182 \
       --max-model-len 32768 \
       --max-num-seqs 32

大概等待10分钟左右

测试 Python 代码

py 复制代码
import requests
import json

url = "http://127.0.0.1:8180/v1/chat/completions"
headers = {"Content-Type": "application/json"}

data = {
    "model": "baidu/ERNIE-4.5-0.3B-PT",
    "messages": [
        {"role": "user", "content": "我是仕宇2050,你帮我写一个Python函数判断字符串是否为回文串"}
    ],
    "temperature": 0.7
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json()["choices"][0]["message"]["content"])

模型开源地址:https://ai.gitcode.com/theme/1939325484087291906

视频演示: 全网同名 #JavaPub #仕宇2050

循环对话的python代码

py 复制代码
import requests
import json

def chat():
    url = "http://127.0.0.1:8180/v1/chat/completions"
    headers = {
        "Content-Type": "application/json"
    }
    model = "baidu/ERNIE-4.5-0.3B-PT"
    
    # 保存对话历史
    messages = []

    print("开始对话吧!(输入 'exit' 或 'quit' 退出)")
    while True:
        user_input = input("\n你:")
        if user_input.lower() in {"exit", "quit"}:
            print("结束对话。")
            break

        # 添加用户消息到对话历史
        messages.append({"role": "user", "content": user_input})

        # 构建请求体
        data = {
            "model": model,
            "messages": messages
        }

        try:
            response = requests.post(url, headers=headers, data=json.dumps(data))
            response.raise_for_status()
            result = response.json()

            if "choices" in result and len(result["choices"]) > 0:
                ai_message = result["choices"][0]["message"]["content"]
                print("AI:", ai_message)

                # 将AI的回复加入对话历史
                messages.append({"role": "assistant", "content": ai_message})
            else:
                print("AI 没有返回内容。")

        except requests.exceptions.RequestException as e:
            print(f"请求错误: {e}")
        except json.JSONDecodeError:
            print(f"JSON解析错误,响应内容: {response.text}")
        except Exception as e:
            print(f"发生错误: {e}")

if __name__ == "__main__":
    chat()
相关推荐
YG亲测源码屋5 小时前
新手做网站如何被百度快速收录教程
百度·百度收录·快速收录
罗光记18 小时前
Quantinuum 发布新型量子计算机“Helios“
数据库·经验分享·其他·百度·twitter
oil欧哟19 小时前
文心 5.0 来了,百度大模型的破局之战
前端·人工智能·百度·prompt
YG亲测源码屋20 小时前
怎么让自己的网址被百度收录(网站如何被百度收录进去)
java·百度·dubbo
YG亲测源码屋1 天前
[SEO]什么是百度快速收录?如何优先获得快速收录权益?
百度·dubbo
GitCode官方1 天前
GitCode 同步发布百度 ERNIE-4.5-VL-28B-A3B-Thinking 多模态大模型
百度·gitcode
CoderYanger2 天前
前端基础——CSS练习项目:百度热榜实现
开发语言·前端·css·百度·html·1024程序员节
野豹商业评论2 天前
三次更名的背后:百度AI的定位困惑
人工智能·百度
YG亲测源码屋2 天前
在百度seo快速收录要求是什么 有哪些
百度·seo
YG亲测源码屋2 天前
如何让百度快速大量收录 如何增加百度收录量的方法有哪些
百度·百度收录·快速收录