
Mind Network FHE Rust SDK 实战用 mind_sdk_deepseek 对 DeepSeek 预测做全同态加密并上链参与模型共识【免费下载链接】awesome-deepseek-integrationIntegrate the DeepSeek API into popular software项目地址: https://gitcode.com/GitHub_Trending/aw/awesome-deepseek-integration导读本文以 docs/fhe.mind-network/README.md 文档为骨架深入讲解 Mind Network 出品的原生 Rust SDKmind_sdk_deepseek让 DeepSeek 作为 AI Agent 先思考并预测随后在本地以全同态加密Fully Homomorphic EncryptionFHE将结果加密再提交到 Mind Network 网络参与模型共识。读完你既能掌握 Rust 侧「DeepSeek 推理 → FHE 加密 → 序列化 → 上链」的完整调用链路也能熟练使用随 SDK 提供的 FHE Voter 节点 CLI注册、投票、查询奖励等。项目定位当 DeepSeek 遇上前沿的 FHEmind_sdk_deepseek是 Mind Network 提供的一个Native Rust SDK目标非常聚焦为 DeepSeek 的调用补充 FHE全同态加密能力。在其设想的应用形态中DeepSeek 负责以 AI Agent 的身份代替用户思考与预测但结果不会明文流出而是先在本地用 FHE 加密成密文再提交至 Mind Network 网络完成模型共识model consensus。仓库根目录的 README.md 将该项目收录在FHEFully Homomorphic Encryptionframeworks分类下见 FHE frameworks 小节的表格条目并给出更直白的行业定位FHE 被誉为密码学的圣杯它允许直接在加密数据上进行计算而无需解密。借助它AI Agent 在调用 DeepSeek 时既能守住隐私——模型完整性与结果共识都有保障——又始终不暴露自己的数据只需接入 Mind Network 即可。这正是该 SDK 与 DeepSeek 集成的独特价值不是单纯把 DeepSeek 封装成 API 客户端而是构造一条AI 预测结果密文化、可验证、可上链的隐私计算管线。端到端工作流预测、加密、提交共识结合文档中给出的库调用示例与 CLI 命令可以勾勒出这套 SDK 的完整数据流推理通过deepseek_rs::DeepSeekClient调用 DeepSeek示例使用DeepSeekReasoner推理模型把业务问题如预测未来 7 天 BTC 价格交给模型得到reasoning_content思考过程与content最终答案。数值化将模型返回的文本答案解析为整数示例解析为u128以便进入同态加密的数值域。加密使用mind_sdk_fhe::FheInt加载本地 FHE 公钥文件fhe_public_key_fp调用fhe_client::encrypt把明文整数加密为密文再经io::serialize_base64序列化为可传输的 Base64 字符串。上链借助 alloy 的 RPC 栈把密文提交上链示例中封装为self.submit_fhe_encrypted最终拿到链上TransactionReceipt交易回执预测结果以密文形式进入 Mind Network 的共识流程。从命名与流程可以推断SDK 内部由deepseek_rsDeepSeek 客户端、mind_sdk_fheFHE 加密/序列化与链上提交逻辑三部分协作mind_sdk_deepseek是面向使用者的统一入口。库级集成在 Rust 工程里调用 SDK文档给出的核心使用示例是一条非常紧凑的预测即加密代码链值得逐段拆解。完整示例代码如下// call deepseek to predict, you can change to other prompt as you wish let prompt Please predict BTC price in next 7 days, return must be a positive integer.to_string() let client deepseek_rs::DeepSeekClient::default().unwrap(); let request deepseek_rs::client::chat_completions::request::RequestBody::new_messages(vec![ deepseek_rs::client::chat_completions::request::Message::new_user_message(prompt) ]).with_model(deepseek_rs::client::chat_completions::request::Model::DeepSeekReasoner); let response client.chat_completions(request).await.unwrap(); //println!(Reasoning: {}, response.choices[0].message.reasoning_content.unwrap()); //println!(Answer: {}, response.choices[0].message.content.unwrap()); // convert deepseek prediction to int type let deepseek_prediction match response.choices[0].clone().message.content.unwrap().parse::u128() { Ok(prediction) prediction, Err(_) 0, }; // fhe encrypt let fhe: mind_sdk_fhe::FheInt mind_sdk_fhe::FheInt::new_from_public_key_local(fhe_public_key_fp); let ciphertext mind_sdk_fhe::fhe_client::encrypt(fhe, u8, deepseek_prediction.clone()); let ciphertext_str: String mind_sdk_fhe::io::serialize_base64(ciphertext)?; // submit ciphertext onchain let result: alloy::rpc::types::TransactionReceipt self.submit_fhe_encrypted(ciphertext_str).await?;第一步构造 DeepSeek 推理请求let client deepseek_rs::DeepSeekClient::default().unwrap(); let request deepseek_rs::client::chat_completions::request::RequestBody::new_messages(vec![ deepseek_rs::client::chat_completions::request::Message::new_user_message(prompt) ]).with_model(deepseek_rs::client::chat_completions::request::Model::DeepSeekReasoner); let response client.chat_completions(request).await.unwrap();这段代码展示了典型的 Chat Completions 调用模式DeepSeekClient::default()基于默认配置创建客户端密钥等凭据应来自环境或默认配置RequestBody::new_messages(...)以消息列表构建请求体这里传入一条由Message::new_user_message(prompt)构造的用户消息.with_model(Model::DeepSeekReasoner)显式选择DeepSeekReasoner推理模型——这也是为什么响应里既有reasoning_content推理过程又有content正式答案client.chat_completions(request)异步发起请求返回的response.choices[0].message即可读取结果。第二步把预测文本解析成整数let deepseek_prediction match response.choices[0].clone().message.content.unwrap().parse::u128() { Ok(prediction) prediction, Err(_) 0, };模型返回的是文本而 FHE 只能对数值明文做运算因此这里把content解析为u128。这也是示例 prompt 中特别强调return must be a positive integer的原因提示词约束输出形态代码才能可靠完成数值化。解析失败时兜底为0避免 panic 中断整条管线。第三步用本地 FHE 公钥加密预测值let fhe: mind_sdk_fhe::FheInt mind_sdk_fhe::FheInt::new_from_public_key_local(fhe_public_key_fp); let ciphertext mind_sdk_fhe::fhe_client::encrypt(fhe, u8, deepseek_prediction.clone()); let ciphertext_str: String mind_sdk_fhe::io::serialize_base64(ciphertext)?;加密环节由mind_sdk_fhe承担关键点有三FheInt::new_from_public_key_local(fhe_public_key_fp)从本地文件加载 FHE公钥fhe_public_key_fp指公钥文件的路径。注意加密只需公钥私钥不出本地这正是数据不出域的隐私基础fhe_client::encrypt(fhe, u8, value)完成明文→密文转换其中字符串参数标识参与运算的整数类型示例中为u8。需要说明的是该类型标签的具体解释取决于mind_sdk_fhe底层实现接入方应与自身部署保持一致不能仅凭字面推断io::serialize_base64(ciphertext)把密文序列化为 Base64 字符串便于放入链上交易或网络传输。第四步把密文提交上链let result: alloy::rpc::types::TransactionReceipt self.submit_fhe_encrypted(ciphertext_str).await?;从代码形态看示例是某个应用结构体self内部的方法片段submit_fhe_encrypted属于应用层封装它接收 Base64 密文通过 alloy 的 RPC 类型栈发起链上交易最终返回alloy::rpc::types::TransactionReceipt交易回执。也就是说SDK 把「推理、加密、序列化」串好而把「签名上链」作为可扩展的接入点交给调用方按需实现。快速开始依赖、构建与运行安装依赖文档采用 crates.io 依赖引入方式在Cargo.toml中加入[dependencies] mind_sdk_deepseek *SDK 同时发布在 crates.io 生态中若要以源码方式构建并运行文档中的 CLI可先按文档 Quick Start 给出的git clonecd步骤获取上游 SDK 仓库源码再在源码目录内执行下面的构建与运行命令。构建SDK 是标准 Rust 工程使用 cargo 即可编译调试版或发布版cargo build --debug cargo build --release运行 CLI文档中的 CLI 需要配合若干节点配置文件一起使用典型的运行方式如下每种操作各启动一台/多台 FHE Voter 节点每台节点通过--node-config-file指向自己的配置cd msn cargo build ./target/debug/mind_sdk_deepseek --log-levelinfo check-hot-wallet-address cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn.toml register 0x06eF5C5ba427434bf36469B877e4ea9044D1b735 cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_1.toml register 0x2F8aCe76a34e50943573826A326a8Eb8DC854f84 cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_2.toml register 0x3df4b66E1895E68aB000f1086e9393ca1937Cd8b cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn.toml deepseek-fhe-vote cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_1.toml deepseek-fhe-vote cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_2.toml deepseek-fhe-vote cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn.toml check-registration cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_1.toml check-registration cargo build ./target/debug/mind_sdk_deepseek --log-leveldebug --node-config-file./config/config_fvn_2.toml check-registration从上面的组合可以读出文档想演示的多节点拓扑config_fvn.toml、config_fvn_1.toml、config_fvn_2.toml代表三套 FHE Voter 节点配置每台节点先用register把各自的投票者钱包注册上链随后都执行deepseek-fhe-vote参与对 DeepSeek 预测密文的共识投票再用check-registration复核注册状态。可执行文件命名在文档不同小节略有差异如部分示例写作./bin/deepseek实际使用应以当前版本构建产物与--help输出为准。CLI 全解析FHE Voter 节点命令集SDK 自带的命令行工具自述为 FHE Randen Voter Node Cli全同态加密投票节点其完整帮助信息如下# ./bin/deepseek --help FHE Randen Voter Node Cli Usage: fvn [OPTIONS] COMMAND Commands: deepseek-fhe-vote let deepseek think and predict, and then encrypted by FHE and submit to Mind Network for model consensus check-hot-wallet-address check hot wallet address, by default will use ./config/config_fvn.toml check-gas-balance check hot wallet gas balance, need gas fee to vote check-registration check if hot wallet has registered with a particular voter wallet register register voter address check-vote-rewards check voting rewards check-vote check voting tx history on the explore help Print this message or the help of the given subcommand(s) Options: --node-config-file NODE_CONFIG_FILE fvn config file, contains all the config to run fvn [default: ./config/config_fvn.toml] --log-level LOG_LEVEL control level of print, useful for debug, default is info [default: info] [possible values: debug, info, warn, error] --hot-wallet-private-key HOT_WALLET_PRIVATE_KEY fvn wallet private key is needed if to load a different wallet from config_fvn.toml to sign the message onchain, by default load from ./config/config_fvn.toml -h, --help Print help -V, --version Print version子命令语义子命令作用deepseek-fhe-vote核心命令让 DeepSeek 思考并预测随后用 FHE 加密将密文提交到 Mind Network 参与模型共识check-hot-wallet-address查询热钱包地址默认读取./config/config_fvn.tomlcheck-gas-balance查询热钱包 Gas 余额——投票需要 Gas 费用余额不足将无法投票check-registration检查热钱包是否已与某个投票者钱包完成注册绑定register voter_address注册投票者地址check-vote-rewards查询投票奖励check-vote在区块浏览器上查询投票交易历史全局选项选项含义与默认值--node-config-file PATH指定 FVN 节点配置文件包含运行所需全部配置默认./config/config_fvn.toml--log-level LEVEL控制日志打印级别便于调试默认info可选debug、info、warn、error--hot-wallet-private-key KEY需要绕过配置文件加载其他钱包时用它直接传入热钱包私钥以完成链上消息签名默认从./config/config_fvn.toml读取-h, --help/-V, --version打印帮助 / 版本CLI 模型里存在两类钱包热钱包hot wallet负责实际发起链上交易与签名投票者钱包voter wallet通过register与之绑定。这也是为什么示例序列总是「先 register再 check-registration / deepseek-fhe-vote / check-vote-rewards」。CLI 实战演练与输出解读文档给出了完整的命令执行示例及其 JSON 输出下面按运行顺序解读。运行 deepseek-fhe-vote一键完成预测 加密 上链投票./bin/deepseek --log-levelinfo deepseek-fhe-vote { app: deepseek, command: deepseek-fhe-vote, arg: deekseek predicted BTC price: 95833, hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: true, result: 0x42d78185e4779dd3105598ac4f2786998c5059f8381a55daec12e4ffcc952a56, note: deekseek predicted BTC price: 95833, gas_sued: 304749, block_number: 26373, tx_hash: 0x42d78185e4779dd3105598ac4f2786998c5059f8381a55daec12e4ffcc952a56 }这是整条链路的一站式演示arg字段显示 DeepSeek 预测出 BTC 价格为 95833发起方为热钱包0x6224...result/note给出本次投票交易的回执信息——包括交易哈希tx_hash、消耗 Gas输出中写作gas_sued应为gas_used的笔误与所在区块号block_number。JSON 中的status: true表示整条推理→加密→提交流程成功完成。查询热钱包地址与 Gas 余额./bin/deepseek --log-levelinfo check-hot-wallet-address { app: deepseek, command: check-hot-wallet-address, arg: , status: true, result: 0x64FF17078669A507D0c831D9E844AF1C967604Dd, note: }check-hot-wallet-address直接返回当前配置对应的热钱包地址。./bin/deepseek --log-levelinfo check-gas-balance { app: deepseek, command: check-gas-balance, arg: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: true, result: 197015375000000, note: }check-gas-balance返回热钱包的 Gas 余额以最小单位表示的整数。帮助信息已明确指出需要 Gas 费用才能投票因此该命令常用于投票前的资金检查。注册前检查未注册的热钱包./bin/deepseek --log-levelinfo check-registration { app: deepseek, command: check-registration, arg: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: false, result: , note: hot wallet is not registered with any voter wallet }输出status: false并提示 hot wallet is not registered with any voter wallet说明该热钱包尚未与任何投票者钱包绑定——这正是接下来需要执行register的原因。注册投票者钱包./bin/deepseek --log-levelinfo register 0x06eF5C5ba427434bf36469B877e4ea9044D1b735 { app: deepseek, command: register, arg: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, voter_wallet: 0x06eF5C5ba427434bf36469B877e4ea9044D1b735, status: true, result: registration successful !, note: is_registered: true, hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, voter_wallet: 0x06eF5C5ba427434bf36469B877e4ea9044D1b735 }register接受一个投票者钱包地址作为位置参数成功后result为 registration successful !note中is_registered: true表明绑定关系已写入链上。注册前后对比投票奖励从 0 到有值注册前查询奖励./bin/deepseek --log-levelinfo check-vote-rewards { app: deepseek, command: check-vote-rewards, arg: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: false, result: 0, note: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, voter_wallet: , vote_rewards: 0 }注册并参与投票后再查询./bin/deepseek --log-levelinfo check-vote-rewards { app: deepseek, command: check-vote-rewards, arg: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: true, result: 206095238095238095, note: hot_wallet: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, voter_wallet: 0x06eF5C5ba427434bf36469B877e4ea9044D1b735, vote_rewards: 206095238095238095 }前后对比非常直观voter_wallet从空变为已绑定的投票者地址vote_rewards从0变为206095238095238095以最小单位计数的投票奖励status也翻转为true。查询投票交易历史./bin/deepseek --log-levelinfo check-vote { app: deepseek, command: check-vote, arg: 0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, status: true, result: check on the explore: testnet: https://explorer-testnet.mindnetwork.xyz/address/0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, mainnet: https://explorer.mindnetwork.xyz/address/0x6224F72f1439E76803e063262a7e1c03e86c6Dbd, note: }check-vote会返回区块浏览器中该钱包地址的查询入口分别覆盖 Mind Network 的 testnet 与 mainnet 两条网络用于人工核对投票交易历史。一条推荐的完整操作时序综合以上命令与输出一个最小可行的 FHE Voter 节点使用流程是准备check-hot-wallet-address确认热钱包地址check-gas-balance确认 Gas 充足绑定register voter_wallet注册投票者钱包随后用check-registration复核未绑定前会返回 not registered投票执行deepseek-fhe-vote让 DeepSeek 预测 → FHE 加密 → 密文上链从回执中读取tx_hash与block_number对账用check-vote-rewards查询累积奖励用check-vote到区块浏览器核对历史投票交易。实践注意事项Gas 是投票前置条件deepseek-fhe-vote需要链上交易务必先通过check-gas-balance确认热钱包有足够 Gas。先注册再投票热钱包必须与投票者钱包完成register绑定否则check-registration会提示未注册奖励查询也会返回空voter_wallet与0奖励。配置文件承载全部运行参数CLI 的默认配置路径是./config/config_fvn.toml多节点场景下应分别为每台节点准备独立配置如示例中的config_fvn_1.toml、config_fvn_2.toml并通过--node-config-file显式指定若想临时换用其他热钱包可用--hot-wallet-private-key覆盖而不必改动配置文件。私钥安全--hot-wallet-private-key直接暴露在命令行中调试用途居多生产环境建议优先使用配置文件且妥善保护私钥文件权限。提示词决定结果可解析性库调用示例要求模型返回正整数随后代码才可按u128解析业务 prompt 必须对输出格式做同样的强约束否则应处理Err(_) 0这类兜底分支。隐私边界文档示例全程只出现 FHE 公钥加载与本地加密密文经 Base64 序列化后才离开本机上链明文预测结果不出本地这是该方案隐私设计的核心。开源许可与延伸阅读本项目以MIT License开源。关于其行业定位FHE 为什么被视为能在加密数据上直接计算、从而让 AI Agent 使用 DeepSeek 时不暴露数据的关键技术可回到仓库主索引 README.md 的FHE (Fully Homomorphic Encryption) frameworks分类查看上下文本文技术细节的原始出处即仓库内的 docs/fhe.mind-network/README.md 文档其中还保留了完整的 Usage、Quick Start、CLI Help 与各命令 JSON 输出示例可作为接入时的直接参考。如有问题也可通过 Mind Network 官方渠道获取支持。【免费下载链接】awesome-deepseek-integrationIntegrate the DeepSeek API into popular software项目地址: https://gitcode.com/GitHub_Trending/aw/awesome-deepseek-integration创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考