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

百度大模型开源

本地启动手册

安装依赖:

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()
相关推荐
羊群智妍14 小时前
2026 AI搜索流量密码:免费GEO监测工具,优化效果看得见
笔记·百度·微信·facebook·新浪微博
陈思杰系统思考Jason18 小时前
系统思考与组织效率
百度·微信·微信公众平台·新浪微博·微信开放平台
marteker2 天前
IAB致力于实现可互操作的媒体测量标准化
搜索引擎·百度·媒体
狒狒热知识3 天前
破局同质化内卷:爱玛2026马年营销,以热爱为刃,铸就行业年轻化标杆
百度·产品运营·营销
zandy10113 天前
AI驱动全球销售商机管理:钉钉DingTalk A1的跨域管理智能解决方案
人工智能·百度·钉钉
陈思杰系统思考Jason3 天前
系统问题误作态度问题
百度·微信·微信公众平台·新浪微博·微信开放平台
屁股割了还要学4 天前
百度网盘网页免vip ---> 高清晰度 + 字幕
经验分享·百度
生活观察站4 天前
新华网×赛迪网双重肯定:销售易AI CRM入选“AI中国”生态范式集
人工智能·百度
D11_5 天前
[特殊字符]️ 5379工具箱 - 全部网站链接汇总
服务器·百度·阿里云·typescript·编辑器