Nicksxs's Blog

What hurts more, the pain of hard work or the pain of regret?

claude的模型现在在写代码这块还是比较权威的,只是也别小瞧了本身它的通用能力
我们打开类似于gpt,claude经常是以文本形式的提问,再得到文本形式的回答,但是对于我们程序员来说,还有一些用途其实是可以更有效的
比如我们可以让claude帮我们画图
像我们的uml图,可以用文本化的plantuml或者mermaid等这些工具来画
比如我可以让claude给我画个深度学习路径图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
graph TD
Start[开始学习神经网络] --> Phase1[第一阶段: 数学基础]

Phase1 --> Math1[线性代数]
Phase1 --> Math2[微积分]
Phase1 --> Math3[概率统计]

Math1 --> Math1a["矩阵运算、特征值<br/>📚 3Blue1Brown线性代数系列<br/>🔗 youtube.com/c/3blue1brown"]
Math2 --> Math2a["偏导数、梯度、链式法则<br/>📚 MIT 18.01单变量微积分<br/>🔗 ocw.mit.edu"]
Math3 --> Math3a["期望、方差、贝叶斯定理<br/>📚 Probabilistic ML书籍<br/>🔗 probml.github.io"]

Math1a --> Phase2
Math2a --> Phase2
Math3a --> Phase2

Phase2[第二阶段: 编程基础] --> Prog1[Python编程]
Phase2 --> Prog2[NumPy/Pandas]
Phase2 --> Prog3[数据可视化]

Prog1 --> Prog1a["基础语法、面向对象<br/>📚 Python Crash Course<br/>🔗 nostarch.com/python-crash-course"]
Prog2 --> Prog2a["数组操作、数据处理<br/>📚 NumPy官方教程<br/>🔗 numpy.org/doc"]
Prog3 --> Prog3a["Matplotlib、Seaborn<br/>📚 Python Data Science Handbook<br/>🔗 jakevdp.github.io"]

Prog1a --> Phase3
Prog2a --> Phase3
Prog3a --> Phase3

Phase3[第三阶段: 机器学习基础] --> ML1[监督学习]
Phase3 --> ML2[损失函数]
Phase3 --> ML3[优化算法]

ML1 --> ML1a["线性回归、逻辑回归<br/>📚 Andrew Ng ML课程<br/>🔗 coursera.org/learn/machine-learning"]
ML2 --> ML2a["MSE、交叉熵<br/>📚 Deep Learning Book Ch5<br/>🔗 deeplearningbook.org"]
ML3 --> ML3a["梯度下降、SGD<br/>📚 Sebastian Ruder优化综述<br/>🔗 ruder.io/optimizing-gradient-descent"]

ML1a --> Phase4
ML2a --> Phase4
ML3a --> Phase4

Phase4[第四阶段: 神经网络基础] --> NN1[感知机]
Phase4 --> NN2[前馈神经网络]
Phase4 --> NN3[反向传播]

NN1 --> NN1a["单层感知机、多层感知机<br/>📚 Neural Networks and Deep Learning<br/>🔗 neuralnetworksanddeeplearning.com"]
NN2 --> NN2a["全连接层、激活函数<br/>📚 Stanford CS231n Lecture 4<br/>🔗 cs231n.stanford.edu"]
NN3 --> NN3a["链式法则、梯度计算<br/>📚 Backprop Calculus详解<br/>🔗 colah.github.io"]

NN1a --> Phase5
NN2a --> Phase5
NN3a --> Phase5

Phase5[第五阶段: 深度学习框架] --> FW1[PyTorch]
Phase5 --> FW2[TensorFlow/Keras]

FW1 --> FW1a["Tensor操作、自动微分<br/>📚 PyTorch官方教程<br/>🔗 pytorch.org/tutorials"]
FW2 --> FW2a["模型构建、训练流程<br/>📚 TensorFlow实战<br/>🔗 tensorflow.org/tutorials"]

FW1a --> Phase6
FW2a --> Phase6

Phase6[第六阶段: 卷积神经网络CNN] --> CNN1[卷积层原理]
Phase6 --> CNN2[经典架构]
Phase6 --> CNN3[应用领域]

CNN1 --> CNN1a["卷积、池化、感受野<br/>📚 CS231n Convolutional Networks<br/>🔗 cs231n.github.io/convolutional-networks"]
CNN2 --> CNN2a["LeNet、AlexNet、VGG<br/>ResNet、Inception、EfficientNet<br/>📚 论文集合: paperswithcode.com<br/>🔗 paperswithcode.com/methods/category/convolutional-neural-networks"]
CNN3 --> CNN3a["图像分类、目标检测、分割<br/>📚 Computer Vision: Algorithms and Applications<br/>🔗 szeliski.org/Book"]

CNN1a --> Phase7
CNN2a --> Phase7
CNN3a --> Phase7

Phase7[第七阶段: 循环神经网络RNN] --> RNN1[RNN基础]
Phase7 --> RNN2[LSTM/GRU]
Phase7 --> RNN3[序列建模]

RNN1 --> RNN1a["循环结构、时间展开<br/>📚 Understanding LSTM Networks<br/>🔗 colah.github.io/posts/2015-08-Understanding-LSTMs"]
RNN2 --> RNN2a["门控机制、长期依赖<br/>📚 Illustrated Guide to LSTM/GRU<br/>🔗 towardsdatascience.com"]
RNN3 --> RNN3a["时间序列、语言模型<br/>📚 Sequence Models课程<br/>🔗 coursera.org/learn/nlp-sequence-models"]

RNN1a --> Phase8
RNN2a --> Phase8
RNN3a --> Phase8

Phase8[第八阶段: 注意力机制与Transformer] --> ATT1[注意力机制]
Phase8 --> ATT2[Transformer架构]
Phase8 --> ATT3[预训练模型]

ATT1 --> ATT1a["Self-Attention、Multi-Head<br/>📚 Attention Is All You Need<br/>🔗 arxiv.org/abs/1706.03762"]
ATT2 --> ATT2a["Encoder-Decoder、位置编码<br/>📚 The Illustrated Transformer<br/>🔗 jalammar.github.io/illustrated-transformer"]
ATT3 --> ATT3a["BERT、GPT系列、T5<br/>📚 Hugging Face Course<br/>🔗 huggingface.co/course"]

ATT1a --> Phase9
ATT2a --> Phase9
ATT3a --> Phase9

Phase9[第九阶段: 生成模型] --> GEN1[自编码器]
Phase9 --> GEN2[生成对抗网络GAN]
Phase9 --> GEN3[扩散模型]

GEN1 --> GEN1a["AE、VAE、特征学习<br/>📚 Tutorial on VAE<br/>🔗 arxiv.org/abs/1606.05908"]
GEN2 --> GEN2a["判别器、生成器、对抗训练<br/>📚 GAN Lab交互式可视化<br/>🔗 poloclub.github.io/ganlab"]
GEN3 --> GEN3a["DDPM、Stable Diffusion<br/>📚 Diffusion Models教程<br/>🔗 lilianweng.github.io/posts/2021-07-11-diffusion-models"]

GEN1a --> Phase10
GEN2a --> Phase10
GEN3a --> Phase10

Phase10[第十阶段: 高级技术] --> ADV1[正则化技术]
Phase10 --> ADV2[优化技巧]
Phase10 --> ADV3[模型压缩]

ADV1 --> ADV1a["Dropout、BatchNorm、数据增强<br/>📚 CS231n训练技巧<br/>🔗 cs231n.github.io/neural-networks-2"]
ADV2 --> ADV2a["Adam、学习率调度、梯度裁剪<br/>📚 An Overview of Optimization<br/>🔗 arxiv.org/abs/1609.04747"]
ADV3 --> ADV3a["剪枝、量化、知识蒸馏<br/>📚 Model Compression Survey<br/>🔗 arxiv.org/abs/1710.09282"]

ADV1a --> Phase11
ADV2a --> Phase11
ADV3a --> Phase11

Phase11[第十一阶段: 实践项目] --> PROJ1[计算机视觉项目]
Phase11 --> PROJ2[自然语言处理项目]
Phase11 --> PROJ3[多模态项目]

PROJ1 --> PROJ1a["Kaggle图像竞赛<br/>物体检测系统<br/>📚 PyImageSearch教程<br/>🔗 pyimagesearch.com"]
PROJ2 --> PROJ2a["文本分类、情感分析<br/>问答系统、对话机器人<br/>📚 实战项目集合<br/>🔗 github.com/dair-ai/ML-Papers-Explained"]
PROJ3 --> PROJ3a["图像描述、视觉问答<br/>📚 OpenAI CLIP论文<br/>🔗 arxiv.org/abs/2103.00020"]

PROJ1a --> Phase12
PROJ2a --> Phase12
PROJ3a --> Phase12

Phase12[第十二阶段: 前沿研究] --> RES1[大语言模型LLM]
Phase12 --> RES2[强化学习]
Phase12 --> RES3[神经架构搜索]

RES1 --> RES1a["GPT-4、Claude、Llama系列<br/>📚 LLM综述论文<br/>🔗 arxiv.org/abs/2303.18223"]
RES2 --> RES2a["DQN、PPO、AlphaGo<br/>📚 Spinning Up in Deep RL<br/>🔗 spinningup.openai.com"]
RES3 --> RES3a["AutoML、NAS方法<br/>📚 NAS Survey<br/>🔗 arxiv.org/abs/1808.05377"]

RES1a --> End
RES2a --> End
RES3a --> End

End[🎓 持续学习与研究]

style Start fill:#e1f5e1
style Phase1 fill:#fff4e6
style Phase2 fill:#fff4e6
style Phase3 fill:#e3f2fd
style Phase4 fill:#e3f2fd
style Phase5 fill:#f3e5f5
style Phase6 fill:#fce4ec
style Phase7 fill:#fce4ec
style Phase8 fill:#e0f2f1
style Phase9 fill:#fff9c4
style Phase10 fill:#ffebee
style Phase11 fill:#e8f5e9
style Phase12 fill:#e1bee7
style End fill:#c8e6c9

生成出来的图效果还是挺不错的

另外比如我们想要生成一个电商系统的下单交易流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
sequenceDiagram
actor User as 👤 用户
participant Web as 🌐 Web/App前端
participant Gateway as 🚪 API网关
participant Auth as 🔐 认证服务
participant Product as 📦 商品服务
participant Cart as 🛒 购物车服务
participant Order as 📋 订单服务
participant Inventory as 📊 库存服务
participant Coupon as 🎫 优惠券服务
participant Payment as 💳 支付服务
participant PayGateway as 💰 支付网关
participant MQ as 📨 消息队列
participant WMS as 🏭 仓储系统
participant Logistics as 🚚 物流系统
participant Notify as 📧 通知服务
participant AfterSale as 🔄 售后服务
participant Finance as 💵 财务系统

Note over User,Finance: 📚 参考架构:微服务电商系统<br/>🔗 github.com/macrozheng/mall

%% 登录认证阶段
rect rgb(230, 245, 255)
Note over User,Auth: 第一阶段:用户认证
User->>Web: 1. 打开电商平台
Web->>Gateway: 2. 请求登录页面
Gateway->>Auth: 3. 验证会话状态

alt 未登录
Auth-->>Web: 4. 返回登录页面
User->>Web: 5. 输入账号密码/手机验证码
Web->>Auth: 6. 提交登录请求
Note right of Auth: 🔐 JWT Token生成<br/>📚 RFC 7519标准<br/>🔗 jwt.io
Auth->>Auth: 7. 验证凭证
Auth-->>Web: 8. 返回Token
Web->>Web: 9. 存储Token到Cookie/LocalStorage
else 已登录
Auth-->>Web: 4. 验证通过
end
end

%% 商品浏览阶段
rect rgb(245, 255, 230)
Note over User,Product: 第二阶段:商品浏览
User->>Web: 10. 搜索/浏览商品
Web->>Gateway: 11. 商品查询请求
Gateway->>Product: 12. 转发查询
Note right of Product: 🔍 Elasticsearch全文搜索<br/>📚 搜索引擎实战<br/>🔗 elastic.co/guide
Product->>Product: 13. 从ES/缓存查询
Product-->>Web: 14. 返回商品列表

User->>Web: 15. 点击商品详情
Web->>Gateway: 16. 请求商品详情
Gateway->>Product: 17. 查询商品信息
Gateway->>Inventory: 18. 查询库存信息
Note right of Inventory: 💾 Redis缓存+MySQL<br/>📚 缓存穿透/击穿方案<br/>🔗 redis.io/topics/lru-cache

par 并行查询
Product-->>Gateway: 19a. 返回商品详情
and
Inventory-->>Gateway: 19b. 返回库存数量
end
Gateway-->>Web: 20. 聚合返回
end

%% 购物车阶段
rect rgb(255, 245, 230)
Note over User,Cart: 第三阶段:加入购物车
User->>Web: 21. 选择规格并加入购物车
Web->>Gateway: 22. 加购请求
Gateway->>Cart: 23. 添加到购物车
Note right of Cart: 🗄️ Redis存储购物车<br/>📚 分布式Session方案<br/>🔗 spring.io/projects/spring-session
Cart->>Inventory: 24. 验证库存是否充足
Inventory-->>Cart: 25. 返回库存状态
Cart->>Cart: 26. 计算商品小计
Cart-->>Web: 27. 返回购物车数据

User->>Web: 28. 查看购物车
Web->>Gateway: 29. 获取购物车列表
Gateway->>Cart: 30. 查询购物车
Cart->>Product: 31. 批量查询商品最新价格
Cart->>Coupon: 32. 查询可用优惠券
Note right of Coupon: 🎫 优惠券系统设计<br/>📚 促销引擎架构<br/>🔗 tech.meituan.com

par 并行查询
Product-->>Cart: 33a. 返回价格信息
and
Coupon-->>Cart: 33b. 返回可用优惠券
end
Cart-->>Web: 34. 返回购物车详情
end

%% 订单创建阶段
rect rgb(255, 240, 245)
Note over User,Order: 第四阶段:订单创建
User->>Web: 35. 点击结算
Web->>Gateway: 36. 进入结算页
Gateway->>Order: 37. 创建预订单

User->>Web: 38. 选择收货地址/优惠券
Web->>Gateway: 39. 提交订单
Gateway->>Order: 40. 创建订单请求

Note right of Order: 🔢 雪花算法生成订单号<br/>📚 分布式ID生成方案<br/>🔗 github.com/twitter/snowflake
Order->>Order: 41. 生成订单号
Order->>Coupon: 42. 锁定优惠券
Order->>Inventory: 43. 预扣减库存
Note right of Inventory: ⚠️ 分布式锁防超卖<br/>📚 Redis+Lua脚本<br/>🔗 redisson.org

alt 库存充足
Inventory-->>Order: 44. 扣减成功
Coupon-->>Order: 45. 锁定成功
Order->>Order: 46. 订单状态:待支付
Order-->>Web: 47. 返回订单信息
else 库存不足
Inventory-->>Order: 44. 库存不足
Order-->>Web: 47. 返回库存不足提示
end
end

%% 支付阶段
rect rgb(240, 248, 255)
Note over User,PayGateway: 第五阶段:支付处理
User->>Web: 48. 选择支付方式
Web->>Gateway: 49. 发起支付请求
Gateway->>Payment: 50. 创建支付单

Note right of Payment: 💳 聚合支付设计<br/>📚 支付系统架构<br/>🔗 github.com/Exrick/xpay
Payment->>Payment: 51. 生成支付单号
Payment->>Order: 52. 关联订单
Payment->>PayGateway: 53. 调用支付渠道

alt 支付宝支付
Note right of PayGateway: 💰 支付宝SDK<br/>📚 开放平台文档<br/>🔗 opendocs.alipay.com
PayGateway->>PayGateway: 54. 调用支付宝API
else 微信支付
Note right of PayGateway: 💚 微信支付API<br/>📚 支付开发文档<br/>🔗 pay.weixin.qq.com
PayGateway->>PayGateway: 54. 调用微信支付API
end

PayGateway-->>User: 55. 返回支付页面/二维码
User->>User: 56. 完成支付操作

Note over PayGateway,Payment: 🔔 异步回调通知
PayGateway->>Payment: 57. 支付成功回调
Note right of Payment: 📚 幂等性设计<br/>🔗 martinfowler.com/articles/patterns-of-distributed-systems
Payment->>Payment: 58. 验证签名并去重
Payment->>Order: 59. 更新订单状态为已支付
Payment->>MQ: 60. 发送支付成功消息

par 异步处理
MQ->>Notify: 61a. 发送通知
Note right of Notify: 📧 消息推送<br/>📚 RabbitMQ/Kafka<br/>🔗 rabbitmq.com
Notify->>User: 短信/邮件/Push通知
and
MQ->>Order: 61b. 确认订单
Order->>Order: 更新订单:待发货
end
end

%% 仓储物流阶段
rect rgb(232, 245, 233)
Note over Order,Logistics: 第六阶段:仓储配送
Order->>WMS: 62. 推送发货指令
Note right of WMS: 📦 WMS系统设计<br/>📚 仓储管理实践<br/>🔗 github.com/topics/wms

WMS->>WMS: 63. 订单拆分(多仓)
WMS->>WMS: 64. 波次拣货
WMS->>WMS: 65. 打包称重
WMS->>Logistics: 66. 创建物流订单

Note right of Logistics: 🚚 电子面单生成<br/>📚 菜鸟/快递鸟API<br/>🔗 kdniao.com
Logistics->>Logistics: 67. 生成运单号
Logistics->>Logistics: 68. 打印电子面单
Logistics-->>WMS: 69. 返回物流信息

WMS->>Order: 70. 更新订单为已发货
Order->>MQ: 71. 发送发货消息
MQ->>Notify: 72. 通知用户已发货
Notify->>User: 73. 发送物流信息

loop 物流跟踪
Logistics->>Logistics: 74. 更新物流轨迹
Note right of Logistics: 🗺️ 物流轨迹追踪<br/>📚 快递100 API<br/>🔗 kuaidi100.com
Logistics->>Order: 75. 同步物流状态
Order->>Notify: 76. 推送物流更新
Notify->>User: 77. 实时物流通知
end

Logistics->>Order: 78. 签收成功
Order->>Order: 79. 更新订单:已签收
Order->>MQ: 80. 发送签收消息
end

%% 订单完成阶段
rect rgb(255, 243, 224)
Note over User,Finance: 第七阶段:订单完成
MQ->>Order: 81. 触发自动确认收货定时器
Note right of Order: ⏰ 7天自动确认<br/>📚 XXL-Job定时任务<br/>🔗 xuxueli.com/xxl-job

alt 用户主动确认
User->>Web: 82a. 确认收货
Web->>Order: 83a. 确认收货请求
else 超时自动确认
Order->>Order: 82b. 7天后自动确认
end

Order->>Order: 84. 订单状态:已完成
Order->>Finance: 85. 触发结算
Note right of Finance: 💰 T+1结算<br/>📚 财务对账系统<br/>🔗 accounting-system-design.com

Finance->>Finance: 86. 计算平台佣金
Finance->>Finance: 87. 生成结算单

User->>Web: 88. 评价商品
Web->>Product: 89. 提交评价
Note right of Product: ⭐ UGC内容审核<br/>📚 评价系统设计<br/>🔗 review-system-architecture.com
Product->>Product: 90. 审核并发布评价
end

%% 售后阶段
rect rgb(255, 235, 238)
Note over User,AfterSale: 第八阶段:售后服务(可选)
opt 需要售后
User->>Web: 91. 申请退货/换货
Web->>AfterSale: 92. 创建售后单
Note right of AfterSale: 🔄 售后工单系统<br/>📚 7天无理由退货<br/>🔗 消费者权益保护法

AfterSale->>AfterSale: 93. 售后审核

alt 审核通过
AfterSale-->>User: 94. 审核通过,返回退货地址
User->>Logistics: 95. 寄回商品
Logistics->>WMS: 96. 商品入库
WMS->>AfterSale: 97. 确认收货
AfterSale->>Inventory: 98. 库存回补
AfterSale->>Payment: 99. 发起退款
Note right of Payment: 💵 原路退回<br/>📚 退款流程设计<br/>🔗 refund-process-design.com
Payment->>PayGateway: 100. 调用退款接口
PayGateway-->>Payment: 101. 退款成功
Payment->>MQ: 102. 发送退款消息
MQ->>Notify: 103. 通知用户
Notify->>User: 104. 退款到账通知
else 审核拒绝
AfterSale-->>User: 94. 拒绝售后申请
end
end
end

%% 数据分析阶段
rect rgb(227, 242, 253)
Note over Order,Finance: 第九阶段:数据统计分析
Note over Order,Finance: 📊 实时数据大屏<br/>📚 Flink流式计算<br/>🔗 flink.apache.org

par 数据采集
Order->>MQ: 订单数据埋点
and
Payment->>MQ: 支付数据埋点
and
Product->>MQ: 商品数据埋点
end

MQ->>Finance: 数据聚合分析
Finance->>Finance: 生成报表<br/>(销售额/转化率/ROI等)
Note right of Finance: 📈 BI系统<br/>📚 数据仓库建设<br/>🔗 github.com/topics/data-warehouse
end

Note over User,Finance: ✅ 完整交易流程结束

学习下用Google的agent开发工具Agent Development Kit简称 ADK,看着名字就不一般,冲着JDK的地位去的哈哈
首先我们安装下pom包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<dependencies>
<!-- The ADK Core dependency -->
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk</artifactId>
<version>0.2.0</version>
</dependency>

<!-- The ADK Dev Web UI to debug your agent (Optional) -->
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-dev</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

这个版本也说明了它还不是个完全体
接下去可以生成一个简单的项目结构

1
2
3
4
5
6
7
8
project_folder/
├── pom.xml (or build.gradle)
├── src/
├── └── main/
│ └── java/
│ └── agents/
│ └── multitool/
└── test/

然后再multitool中创建个java文件,可以叫 MultiToolAgent.java
注意这里需要使用jdk 17及以上版本
示例代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package agents.multitool;

import com.google.adk.agents.BaseAgent;
import com.google.adk.agents.LlmAgent;
import com.google.adk.events.Event;
import com.google.adk.runner.InMemoryRunner;
import com.google.adk.sessions.Session;
import com.google.adk.tools.Annotations.Schema;
import com.google.adk.tools.FunctionTool;
import com.google.genai.types.Content;
import com.google.genai.types.Part;
import io.reactivex.rxjava3.core.Flowable;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Scanner;

public class MultiToolAgent {

private static String USER_ID = "student";
private static String NAME = "multi_tool_agent";

// The run your agent with Dev UI, the ROOT_AGENT should be a global public static final variable.
public static final BaseAgent ROOT_AGENT = initAgent();

public static BaseAgent initAgent() {
return LlmAgent.builder()
.name(NAME)
.model("gemini-2.0-flash")
.description("Agent to answer questions about the time and weather in a city.")
.instruction(
"You are a helpful agent who can answer user questions about the time and weather"
+ " in a city.")
.tools(
FunctionTool.create(MultiToolAgent.class, "getCurrentTime"),
FunctionTool.create(MultiToolAgent.class, "getWeather"))
.build();
}

public static Map<String, String> getCurrentTime(
@Schema(name = "city",
description = "The name of the city for which to retrieve the current time")
String city) {
String normalizedCity =
Normalizer.normalize(city, Normalizer.Form.NFD)
.trim()
.toLowerCase()
.replaceAll("(\\p{IsM}+|\\p{IsP}+)", "")
.replaceAll("\\s+", "_");

return ZoneId.getAvailableZoneIds().stream()
.filter(zid -> zid.toLowerCase().endsWith("/" + normalizedCity))
.findFirst()
.map(
zid ->
Map.of(
"status",
"success",
"report",
"The current time in "
+ city
+ " is "
+ ZonedDateTime.now(ZoneId.of(zid))
.format(DateTimeFormatter.ofPattern("HH:mm"))
+ "."))
.orElse(
Map.of(
"status",
"error",
"report",
"Sorry, I don't have timezone information for " + city + "."));
}

public static Map<String, String> getWeather(
@Schema(name = "city",
description = "The name of the city for which to retrieve the weather report")
String city) {
if (city.toLowerCase().equals("new york")) {
return Map.of(
"status",
"success",
"report",
"The weather in New York is sunny with a temperature of 25 degrees Celsius (77 degrees"
+ " Fahrenheit).");

} else {
return Map.of(
"status", "error", "report", "Weather information for " + city + " is not available.");
}
}

public static void main(String[] args) throws Exception {
InMemoryRunner runner = new InMemoryRunner(ROOT_AGENT);

Session session =
runner
.sessionService()
.createSession(NAME, USER_ID)
.blockingGet();

try (Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8)) {
while (true) {
System.out.print("\nYou > ");
String userInput = scanner.nextLine();

if ("quit".equalsIgnoreCase(userInput)) {
break;
}

Content userMsg = Content.fromParts(Part.fromText(userInput));
Flowable<Event> events = runner.runAsync(USER_ID, session.id(), userMsg);

System.out.print("\nAgent > ");
events.blockingForEach(event -> System.out.println(event.stringifyContent()));
}
}
}
}

这个示例非常简单,就是初始化模型,提供基本的提示词,接下去就是两个简单的工具可供使用,提供城市的时间和纽约的天气
要运行起来需要申请api key,然后写到环境变量里

1
2
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
export GOOGLE_API_KEY=PASTE_YOUR_ACTUAL_API_KEY_HERE

在这里替换成自己的api key就行
然后运行

1
2
3
4
mvn exec:java \
-Dexec.mainClass="com.google.adk.web.AdkWebServer" \
-Dexec.args="--adk.agents.source-dir=src/main/java" \
-Dexec.classpathScope="compile"

就可以看到一个简单的运行界面

初使用后发现还是比较容易上手,只是后续更深入的还需要好好研究学习

wsl出来这些年感觉在windows里使用linux,或者ubuntu真的是方便了很多,不用搞虚拟机这些
但是也有一些明显的问题,首先就是默认它是在C盘中安装,长久使用占用的空间就会越来越大,而且对于一些临时使用占用空间后,即使删除了文件,windows并不会对已经扩容的虚拟磁盘文件进行缩容
所以就介绍下怎么手动来给它释放空间
首先可以看下安装的系统有哪些

1
wsl -l -v

比如我这就是一个ubuntu 20.04

1
2
  NAME            STATE           VERSION
* Ubuntu-20.04 Running 2

然后我们需要寻找下虚拟磁盘的所在位置
我的是在
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx
可以按文件名 ext4.vhdx 进行查找
当然在操作之前我们还是要做好备份工作,并且还有特殊功效

1
2
3
4
# 首先进行关机
wsl --shutdown
# 然后做打包备份到制定路径,放心这里打包的大小就是实际大小
wsl --export Ubuntu-20.04 X:\Ubuntu-20.04.tar

然后我们运行 diskpart 命令,这是windows用来管理磁盘文件的工具
运行后会进入到 diskpart 工具的命令状态下

1
select vdisk file="C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"

接着我们再运行select vdisk命令来选中这个文件
选中以后会提示
DiskPart 已成功选择虚拟磁盘文件。
接着运行压缩命令

1
compact vdisk

运行时会有个压缩进度展示,压缩完成后会显示以下内容

1
2
3
  100 百分比已完成

DiskPart 已成功压缩虚拟磁盘文件。

最终我们运行

1
detach vdisk

分离命令就可以了
这样子我们的wsl因为扩容后无法自动收回的空间就被我们压缩出来了

之前在我的MacBookPro里使用gpt-oss,因为总的内存只有18g,加上系统本身和各种后台程序的占用,剩下的一般就一半左右,然后这个模型大小就有13g左右,运行起来是很吃力的
正好我这有个服役比较久的windows笔记本,带有3060显卡,只是显存是6g的,想试下看能不能通过显卡来给它加加速,这里我使用了lm studio来运行gpt-oss 20b模型
这个lm studio可以配置有多少层transformer运行在gpu上,

我们可以大致除一下
这个gpt-oss 20b是有24层,官标的显存需求是16g,我们有6g显存,大约可以加载8~9层的样子,并且lm studio也自动算出来是加载8层
通过这个配置我们运行的gpt-oss能够得到勉强可用的程度

能达到4.x个token的生成速度,还是比mac上要把所有程序全关了,清掉很多token来得方便
实测将gpu卸载层数调整到9是勉强还可以运行,再往上就加载不了了,显存小没办法
当然我们还可以继续用 unsloth 进行微调
例如参考 https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/gpt-oss-(20B)-Fine-tuning.ipynb
同时可以通过nvidia-smi来查看显存占用

过程中倒是没看到显存完全占满,可以通过nvitop再进行观察
能够在gpu中加载部分层的确能把大模型的生成速度提升一些,但是还是受限于显存大小,最好是能有显存大于16g的显卡可以尝试测一下

之前体验过gemini code这个工具,谷歌还算比较友好,有token,有网络就可以用,claude code目前是个很严格,而且这家公司也对国内用户很不友好
所以就研究了下怎么把它对接上国内的模型
幸好之前deepseek发布v3.1的时候天然给了支持

1
2
3
4
5
6
7
8
## 由deepseek提供的兼容claude code的base url
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
## deepseek的token
export ANTHROPIC_AUTH_TOKEN={token}
## 对应的deepseek-chat模型,这个是非推理的
export ANTHROPIC_MODEL=deepseek-chat
## 快速小模型(同样可设为 deepseek-chat)
export ANTHROPIC_SMALL_FAST_MODEL=deepseek-chat

如果需要设置乘推理型的
可以把模型改成

1
export ANTHROPIC_MODEL=deepseek-reasoner

当然这个如果要长久有效得放在 .zshrc ,根据所用的shell工具来设置
然后安装claude需要node版本在18及以上

1
2
nvm use v18
npm install -g @anthropic-ai/claude-code

安装以后到想要开发的项目
运行

1
claude

接下来我们同样以todo应用作为测试应用

1
帮我写一个todo应用,使用react,ui需要尽可能美观

只是加了个美观的要求

1
2
3
4
5
6
7
8
⏺ Update Todos
⎿  ☐ Set up React project structure and dependencies
☐ Create main Todo component with state management
☐ Design and implement beautiful UI with CSS/styling
☐ Add todo functionality (add, delete, toggle complete)
☐ Test the application

⏺ Let me start by checking the current directory structure and then create the React todo application.

首先它分了五步
然后逐步运行对应的动作,生成文件等

生成的还是比较美观可用的,说明国内模型在简单的编码任务上也具有比较不错的能力了

0%