我在 5 天内将 OpenAI Python SDK 移植到 Rust

📄 中文摘要

为了实现一个实时语音代理项目,开发者需要一个快速的 OpenAI 客户端,尽管官方的 Python SDK 表现出色,但开发者选择了 Rust,以便进行 WebSocket 音频流传输、边缘部署到 Cloudflare Workers,并在多个工具调用的代理循环中实现亚秒级延迟。因此,开发者完成了 SDK 的移植工作,提交了 259 次代码,耗时 5 天,涵盖了 100 多个 API 方法。在第一天,开发者进行了 120 次提交,主要是利用 Claude Code 将 Python 类型转换为 Rust,同时设置了预提交钩子、WASM 检查和基准测试。后续工作集中在架构决策、性能调优以及 Node/Python 绑定上。最终成果是一个名为 openai-oxide 的 Rust 客户端,它的 API 接口与官方 Python SDK 相匹配,同时具有更快的性能和可部署到 WASM 的能力。

📄 English Summary

I ported the OpenAI Python SDK to Rust in 5 days with Claude Code.

A fast OpenAI client was needed for a real-time voice agent project, leading to the decision to port the official Python SDK to Rust. The Rust implementation was chosen for its advantages in WebSocket audio streaming, edge deployment to Cloudflare Workers, and sub-second latency in agentic loops with numerous tool calls. The porting process involved 259 commits over 5 days, with the first day accounting for 120 commits primarily focused on translating types from Python to Rust using Claude Code, while also setting up pre-commit hooks, WASM checks, and benchmarks. Subsequent days were dedicated to architectural decisions, performance tuning, and creating Node/Python bindings. The end result is openai-oxide, a Rust client that matches the API surface of the official Python SDK while offering improved speed and WASM deployment capabilities.

Powered by Cloudflare Workers + Payload CMS + Claude 3.5

数据源: OpenAI, Google AI, DeepMind, AWS ML Blog, HuggingFace 等