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

百度大模型开源

本地启动手册

安装依赖:

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()
相关推荐
AI360labs_atyun11 小时前
AI教育开启新篇章
人工智能·百度·ai
一壶浊酒..3 天前
python 爬取百度图片
开发语言·python·百度
2401_865273795 天前
郑光荣:守护市井烟火
百度·facebook·paddle·新浪微博·微信开放平台
陈思杰系统思考Jason6 天前
人类真的能“控制自己”吗?
百度·微信·微信公众平台·新浪微博·微信开放平台
卷Java6 天前
百度AI车牌识别配置指南
java·开发语言·百度·uni-app·dubbo·微信公众平台
道可云7 天前
道可云人工智能每日资讯|2025世界智能网联汽车大会将在北京举办
人工智能·百度·汽车·ar·xr·deepseek
你好~每一天11 天前
2025 中小企业 AI 转型:核心岗技能 “怎么证、怎么用”?
人工智能·百度·数据挖掘·数据分析·职业·转行
三天不学习15 天前
uniapp集成语音识别与图片识别集成方案【百度智能云】
百度·uni-app·语音识别
semantist@语校15 天前
语校网500所里程碑:日本语言学校数据库的标准化与可追溯机制
大数据·数据库·人工智能·百度·语言模型·oracle·github
KKKlucifer17 天前
IDC发布AI+政务、财政、应急三大市场空间与厂商份额报告
人工智能·百度·政务