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

百度大模型开源

本地启动手册

安装依赖:

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()
相关推荐
大力财经10 小时前
百度斩获大模型中标第一,股价上涨5%
百度
罗光记1 天前
PHP诞生30周年
前端·数据库·百度·facebook·twitter
kebijuelun2 天前
百度文心 4.5 大模型详解:ERNIE 4.5 Technical Report
人工智能·深度学习·百度·语言模型·自然语言处理·aigc
shadowcz0072 天前
奥特曼论人工智能、OpenAI与创业
人工智能·百度
LucianaiB2 天前
百度开源文心4.5系列开源21款模型,实测 ERNIE-4.5-VL-28B-A3B-Paddle 多项评测结果超 Qwen3-235B-A22B
百度·开源·文心大模型·paddle·gitcode
wei_shuo2 天前
百度开源文心 4.5 系列开源大模型 GitCode 本地化部署,硅基流动:文心 vs. DeepSeek vs. Qwen 3.0 深度测评
百度·开源·文心大模型·gitcode
AI生存日记2 天前
百度文心大模型 4.5 系列全面开源 英特尔同步支持端侧部署
人工智能·百度·开源·open ai大模型
国服第二切图仔3 天前
文心开源大模型ERNIE-4.5-0.3B-Paddle私有化部署保姆级教程及技术架构探索
百度·架构·开源·文心大模型·paddle·gitcode
Qiuner3 天前
【源力觉醒 创作者计划】开源、易用、强中文:文心一言4.5或是 普通人/非AI程序员 的第一款中文AI?
人工智能·百度·开源·文心一言·gitcode