ollama本地部署

0 启动服务

要保证模型一直启动:

OLLAMA_KEEP_ALIVE='-1' ollama serve

不加-1版本,5分钟后下线

ollama serve

1 查看本地模型

ollama list

2 运行大模型

ollama run xxx

Deepseek本地部署+codex使用

0 快速下载

Host node1
    HostName 172.xx.xxx.22
    User root
    Port 22
Host NVIDIA
    HostName 127.0.0.1
    User root
    Port 2222
    ProxyJump node1
    LocalForward 6080 127.0.0.1:6080
    RemoteForward 8888 127.0.0.1:7890
    ServerAliveInterval 30
    ServerAliveCountMax 3
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
export http_proxy=http://127.0.0.1:8888
export https_proxy=http://127.0.0.1:8888
export no_proxy=localhost,127.0.0.1
curl https://pypi.org

1 本地部署

python3 -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V2-Lite-Chat \
    --trust-remote-code \
    --tensor-parallel-size 2 \
    --gpu-memory-utilization 0.8 \
    --max-model-len 16384 \
    --served-model-name deepseek \
    --host 0.0.0.0 \
    --port 8000

2 交互界面

pip3 install openai==2.24.0

chat_ui.py

import streamlit as st
import openai

# 配置OpenAI客户端连接本地vLLM
client = openai.OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="token-abc123"
)

def main():
    st.set_page_config(
        page_title="DeepSeek R1 聊天助手",
        page_icon="🤖",
        layout="wide"
    )
    
    st.title("🤖 DeepSeek R1 聊天助手")
    st.markdown("与本地部署的DeepSeek模型进行对话")
    
    # 初始化会话状态
    if "messages" not in st.session_state:
        st.session_state.messages = []
    
    # 侧边栏配置
    with st.sidebar:
        st.subheader("配置")
        temperature = st.slider("温度", 0.1, 1.0, 0.7, 0.1)
        max_tokens = st.slider("最大生成长度", 100, 2000, 512, 100)
        use_streaming = st.checkbox("启用流式输出", value=True)
        
        if st.button("清空对话历史"):
            st.session_state.messages = []
            st.rerun()
    
    # 显示对话历史
    for message in st.session_state.messages:
        with st.chat_message(message["role"]):
            st.markdown(message["content"])
    
    # 用户输入
    if prompt := st.chat_input("请输入您的问题..."):
        # 添加用户消息
        st.session_state.messages.append({"role": "user", "content": prompt})
        with st.chat_message("user"):
            st.markdown(prompt)
        
        # 生成助手回复
        with st.chat_message("assistant"):
            if use_streaming:
                # 流式输出
                response_placeholder = st.empty()
                full_response = ""
                
                try:
                    response = client.chat.completions.create(
                        model="deepseek",
                        messages=[{"role": "user", "content": prompt}],
                        temperature=temperature,
                        max_tokens=max_tokens,
                        stream=True
                    )
                    
                    for chunk in response:
                        if chunk.choices[0].delta.content is not None:
                            content = chunk.choices[0].delta.content
                            full_response += content
                            response_placeholder.markdown(full_response + "▌")
                    
                    response_placeholder.markdown(full_response)
                    
                except Exception as e:
                    full_response = f"错误: {str(e)}"
                    response_placeholder.markdown(full_response)
            else:
                # 非流式输出
                with st.spinner("思考中..."):
                    try:
                        response = client.chat.completions.create(
                            model="deepseek",
                            messages=[{"role": "user", "content": prompt}],
                            temperature=temperature,
                            max_tokens=max_tokens
                        )
                        full_response = response.choices[0].message.content
                        st.markdown(full_response)
                    except Exception as e:
                        full_response = f"错误: {str(e)}"
                        st.markdown(full_response)
            
            # 添加助手消息到历史
            st.session_state.messages.append({"role": "assistant", "content": full_response})

if __name__ == "__main__":
    main()

3 codex

config.toml

[projects.'C:\Users\HP']
trust_level = "trusted"

[notice.model_migrations]
"gpt-5.3-codex" = "gpt-5.4"

# ================= 新增本地模型配置 =================

# 1. 定义本地大模型的 Provider
[model_providers.local]
name = "Local Model"
base_url = "http://localhost:8000/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

# 2. 定义对应的 Profile (指定使用的模型名称)
[profiles.local]
model_provider = "local"
model = "deepseek"
$env:OPENAI_API_KEY="token-abc123"
codex --profile local

更多推荐