<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title><![CDATA[灰度发布]]></title> 
<atom:link href="https://www.mysen.top/rss.php" rel="self" type="application/rss+xml" />
<description><![CDATA[]]></description>
<link>https://www.mysen.top/</link>
<language>zh-cn</language>
<generator>emlog</generator>

<item>
    <title>PVE直通显卡到ubuntu24.04虚拟机</title>
    <link>https://www.mysen.top/?post=26</link>
    <description><![CDATA[<p><strong>驱动重装</strong><br />
在ubuntu虚拟机上进行以下操作：</p>
<ol>
<li>卸载现有驱动：
<pre><code class="language-bash">sudo apt --purge remove nvidia*
sudo apt autoremove</code></pre></li>
<li>通过<code>ubuntu-drivers autoinstall</code>自动安装或从官网下载对应版本驱动</li>
<li>安装NVIDIA容器工具包，以实现Docker对GPU的调用
<pre><code class="language-bash"># 添加仓库
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# 安装工具包，以实现Docker对GPU的调用
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker</code></pre></li>
<li>编辑/etc/docker/daemon.json文件
<pre><code class="language-bash">{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
  "path": "/usr/bin/nvidia-container-runtime",
  "runtimeArgs": []
}
}
}</code></pre></li>
<li>执行sudo systemctl restart docker重启服务</li>
<li>安装完成后验证：nvidia-smi</li>
<li>最后重启系统使更改生效</li>
</ol>]]></description>
    <pubDate>Fri, 17 Oct 2025 23:30:11 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/?post=26</guid>
</item>
<item>
    <title>Ubuntu24.04安装docker compose</title>
    <link>https://www.mysen.top/?post=23</link>
    <description><![CDATA[<p>安装部署：</p>
<ol>
<li>若之前尝试过安装，先移除残留配置
<pre><code class="language-bash">sudo apt remove docker-compose
sudo rm -f /etc/apt/sources.list.d/docker.list</code></pre></li>
<li>添加Docker官方GPG密钥
<pre><code class="language-bash">sudo mkdir -m 0755 -p /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc</code></pre>
<p>3.‌ 配置官方仓库</p>
<pre><code class="language-bash">echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable" | sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null</code></pre></li>
<li>刷新并安装，‌检查版本：docker compose version
<pre><code class="language-bash">sudo apt update
sudo apt install docker-compose-plugin</code></pre></li>
</ol>
<p>基础操作命令：</p>
<ol>
<li>‌停止所有运行中的容器
<pre><code class="language-bash">docker stop $(docker ps -q)</code></pre></li>
<li>删除所有容器（包括已停止的）
<pre><code class="language-bash">docker rm $(docker ps -aq)</code></pre></li>
<li>强制删除方案，针对卡死的容器
<pre><code class="language-bash">docker rm -f $(docker ps -aq)</code></pre></li>
<li>执行docker-compose.yaml文件
<pre><code class="language-bash">docker compose up -d</code></pre>
<p>配置国内镜像源：</p></li>
<li>创建文件
<pre><code class="language-bash">nano  /etc/docker/daemon.json</code></pre></li>
<li>添加加速地址
<pre><code class="language-json">{
"registry-mirrors":[
"https://docker.xuanyuan.me",
"https://docker.1ms.run",
"https://docker.m.daocloud.io"
]
}</code></pre></li>
<li>加载重启服务
<pre><code class="language-bash">systemctl daemon-reload &amp;&amp; systemctl restart docker</code></pre></li>
<li>验证配置
<pre><code class="language-bash">docker info | grep -A 10 -i "registry mirrors"</code></pre></li>
</ol>
<p>安装部署dify详见参考文档https://github.com/langgenius/dify/blob/main/README_CN.md<br />
dify使用手册https://docs.dify.ai/zh-hans/introduction<br />
安装部署coze详见参考文档https://github.com/coze-dev/coze-studio/blob/main/README.zh_CN.md</p>
<p>注：若需保留环境变量灵活性，建议在.env文件中统一管理IP配置。（127.0.0.1改成0.0.0.0，这样局域网内主机能访问）</p>
<p>coze开源调用本地ollama模型：</p>
<ol>
<li>拉取模型，确保本机能运行</li>
<li>进入到下载的coze-studio文件目录下/backend/conf/model/template中，复制并修改*_ollama.yaml文件到/coze-studio/backend/conf/model/下，名字修改为模型名称，编辑复制过来的yaml文件，修改里面的name、meta.conn_config.model、meta.conn_config.base_url即可</li>
<li>进入coze-studio的docker目录重启服务，使配置生效
<pre><code class="language-bash">docker compose --profile "*" restart coze-server</code></pre></li>
</ol>]]></description>
    <pubDate>Fri, 12 Sep 2025 18:20:36 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/?post=23</guid>
</item>
<item>
    <title>大模型应用的技术架构</title>
    <link>https://www.mysen.top/?post=22</link>
    <description><![CDATA[<p>AGI架构商业落地</p>
<p>大模型应用的技术架构<br />
AI&gt;software&gt;world<br />
AI世界分三类人：AI使用者、AI产品开发者、基础大模型相关</p>
<p>调用大模型，相当于调动一个人<br />
TA懂人话<br />
TA说人话<br />
TA直接给结果，但不一定对</p>
<p>核心心法：把AI当人看<br />
范式变化所在，所有方案的源泉</p>
<table>
<thead>
<tr>
<th style="text-align: center;">要解决的问题</th>
<th style="text-align: center;">举例</th>
<th style="text-align: center;">人的思路</th>
<th style="text-align: center;">大模型的思路</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">布置任务</td>
<td style="text-align: center;">查数据</td>
<td style="text-align: center;">对话</td>
<td style="text-align: center;">Prompt Engineering（提示词工程）</td>
</tr>
<tr>
<td style="text-align: center;">新知识/记不住</td>
<td style="text-align: center;">报税</td>
<td style="text-align: center;">学习资料</td>
<td style="text-align: center;">RAG（检索增强生成）</td>
</tr>
<tr>
<td style="text-align: center;">深度理解</td>
<td style="text-align: center;">学新语言</td>
<td style="text-align: center;">好好学习</td>
<td style="text-align: center;">Fine-tuning（微调）</td>
</tr>
<tr>
<td style="text-align: center;">对接外界</td>
<td style="text-align: center;">获取天气</td>
<td style="text-align: center;">各种工具</td>
<td style="text-align: center;">Function Calling（函数调用，对接外部主动性，调用API）</td>
</tr>
<tr>
<td style="text-align: center;">解决复杂问题</td>
<td style="text-align: center;">工程项目</td>
<td style="text-align: center;">能力综合</td>
<td style="text-align: center;">Agent（智能体）</td>
</tr>
</tbody>
</table>
<p>给大模型布置任务-Prompt Engineering（提示词工程）<br />
适用场景：知识问答、情报分析、写作、编程、文本加工处理。。。<br />
应用程序→prompt→大模型→response→应用程序<br />
人和人对话，程序和LLM对话都要：指令具体、信息丰富、尽量少歧义</p>
<p>给大模型新知识-RAG（检索增强生成）（即时性，现找）<br />
适用场景：智能知识库、智能诊断、数字分身、带例子的Prompt Eng.（Few-shot）...<br />
人找知识，会查资料，LLM找知识，要查向量数据库，向量检索可以找到相似的<br />
传统数据库查找数据是匹配，存在不匹配的情况就无法查找<br />
向量数据库，维度查找，使用余弦算法越小越相似，基于相似度，类似语意查找，相似即可<br />
应用程序→知识线索→（知识→Embeddings→向量数据库）→相关知识→Prompt→大模型→response→应用程序<br />
接口只有提示词，和大模型互动</p>
<p>让大模型深度理解知识-Fine-tuning（微调）（反应快，提前训练）全量或非全量<br />
适用场景：智能知识库、智能诊断、数字分身、带例子的Prompt Eng.（Few-shot）...<br />
人阅读、背诵、理解资料，LLM进行增量机器学习训练<br />
应用程序→知识线索→（知识→Embeddings→向量数据库）→相关知识→Prompt→垂直大模型（Fine-tuning（Retieval-Augmented Generation（知识→Embeddings→向量数据库）））→基础大模型→垂直大模型→response→应用程序</p>
<p>让大模型对接外界-Function Calling（调用函数、APIs（Agent用JSON格式反向提出要求）、工具）<br />
适用场景：智能助手、下一代搜索引擎、机器人、Agent...<br />
推理能力是智能体的核心技能之一，<br />
应用程序→prompt→垂直大模型→Agent（基础大模型）→Function Calling→应用程序→调用→APIs→返回结果→prompt→大模型→response→应用程序</p>
<p>大模型应用的知识体系<br />
场景：智能客服 智能知识库 智能数据分析 智能情报分析 智能助手</p>
<table>
<thead>
<tr>
<th style="text-align: center;">类别</th>
<th style="text-align: center;">原理</th>
<th style="text-align: center;">实战</th>
<th style="text-align: center;">认知</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">prompt（提示词）</td>
<td style="text-align: center;">LLM生成原理 高质量prompt原理</td>
<td style="text-align: center;">基础要素 格式约束 风格控制 思维链 自洽性 思维树 指令调优</td>
<td style="text-align: center;">把AI当人看</td>
</tr>
<tr>
<td style="text-align: center;">AI编程</td>
<td style="text-align: center;">AI编程是LLM能力天花板</td>
<td style="text-align: center;">通义灵码</td>
<td style="text-align: center;">AI提效定律 AI能力定律</td>
</tr>
<tr>
<td style="text-align: center;">API</td>
<td style="text-align: center;">用微调提升 prompt稳定性</td>
<td style="text-align: center;">生成式API 对话式API Function Calling fine-tuning</td>
<td style="text-align: center;">自然语言连接一切</td>
</tr>
<tr>
<td style="text-align: center;">RAG</td>
<td style="text-align: center;">Embeddings</td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr>
<td style="text-align: center;">开发框架和工具栈</td>
<td style="text-align: center;">Agent</td>
<td style="text-align: center;"></td>
<td style="text-align: center;">多框架组合开发 Prompt和代码分离</td>
</tr>
<tr>
<td style="text-align: center;">Fine-tuning</td>
<td style="text-align: center;">机器学习 大模型训练 微调原理</td>
<td style="text-align: center;">求解器 损失函数 超参</td>
<td style="text-align: center;">微调仍是炼丹</td>
</tr>
<tr>
<td style="text-align: center;">多模态</td>
<td style="text-align: center;">特征对齐</td>
<td style="text-align: center;"></td>
<td style="text-align: center;">传统CV模型仍有价值</td>
</tr>
<tr>
<td style="text-align: center;">产品</td>
<td style="text-align: center;">商业逻辑 用户体验</td>
<td style="text-align: center;">需求分析 与人沟通 产品迭代 产品运营</td>
<td style="text-align: center;">AI产品设计原则 产品经理调prompt 产品经理实现demo</td>
</tr>
<tr>
<td style="text-align: center;">交付</td>
<td style="text-align: center;"></td>
<td style="text-align: center;">云厂商选型 算法备案</td>
<td style="text-align: center;">向量数据库选项原则</td>
</tr>
</tbody>
</table>
<p>官网、熟悉名词术语、要有知识体系、系统学习能力</p>]]></description>
    <pubDate>Fri, 05 Sep 2025 19:52:22 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/?post=22</guid>
</item>
<item>
    <title>100个IT运维知识</title>
    <link>https://www.mysen.top/preserve.html</link>
    <description><![CDATA[<p><img src="https://www.mysen.top/content/uploadfile/202509/e6df1756974081.jpeg" alt="运维知识1" title="运维知识1" /><br><br />
<img src="https://www.mysen.top/content/uploadfile/202509/3f561756974081.jpeg" alt="运维知识2" title="运维知识2" /><br><br />
<img src="https://www.mysen.top/content/uploadfile/202509/20941756974081.jpeg" alt="运维知识3" title="运维知识3" /><br><br />
<img src="https://www.mysen.top/content/uploadfile/202509/31331756974081.jpeg" alt="运维知识4" title="运维知识4" /><br><br />
<img src="https://www.mysen.top/content/uploadfile/202509/4caa1756974081.jpeg" alt="运维知识5" title="运维知识5" /><br><br />
<img src="https://www.mysen.top/content/uploadfile/202509/2b591756974081.jpeg" alt="运维知识6" title="运维知识6" /></p>]]></description>
    <pubDate>Thu, 04 Sep 2025 16:28:00 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/preserve.html</guid>
</item>
<item>
    <title>Ubuntu 24.04搭建高可用Harbor私有镜像仓库</title>
    <link>https://www.mysen.top/harbor.html</link>
    <description><![CDATA[<h1>一、 确认配置</h1>
<ul>
<li>
<p>两台镜像仓库，模拟生产环境高可用</p>
<table>
<thead>
<tr>
<th style="text-align: center;">节点类型</th>
<th style="text-align: center;">数量</th>
<th style="text-align: center;">CPU</th>
<th style="text-align: center;">内存</th>
<th style="text-align: center;">磁盘</th>
<th style="text-align: center;">主机名</th>
<th style="text-align: center;">IP</th>
<th style="text-align: center;">关键服务/组件</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">私有镜像库节点</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">4核</td>
<td style="text-align: center;">4G</td>
<td style="text-align: center;">40G</td>
<td style="text-align: center;">harbor1,harbor2</td>
<td style="text-align: center;">10.31.3.241-242/16;<br>10.31.3.250/16(VIP)</td>
<td style="text-align: center;">Harbor, contained, cni,<br> nerdctl, HAProxy, Keepalived</td>
</tr>
</tbody>
</table>
</li>
<li>
<p>没有说明是某个节点单独运行的，需要每个节点都执行</p>
</li>
<li>
<p>主要组件版本：harbor 2.13.2，containerd 1.7.27， cni 1.7.1， nerdctl 2.1.3</p>
</li>
</ul>
<h1>二、 配置环境</h1>
<h2>1. 基础环境配置</h2>
<pre><code class="language-bash"># 1. 配置阿里云Ubuntu镜像源
sudo sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list
sudo sed -i 's|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list

# 2. 安装必要依赖
sudo apt update &amp;&amp; sudo apt upgrade -y
sudo apt install -y  chrony containerd iptables haproxy keepalived rsync

# 3. 配置时间同步，timedatectl查看当前时间/时区
sudo timedatectl set-timezone Asia/Shanghai
sudo systemctl enable chrony &amp;&amp; sudo systemctl start chrony

# 4.1 设置主节点主机名为harbor1
sudo hostnamectl set-hostname harbor1
# 4.2 设置备节点主机名为harbor2
sudo hostnamectl set-hostname harbor2

# 5.1 harbor1编辑固定IP为10.31.3.241，也可在路由器上操作mac与IP的绑定
cat &lt;&lt;EOF | sudo tee /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    enp6s18:
      dhcp4: no
      addresses: [10.31.3.241/16]
      routes:
        - to: default
          via: 10.31.0.1
      nameservers:
        addresses: [10.31.0.1, 223.5.5.5]
EOF

# 5.2 harbor2编辑固定IP为10.31.3.242，应用网络修改运行netplan apply
cat &lt;&lt;EOF | sudo tee /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    enp6s18:
      dhcp4: no
      addresses: [10.31.3.242/16]
      routes:
        - to: default
          via: 10.31.0.1
      nameservers:
        addresses: [10.31.0.1, 223.5.5.5]
EOF

# 6. 添加主机解析，10.31.3.250为后面负载均衡虚拟的VIP地址，确认局域网内没有被占用
cat &lt;&lt;EOF | sudo tee -a /etc/hosts
10.31.3.241 harbor1
10.31.3.242 harbor2
10.31.3.250 harbor.mysen.top
EOF

# 7. 配置ssh启用root密码登录，方便后续传输证书
echo "PermitRootLogin yes" | sudo tee -a /etc/ssh/sshd_config
systemctl restart ssh
passwd root #设置root密码</code></pre>
<h2>2. ‌配置containerd‌</h2>
<pre><code class="language-bash"># 1. 生成默认配置再修改部分参数，验证安装containerd --version，重启容器systemctl restart containerd
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's|SystemdCgroup = false|SystemdCgroup = true|g' /etc/containerd/config.toml
sudo sed -i 's|registry.k8s.io/pause:3.8|registry.aliyuncs.com/google_containers/pause:3.10|g' /etc/containerd/config.toml

# 2. 安装加载cni网络插件（自行科学上网）
wget https://github.com/containernetworking/plugins/releases/download/v1.7.1/cni-plugins-linux-amd64-v1.7.1.tgz
sudo mkdir -p /opt/cni/bin &amp;&amp; sudo tar -xzvf cni-plugins-linux-amd64-v1.7.1.tgz -C /opt/cni/bin

# 3. 安装配置nerdctl‌，验证安装运行nerdctl --version
wget https://github.com/containerd/nerdctl/releases/download/v2.1.3/nerdctl-2.1.3-linux-amd64.tar.gz
sudo tar Cxzvvf /usr/local/bin nerdctl-2.1.3-linux-amd64.tar.gz
sudo nerdctl network create --subnet 172.20.0.0/16 harbor-net

# 4. 创建compose，验证compose version，替代docker-compose
sudo tee /usr/local/bin/compose &lt;&lt;'EOF'
#!/bin/bash
nerdctl compose "$@"
EOF
sudo chmod +x /usr/local/bin/compose

# 5. 环境变量配置，添加必要别名以及创建符号链接，替代docker命令
echo "alias docker='nerdctl'" &gt;&gt; ~/.bashrc
echo "alias docker-compose='nerdctl compose'" &gt;&gt; ~/.bashrc
source ~/.bashrc
sudo ln -s /usr/local/bin/nerdctl /usr/local/bin/docker
sudo ln -s /usr/local/bin/nerdctl-compose /usr/local/bin/docker-compose</code></pre>
<h2>3. 生成证书</h2>
<pre><code class="language-bash"># 1. 创建证书目录并进入(两个节点都创建目录后，证书的后续2-7步操作都在harbor1节点上操作)
sudo mkdir -p /data/cert &amp;&amp; cd /data/cert

# 2. 生成CA证书‌，OpenSSL 3.0+生成的私钥默认使用PKCS#8格式，而Harbor 2.13.2需要PKCS#1格式
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ca.key -out ca.crt -subj "/CN=harbor.mysen.top"

# 3. ‌生成服务器证书‌
openssl req -new -newkey rsa:2048 -nodes -keyout harbor.mysen.top.key -out harbor.mysen.top.csr -subj "/CN=harbor.mysen.top"

# 4. 生成x509 v3扩展文件
cat &gt; v3.ext &lt;&lt;-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=harbor.mysen.top
IP.1 = 10.31.3.250
IP.2 = 10.31.3.241
IP.3 = 10.31.3.242
EOF

# 5. 使用CA签发证书
openssl x509 -req -days 365 -extfile v3.ext -in harbor.mysen.top.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out harbor.mysen.top.crt

# 6. 合并证书为PEM格式，并设置权限，harbor.mysen.top.pem用于haproxy，harbor.pem用于harbor.yml
cat harbor.mysen.top.key harbor.mysen.top.crt &gt; harbor.mysen.top.pem
chmod 600 harbor.mysen.top.pem
cat ca.crt harbor.mysen.top.crt &gt; harbor.pem
chmod 600 harbor.pem

# 7. 同步证书到harbor2节点
rsync -avz /data/cert/ root@harbor2:/data/cert/

# 8. 两个节点添加CA证书信任
sudo cp /data/cert/ca.crt /usr/local/share/ca-certificates/
sudo cp /data/cert/harbor.mysen.top.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates --fresh</code></pre>
<h2>4. 部署Harbor</h2>
<pre><code class="language-bash"># 1. 下载Harbor离线安装包，解压并进入目录
sudo wget https://github.com/goharbor/harbor/releases/download/v2.13.2/harbor-offline-installer-v2.13.2.tgz
sudo tar xvf harbor-offline-installer-v2.13.2.tgz &amp;&amp; cd harbor

# 2. 复制默认配置文件，修改hostname为harbor.mysen.top，修改https证书路径
cp harbor.yml.tmpl harbor.yml
sudo sed -i 's|reg.mydomain.com|harbor.mysen.top|g' /root/harbor/harbor.yml
sudo sed -i 's|/your/certificate/path|/data/cert/harbor.pem|g' /root/harbor/harbor.yml
sudo sed -i 's|/your/private/key/path|/data/cert/harbor.mysen.top.key|g' /root/harbor/harbor.yml

# 3. 使用创建的网络配置
cat &lt;&lt;EOF | sudo tee -a /root/harbor/harbor.yml
network:
  name: harbor-net
  external: true
EOF

# 4. 修改Harbor安装脚本，docker-compoes替换为compose，注释掉Docker检查部分
sudo sed -i 's|=docker-|=|g' /root/harbor/install.sh
sudo sed -i 's/^.*check_docker.*$/#&amp;/' /root/harbor/install.sh
sudo sed -i 's|down|stop \&amp;\&amp; $DOCKER_COMPOSE rm|g' /root/harbor/install.sh

# 5. 修改prepare脚本，替换docker为nerdctl
sudo sed -i 's|docker|nerdctl|g' /root/harbor/prepare

# 6. 使用nerdctl解压生成本地镜像文件，防止在线拉取镜像
nerdctl load -i harbor.v2.13.2.tar.gz

# 7. 安装并启动Harbor，验证在局域网内其他主机上通过浏览器访问https://10.31.3.241或242
sudo ./prepare &amp;&amp; sudo ./install.sh</code></pre>
<h2>5. 负载均衡</h2>
<pre><code class="language-bash"># 1. 配置HAProxy，stats auth后为账号密码
cat &lt;&lt;EOF | sudo tee -a /etc/haproxy/haproxy.cfg

frontend harbor-https
    bind *:443 ssl crt /data/cert/harbor.mysen.top.pem
    mode http
    option httplog
    option forwardfor
    default_backend harbor-backend

backend harbor-backend
    mode http
    balance roundrobin
    server harbor1 10.31.3.241:443 check
    server harbor2 10.31.3.242:443 check

listen stats
    bind *:8080
    mode http
    stats enable
    stats uri /haproxy?stats
    stats realm Haproxy\ Statistics
    stats auth mysen:kubernetes
    stats hide-version
    stats refresh 30s
EOF

# 2. 检查配置语法
sudo haproxy -c -f /etc/haproxy/haproxy.cfg

# 3.  启动HAProxy，验证运行systemctl status haproxy
sudo systemctl restart haproxy &amp;&amp; sudo systemctl enable haproxy

# 4.1 配置主节点 (harbor1)的keepalived，根据实际网卡名称修改enp6s18，priority为优先级
sudo tee /etc/keepalived/keepalived.conf &lt;&lt;-'EOF'
global_defs {
    router_id harbor_ha_1
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER
    interface enp6s18
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass kubernetes
    }
    virtual_ipaddress {
        10.31.3.250/16
    }
    track_script {
        chk_haproxy
    }
}
EOF

# 4.2 配置备节点（harbor2）keepalived的配置文件，auth_pass后为密码，备节点的优先级低于主节点
sudo tee /etc/keepalived/keepalived.conf &lt;&lt;-'EOF'
global_defs {
    router_id harbor_ha_2
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp6s18
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass kubernetes
    }
    virtual_ipaddress {
        10.31.3.250/16
    }
    track_script {
        chk_haproxy
    }
}
EOF

# 5. 启动Keepalived，验证运行sudo systemctl status keepalived
sudo systemctl restart keepalived &amp;&amp; sudo systemctl enable keepalived</code></pre>
<h2>6. 部署验证</h2>
<pre><code class="language-bash"># 1. 完整重启服务，确保依赖服务正确启动，先停止haproxy后，进入/root/harbor/目录再执行。
sudo systemctl stop haproxy
cd /root/harbor/ &amp;&amp; docker-compose down &amp;&amp; docker-compose up -d
sudo systemctl restart haproxy

# 2. 证书验证
md5sum /data/cert/harbor.mysen.top.pem  # 传输后验证文件完整性，两个节点运行对比
openssl verify -CAfile ca.crt harbor.mysen.top.crt  # 验证证书链完整性,OK正常
openssl x509 -in /etc/harbor/ssl/harbor.crt -noout -text | grep -A1 "Subject Alternative Name"  # 验证SAN扩展是否包含所有IP和域名
curl https://10.31.3.242  # 在harbor1上运行，查看返回是否为html标签
curl https://10.31.3.241  # 在harbor2上运行，查看返回是否为html标签
openssl s_client -connect 10.31.3.242:443 -servername harbor.mysen.top | openssl x509 -noout -text  # 在harbor1上运行与下一条命令对比，应该完全一致
openssl s_client -connect 10.31.3.241:443 -servername harbor.mysen.top | openssl x509 -noout -text  # 在harbor2上运行与上一条命令对比，应该完全一致
openssl s_client -connect 10.31.3.250:443 -servername harbor.mysen.top | openssl x509 -noout -text  # 检查HAProxy是否与harbor1/2一致</code></pre>
<h1>三、 使用手册</h1>
<h2>1. 镜像同步</h2>
<p><strong>还存在复制问题没有解决？？</strong><br />
<strong>其他仓库推送到harbor提示证书问题？？</strong></p>
<pre><code class="language-bash"># 在harbor1的web界面操作：
1.1 在局域网内其他电脑上访问harbor1仓库管理地址https://10.31.3.241（默认账户密码为：admin/Harbor12345）
1.2 点击系统管理的子菜单→仓库管理→新建目标
目标名：harbor2
目标url：https://10.31.3.242
不用输入访问ID和密码，点击测试连接，确定。
1.3 点击系统管理的子菜单→复制管理→新建规则
名称：harbor2
目标仓库：harbor2-https://10.31.3.242
触发模式：事件驱动
勾选删除本地资源时同时也删除远程的资源
其他默认，也可根据需要修改。

# 在harbor2的web界面操作：
1.1 在局域网内其他电脑上访问harbor2仓库管理地址https://10.31.3.242（默认账户密码为：admin/Harbor12345）
1.2 点击系统管理的子菜单→仓库管理→新建目标
目标名：harbor1
目标url：https://10.31.3.241
不用输入访问ID和密码，点击测试连接，确定。
1.3 点击系统管理的子菜单→复制管理→新建规则
名称：harbor1
目标仓库：harbor2-https://10.31.3.241
触发模式：事件驱动，勾选删除本地资源时同时也删除远程的资源
其他默认，也可根据需要修改。</code></pre>
<h2>2. 镜像拉取</h2>
<pre><code class="language-bash"># 1. 获取Calico 3.30.2官方镜像，typha为大规模集群需要
nerdctl pull calico/cni:v3.30.2
nerdctl pull calico/node:v3.30.2
nerdctl pull calico/kube-controllers:v3.30.2
nerdctl pull calico/pod2daemon-flexvol:v3.30.2
nerdctl pull calico/typha:v3.30.2</code></pre>
<h2>3. 镜像推送</h2>
<pre><code class="language-bash"># 2. 重新标记并推送至Harbor（根据实际主机名修改）
nerdctl tag calico/cni:v3.30.2 harbor.mysen.pro/library/calico-cni:v3.30.2
nerdctl tag calico/node:v3.30.2 harbor.mysen.pro/library/calico-node:v3.30.2
nerdctl tag calico/kube-controllers:v3.30.2 harbor.mysen.pro/library/calico-kube-controllers:v3.30.2
nerdctl tag calico/pod2daemon-flexvol:v3.30.2 harbor.mysen.pro/library/calico-pod2daemon-flexvol:v3.30.2
nerdctl tag calico/typha:v3.30.2 harbor.mysen.pro/library/calico-typha:v3.30.2

# 3. 推送镜像(需先登录Harbor)
nerdctl login harbor.mysen.pro
nerdctl push harbor.mysen.pro/library/calico-cni:v3.30.2
nerdctl push harbor.mysen.pro/library/calico-node:v3.30.2
nerdctl push harbor.mysen.pro/library/calico-kube-controllers:v3.30.2
nerdctl push harbor.mysen.pro/library/calico-pod2daemon-flexvol:v3.30.2
nerdctl push harbor.mysen.pro/library/calico-typha:v3.30.2</code></pre>
<h2>4. 配置k8s拉取私有镜像</h2>
<h1>四、 其他事项</h1>
<h2>1. 证书续期</h2>
<h2>2. 安全加固</h2>
<h2>3. 监控维护</h2>]]></description>
    <pubDate>Sun, 03 Aug 2025 05:26:36 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/harbor.html</guid>
</item>
<item>
    <title>FRP内网穿透之1panel篇</title>
    <link>https://www.mysen.top/frp.html</link>
    <description><![CDATA[<h2>搭建目的</h2>
<p><strong>为了能远程家里电脑，同时映射web网站服务。</strong></p>
<h2>拓扑图</h2>
<p><img src="https://www.mysen.top/content/uploadfile/202508/b1011756281832.png" alt="FRP拓扑图" title="FRP拓扑图" /></p>
<h2>配置清单</h2>
<table>
<thead>
<tr>
<th style="text-align: center;">硬件</th>
<th style="text-align: center;">配置建议</th>
<th style="text-align: center;">推荐配置</th>
<th style="text-align: center;">组件服务</th>
<th style="text-align: center;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">路由器</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">连接互联网，光猫即可</td>
</tr>
<tr>
<td style="text-align: center;">交换机</td>
<td style="text-align: center;">至少2个万兆电口或光口</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">负责局域网内数据交换</td>
</tr>
<tr>
<td style="text-align: center;">服务器</td>
<td style="text-align: center;">万兆电口或光口</td>
<td style="text-align: center;">24核/128G/256G+1T</td>
<td style="text-align: center;">pve<br>windows专业版<br>ubuntu24.04</td>
<td style="text-align: center;">也可以自组海洋垃圾</td>
</tr>
<tr>
<td style="text-align: center;">NAS存储</td>
<td style="text-align: center;">万兆电口或光口</td>
<td style="text-align: center;">10核/8G/4T+4T</td>
<td style="text-align: center;">docker</td>
<td style="text-align: center;">Raid 1</td>
</tr>
<tr>
<td style="text-align: center;">云服务</td>
<td style="text-align: center;">阿里云ECS</td>
<td style="text-align: center;">2核/2G/20G</td>
<td style="text-align: center;">ubuntu24.04<br>1panel</td>
<td style="text-align: center;">买OSS资源包做好快照备份</td>
</tr>
</tbody>
</table>
<h2>局域网搭建</h2>
<p><strong>根据需求及现有设备，采购配置缺少的设备，确保局域网内设备之间能通信。</strong></p>
<h3>服务器配置</h3>
<p><strong>1. 服务器部署Proxmox VE，具体部署流程请点<a href="https://www.mysen.top/pve.html" title="部署PVE">这里</a>。</strong></p>
<ol start="2">
<li>上传windows的ISO以及ubuntu24.04的ISO文件至PVE。</li>
<li>新建虚拟机安装windows系统。</li>
<li>开启远程桌面服务。</li>
<li>新建虚拟机安装ubuntu系统。</li>
<li>部署1panel管理系统。</li>
<li>安装frpc客户端应用。
<h3>NAS存储配置</h3></li>
<li>配置阵列raid 1</li>
<li>启用docker与NFS服务。</li>
<li>拉取jlesage/firefox镜像。</li>
<li>部署火狐浏览器容器。</li>
</ol>
<h2>云服务配置</h2>
<p>1、带固定IP的云服务器（阿里云、腾讯云、百度云等等）</p>
<img src="https://www.mysen.top/content/uploadfile/202507/e3721753842325.png" alt="aliyun.png" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<p>2、局域网内能部署docker容器的设备（主机、NAS、路由器等等）<br />
以阿里云为例：<br />
1、创建一个价格最优惠的实例就行（推荐部署Ubuntu22.04 64位 UEFI版），ecs.e-c1m1.large 20G大概26元/月</p>
<img src="/content/uploadfile/202507/e4d31753111894.png" alt="阿里云服务器.png"  width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<p>（图为直接买三年的价格算下来差不多12块/月，2025年7月21日的价格）<br />
1、等待自动部署开机，点击云服务器管理控制台的远程连接登录进系统。<br />
2、安装<a href="https://1panel.cn/docs/v2/installation/online_installation/#1" target="_blank" rel="noopener noreferrer">1panel社区版</a>（注意配置登录端口和路径），完成后通过 <code>http://公网IP:端口/路径</code> 访问1panel管理面板，在应用商店中安装frp服务端实用工具和OpenResty web服务器。<br />
3、根据frp服务端配置的两个端口，在阿里云实例网络与安全中，配置入方向规则。<br />
局域网内主机（联网、linux系统）：<br />
1、安装1panel社区版，部署frp客户端（端口那些和阿里云的一致），部署需要穿透到外网访问的服务。<br />
2、修改frpc.toml文件，添加需要映射的配置信息，重启frp客户端。<br />
阿里云OpenResty：<br />
1、申请免费SSL证书。<br />
2、添加网站反向代理。<br />
注：自行申请域名以及备案。<br />
验证：输入域名访问测试。</p>]]></description>
    <pubDate>Mon, 21 Jul 2025 21:45:54 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/frp.html</guid>
</item>
<item>
    <title>AI大模型基本原理及阿里百炼API调用</title>
    <link>https://www.mysen.top/api.html</link>
    <description><![CDATA[<h2>AIGC的发展历程</h2>
<h3>从GPT1到GPT4</h3>
<ol>
<li><strong>GPT-1（2018年）</strong><br />
基于12层Transformer解码器架构，参数量1.17亿，首次采用无监督预训练+微调范式，在文本生成任务中展现基础语言理解能力。</li>
<li><strong>GPT-2（2019年）</strong><br />
参数量增至15亿，训练数据达40GB，证明模型规模扩大可显著提升零样本任务表现，生成文本连贯性增强。</li>
<li><strong>GPT-3（2020年）</strong><br />
参数量突破1750亿，引入Few-shot学习能力，支持代码生成等复杂任务，但存在逻辑错误和偏见问题。</li>
<li><strong>GPT-4（2023年）</strong><br />
多模态融合架构，优化推理能力和安全伦理机制，在专业考试和创意写作中达到人类水平。</li>
</ol>
<h3>什么是AI</h3>
<p>人工智能（AI）指通过算法模拟人类认知功能的系统，涵盖机器学习、自然语言处理、计算机视觉等领域。其核心目标是使机器具备感知、推理、学习和决策能力。</p>
<h3>分析式与生成式AI的区别</h3>
<table>
<thead>
<tr>
<th>类型</th>
<th>分析式AI</th>
<th>生成式AI</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>原理</strong></td>
<td>基于判别模型分析数据规律</td>
<td>基于生成模型创造新内容</td>
</tr>
<tr>
<td><strong>应用</strong></td>
<td>金融风控、医疗诊断</td>
<td>文本/图像生成、创意设计</td>
</tr>
<tr>
<td><strong>案例</strong></td>
<td>SVM分类、推荐系统</td>
<td>GPT文本生成、DALL·E图像合成</td>
</tr>
</tbody>
</table>
<h3>GPT是如何训练出来的</h3>
<ol>
<li><strong>预训练</strong>：通过海量文本学习语言规律，采用自注意力机制捕捉长距离依赖。</li>
<li><strong>微调</strong>：在标注数据上调整模型的参数以适应具体任务。</li>
<li><strong>RLHF</strong>：通过人类反馈强化学习优化输出质量，如ChatGPT的对话对齐。</li>
</ol>
<h3>AIGC的表现与优势</h3>
<ol>
<li><strong>效率提升</strong>：快速生成营销文案或设计草图，比人工快100倍。</li>
<li><strong>成本优化</strong>：电商产品描述生成成本降低90%。</li>
<li><strong>创新赋能</strong>：辅助科研人员生成蛋白质结构假设，加速药物研发。</li>
</ol>
<h3>AIGC的通用能力应用</h3>
<ol>
<li><strong>医疗</strong>：合成匿名病例数据辅助罕见病研究。</li>
<li><strong>教育</strong>：为每位学生生成个性化习题。</li>
<li><strong>保险</strong>：车险理赔中AI定损将处理时间从3天缩短至25分钟。</li>
<li><strong>文案</strong>：快速生成新媒体内容，提高曝光度。</li>
</ol>
<h2>大模型API调用</h2>
<h3>全球AI发展现状</h3>
<ol>
<li><strong>技术发展前沿</strong>：2025年全球AI持续突破，生成式AI和多模态融合和成为核心发展方向（多模态生成技术实现文本到3D模型的跨越），行业定制化生成模型成为新趋势。</li>
<li><strong>全球竞争格局</strong>：欧洲4月推出《AI大陆行动计划》，美国7月发布《Winning this AI Race》计划，中国8月发布《关于深入实施“人工智能+”行动的意见》文件。</li>
<li><strong>行业应用深化</strong>：医疗健康、国家电网、海尔工厂、钢铁生产、农业创新都在利用AI提高效率。</li>
<li><strong>未来发展趋势</strong>：Agentic AI的崛起，从被动响应转向自主执行复杂任务；AI将更深度融入经济社会各领域，推动生产力变革和产业升级。</li>
</ol>
<h3>API调用项目实操</h3>
<ol>
<li>
<p><strong>情感分析-Qwen（掌握DashScope调⽤⼤模型）</strong></p>
<ul>
<li><strong>获取API</strong><br />
访问阿里云百炼平台：<a href="https://bailian.console.aliyun.com/">https://bailian.console.aliyun.com/</a> ，完成注册登录<br />
点击右上角齿轮，点击API-Key，点击创建API-KEY(建议添加描述，区分用途)，复制API Key
<img src="https://www.mysen.top/content/uploadfile/202509/650d1758108333.png" alt="进入设置" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<img src="https://www.mysen.top/content/uploadfile/202509/42fd1758108333.png" alt="创建API" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<img src="https://www.mysen.top/content/uploadfile/202509/55ae1758108333.png" alt="复制API" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div></li>
<li><strong>配置环境</strong><br />
以Ubuntu24.04为例（系统已默认安装python3）：
<pre><code class="language-bash"># 1. 安装python虚拟环境组件
apt install python3-venv
# 2. 创建名为test虚拟环境，删除直接rm -rf test即可
python3 -m venv test
# 3. 激活虚拟环境，后续安装的依赖包都在虚拟环境中不影响全局python，运行deactivate退出虚拟环境
source test/bin/activate
# 4. 在虚拟环境中安装依赖包，dashscope用于AI模型开发的库，python-dotenv用于从.env文件中加载环境变量到应用程序中
pip install dashscope python-dotenv</code></pre></li>
<li><strong>构建项目</strong>
<pre><code class="language-bash"># 1. 创建项目目录及文件
mkdir sentiment &amp;&amp; cd sentiment/ &amp;&amp; touch .env requirements.txt config.py main.py
# 2. 在.env文件中添加变量为从阿里云百炼获取的API Key，降低API外泄风险
echo "DASHSCOPE_API_KEY=您的API" &gt; .env
# 3. 在requirements.txt文件中添加项目依赖，也可运行pip install -r requirements.txt安装依赖包
cat &lt;&lt; EOF | tee requirements.txt
dashscope&gt;=1.23.0
python-dotenv&gt;=1.0.0
EOF
# 4. 在config.py文件中引用调用的模型名称、链接及密钥，可以尝试更换模型版本(qwen-turbo/qwen-max)
cat &lt;&lt; EOF | tee config.py
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
API_KEY =os.getenv('DASHSCOPE_API_KEY')
MODEL_NAME = 'qwen-plus-2025-09-11'
BASE_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1'
EOF
# 5. 在main.py主程序中添加执行代码，注意代码对齐，有严格的代码规范
cat &lt;&lt; EOF | tee main.py
from http import HTTPStatus
import dashscope
from config import Config
class SentimentAgent:
def __init__(self):
dashscope.api_key = Config.API_KEY
def analyze_sentiment(self, text):
"""情感分析核心方法"""
messages = [
    {
        "role": "system",
        "content": "你是一个专业的情感分析模型。请分析以下文本的情感倾向，仅返回'正面'、'负面'或'中性'"
    },
    {
        "role": "user",
        "content": text
    }
]
response = dashscope.Generation.call(
    model=Config.MODEL_NAME,
    messages=messages,
    result_format='message'
)
if response.status_code == HTTPStatus.OK:
    return response.output.choices[0].message.content
else:
    raise Exception(f"API调用失败: {response.message}")
if __name__ == '__main__':
main = SentimentAgent()
while True:
text = input("请输入待分析文本(输入q退出): ")
if text.lower() == 'q':
    break
result = main.analyze_sentiment(text)
print(f"情感分析结果: {result}")
EOF
# 6. 运行主程序测试效果
python main.py</code></pre></li>
<li><strong>进阶优化</strong>
<pre><code class="language-bash"># 1. 在main.py文件中增加修改模型默认参数，测试输出结果
response = dashscope.Generation.call(
model=Config.MODEL_NAME,
messages=messages,
result_format='message',
temperature=0.3,  # 温度参数，不同模型默认值不同，控制输出随机性(0-1)，越大越随机，越小则缺乏创意
top_p=0.8         # 核采样参数，越高越多样，越低越集中
)
# 2. 在main.py文件中扩展情感分类，修改系统提示词，测试输出结果
"content": "……请分析以下文本的情感倾向，返回: 非常正面/正面/中性/负面/非常负面"
# 3. 在main.py文件中，系统提示词再增加一行情感强度评分并返回指定的格式，测试输出结果
"content": "返回JSON格式: {'情感':'正面','评分':0.8}"</code></pre></li>
<li><strong>案列总结</strong><br />
注意规范的安全的管理API Key，初步理解prompt工程设计，了解可扩展的架构设计</li>
</ul>
</li>
<li>
<p><strong>查询天⽓-Qwen（了解Function Call）</strong></p>
<ul>
<li><strong>获取API</strong><br />
除了要获取阿里百炼模型的API外还需要一个查询天气的API（以和风天气为例）<br />
访问和风天气开发者平台：<a href="https://dev.qweather.com/">https://dev.qweather.com/</a> ，完成注册登录<br />
在本地执行以下命令生成公钥和私钥（以Ubuntu为例）:
<pre><code class="language-bash">openssl genpkey -algorithm ED25519 -out ed25519-private.pem \
&amp;&amp; openssl pkey -pubout -in ed25519-private.pem &gt; ed25519-public.pem
cat ed25519-public.pem</code></pre>
<p>在和风天气控制台点击项目管理，创建项目，创建凭据，复制ed25519-public.pem的内容至上传公钥中，复制项目ID和凭据ID</p>
<img src="https://www.mysen.top/content/uploadfile/202509/a04a1758118476.png" alt="创建项目" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<img src="https://www.mysen.top/content/uploadfile/202509/1d401758186063.png" alt="创建JWT" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<img src="https://www.mysen.top/content/uploadfile/202509/e89c1758186445.png" alt="获取ID" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div>
<p>进入test虚拟环境，安装依赖，生成12小时有效的token</p>
<pre><code class="language-bash"># 1. 进入test虚拟环境
source test/bin/activate
# 2. 安装依赖包
pip3 install PyJWT
# 3. 创建生成JWT_Token的文件，private_key为生成的ed25519-private.pem内容，sub为项目ID，kid为凭据ID
cat &lt;&lt; EOF | tee make_jwt_token.py
import sys
import time
import jwt
private_key = """ed25519-private.pem的全部内容"""
payload = {
'iat': int(time.time()) - 30,
'exp': int(time.time()) + 43200,
'sub': '项目ID'
}
headers = {
'kid': '凭据ID'
}
encoded_jwt = jwt.encode(payload, private_key, algorithm='EdDSA', headers = headers)
print(f"JWT:  {encoded_jwt}")
EOF</code></pre>
<p>复制token，到和风天气控制台的帮助与支持，点击JWT验证确保生成的token有效</p>
<img src="https://www.mysen.top/content/uploadfile/202509/c4d21758187362.png" alt="验证token" width="60%" style="float: left; margin-right: 10px">
<div style="clear: both"></div></li>
<li><strong>搭建环境</strong>
<pre><code class="language-bash"># 还是在test虚拟环境中安装依赖包，注意当前所在目录
source test/bin/activate
pip install dashscope python-dotenv requests</code></pre></li>
<li><strong>构建项目</strong>
<pre><code class="language-bash"># 1. 创建项目目录及文件
mkdir weather &amp;&amp; cd weather/ &amp;&amp; touch .env requirements.txt config.py weather_api.py main.py
# 2. 在.env文件中添加变量并分别设置为阿里百炼和和风天气的JWT验证
cat &lt;&lt; EOF | tee .env
API_HOST=和风天气API Host
QWEATHER_JWT=和风天气的JWT token，例如：Bearer eyJhbGci...
DASHSCOPE_API_KEY=阿里百炼模型APIkey
EOF
# 3. 在requirements.txt文件中添加依赖包，requests为请求依赖包
cat &lt;&lt; EOF | tee requirements.txt
dashscope&gt;=1.23.0
python-dotenv&gt;=1.0.0
requests&gt;=2.31.0
EOF
# 4. 在config.py文件中获取模型名称以及API,模型可修改为文本生成或全模态
cat &lt;&lt; EOF | tee config.py
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
QWEATHER_HOST = os.getenv('API_HOST')
QWEATHER_JWT = os.getenv('QWEATHER_JWT')
DASHSCOPE_API_KEY = os.getenv('DASHSCOPE_API_KEY')
MODEL_NAME = 'qwen-plus-2025-09-11'
EOF
# 5. 在weather_api.py文件中封装API
cat &lt;&lt; EOF | tee weather_api.py
import gzip
import json
import requests
from config import Config
class QWeatherAPI:
@staticmethod
def get_weather(endpoint, params=None):
"""通用调用API"""
url = f"https://{Config.QWEATHER_HOST}{endpoint}"
headers = {
    "Authorization": Config.QWEATHER_JWT,
    "Accept-Encoding": "gzip"
}
try:
    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    return response.json()
except requests.exceptions.RequestException as e:
    print(f"API调用失败: {str(e)}")
    return None
@staticmethod
def get_city_id(city_name):
"""调用Geo API获取城市id"""
return QWeatherAPI.get_weather('/geo/v2/city/lookup', {'location': city_name})
@staticmethod
def get_current_weather(city_name):
"""获取实时天气"""
geo_data = QWeatherAPI.get_city_id(city_name)
if not geo_data or not geo_data.get("location"):
    return None
location_id = geo_data["location"][0]["id"]
return QWeatherAPI.get_weather('/v7/weather/now', {'location': location_id})
EOF
# 6. 在main.py文件中添加如下代码
cat &lt;&lt; EOF | tee main.py
import dashscope
from http import HTTPStatus
from config import Config
from weather_api import QWeatherAPI
class WeatherAgent:
def __init__(self):
dashscope.api_key = Config.DASHSCOPE_API_KEY
def get_weather_function(self):
"""定义天气查询的Function Call规范"""
return {
    "name": "get_current_weather",
    "description": "获取指定城市的当前天气情况",
    "parameters": {
        "type": "object",
        "properties": {
            "city": {
                "type": "string",
                "description": "城市名称，如'北京'"
            }
        },
        "required": ["city"]
    }
}
def run_query(self, user_input):
"""处理用户查询"""
response = dashscope.Generation.call(
    model=Config.MODEL_NAME,
    messages=[{"role": "user", "content": user_input}],
    functions=[self.get_weather_function()],
    result_format='message'
)
if response.status_code == HTTPStatus.OK:
    # 检查是否需要调用函数
    if "function_call" in response.output.choices[0].message:
        func_call = response.output.choices[0].message["function_call"]
        if func_call["name"] == "get_current_weather":
            # 解析参数并调用天气API
            city = eval(func_call["arguments"])["city"]
            weather_data = QWeatherAPI.get_current_weather(city)
            # 将结果返回给模型生成最终回复
            second_response = dashscope.Generation.call(
                model=Config.MODEL_NAME,
                messages=[
                    {"role": "user", "content": user_input},
                    {"role": "function", "name": func_call["name"], "content": str(weather_data)}
                ]
            )
            return second_response.output.choices[0].message["content"]
    else:
        return response.output.choices[0].message["content"]
else:
    raise Exception(f"API调用失败: {response.message}")
if __name__ == '__main__':
main = WeatherAgent()
while True:
query = input("请输入您的天气查询(输入q退出): ")
if query.lower() == 'q':
    break
result = main.run_query(query)
print(f"查询结果: {result}")
EOF</code></pre></li>
<li><strong>进阶建议</strong><br />
添加更多功能的函数，例如天气预报、空气质量等<br />
实现多轮对话记忆功能<br />
添加用户位置自动识别</li>
<li><strong>案列总结</strong><br />
理解模型如何决定调用函数以及传递参数</li>
</ul>
</li>
<li>
<p>表格提取-Qwen（了解多模态⼤模型）</p>
</li>
<li>
<p>运维事件处置-Qwen</p>
</li>
</ol>]]></description>
    <pubDate>Wed, 07 May 2025 10:15:28 +0800</pubDate>
    <dc:creator>袋鼠</dc:creator>
    <guid>https://www.mysen.top/api.html</guid>
</item>
</channel>
</rss>