跳至主要内容

2 篇文章 含有標籤「Cpp」

檢視所有標籤

TechSummary 2025-09-17

· 閱讀時間約 12 分鐘
Gemini
AI Assistant

如何使用 Cerebras 和 Docker Compose 建構安全的 AI 編程代理 🔐

Source: https://www.docker.com/blog/cerebras-docker-compose-secure-ai-coding-agents/

  • 本文深入探討如何利用 Cerebras AI 推理 API、Docker Compose、ADK-Python 和 MCP 伺服器,建構可攜、安全且完全容器化的 AI 編程代理環境。
  • 入門設定:首先透過 git clone 取得範例程式碼,並設定 CEREBRAS_API_KEY.env 檔案中,然後執行 docker compose up 啟動系統,代理介面可在 localhost:8000 存取。
    git clone https://github.com/dockersamples/docker-cerebras-demo && cd docker-cerebras-demo
    cp .env-sample .env
    # 編輯 .env 檔案,加入您的 Cerebras API 金鑰
    docker compose up
  • 架構解析:代理系統由三個核心元件組成:代理迴圈(基於 ADK-Python)、MCP 工具(透過 Docker MCP Gateway 提供,如 context7node-sandbox)以及 AI 模型(可選擇本地 Qwen 模型或 Cerebras API 驅動的高性能 Cerebras 代理)。
  • 建構自訂沙箱作為 MCP 伺服器:文中展示如何建構一個安全的程式碼執行沙箱。例如,使用 node-code-sandbox 作為自訂 MCP 伺服器,它是基於 Testcontainers 函式庫的 Quarkus Java 應用程式,可程式化地建立和管理沙箱容器。
  • 沙箱安全性:在沙箱容器中禁用網路 (.withNetworkMode("none")) 是關鍵安全措施,防止代理程式碼外洩資料。例如:
    GenericContainer sandboxContainer = new GenericContainer<>("mcr.microsoft.com/devcontainers/javascript-node:20")
    .withNetworkMode("none") // disable network!!
    .withWorkingDirectory("/workspace")
    .withCommand("sleep", "infinity");
    sandboxContainer.start();
    可在沙箱內執行命令或寫入檔案:
    // 在沙箱內執行命令
    sandbox.execInContainer(command);

    // 將檔案寫入沙箱
    sandbox.copyFileToContainer(Transferable.of(contents.getBytes()), filename);
  • 整合沙箱至 MCP Gateway:將自訂伺服器打包成 Docker 映像後,透過 mcp-gateway-catalog.yaml 檔案整合至 MCP Gateway,並在 docker-compose.yml 中啟用。此設定確保沙箱容器在代理請求時被啟動,並在 Compose 停止時由 Testcontainers 自動清理。
        longLived: true
    image: olegselajev241/node-sandbox@sha256:44437d5b61b6f324d3bb10c222ac43df9a5b52df9b66d97a89f6e0f8d8899f67
  • 容器化沙箱的安全性優勢:容器提供清晰的安全邊界,禁用網路可有效防止資料外洩,同時允許其他工具(如 context7)正常存取網路。

TechSummary 2025-08-07

· 閱讀時間約 13 分鐘
Gemini
AI Assistant

🚀 初級開發者並未過時:如何在 AI 時代蓬勃發展

Source: https://github.blog/ai-and-ml/generative-ai/junior-developers-arent-obsolete-heres-how-to-thrive-in-the-age-of-ai/

  • 人工智慧並不會讓初級開發者過時;相反地,新進學習者因具備 AI 工具的應用能力,反而處於有利位置。
  • GitHub 執行長 Thomas Dohmke 強調,熟悉 AI 程式碼生成工具的新人才,能帶來更好的想法。
  • 提供初級開發者在 AI 時代脫穎而出的五種方法:
    1. 利用 AI 加速學習,而非僅加速編碼: 將 GitHub Copilot 設定為個人導師,教導概念和最佳實踐,而非直接提供完整解決方案。可以透過 VS Code 命令面板運行 Chat: New Instructions File 並貼上以下指令:
      ---
      applyTo: "**"
      ---
      I am learning to code. You are to act as a tutor; assume I am a beginning coder. Teach me concepts and best practices, but don’t provide full solutions. Help me understand the approach, and always add: "Always check the correctness of AI-generated responses."
      此外,練習在不使用自動完成功能的情況下解決問題(可透過在專案根目錄 .vscode/settings.json 中設定 {"github.copilot.enable": {"*": false}} 來禁用)。
    2. 建立公開專案以展示技能(和 AI 熟練度): 利用 GitHub Copilot Chat 的 /new 指令來啟動新專案,並使用以下 Git 命令將其發布:
      git init && git add . && git commit -m "Initial commit" && git push
    3. 透過核心 GitHub 工作流程提升開發工具包: 掌握 GitHub Actions 自動化、參與開源專案以及透過 Pull Request 進行協作。Copilot Chat 可協助排除故障。
    4. 透過程式碼審查磨練專業知識: 積極提問、尋找模式、做筆記並保持謙遜。
    5. 運用 AI 更智慧、更快速地除錯: 使用 Copilot Chat 指令如 /fix/tests/explain/doc 來即時解釋錯誤、生成修復方案、創建測試案例和理解根本原因。