[bot] Add Replicate Python SDK integration for model run, stream, and async execution instrumentation (345,748 weekly downloads)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
首先查看 py/src/braintrust/integrations/、py/src/braintrust/wrappers/、py/noxfile.py、integrations/init.py、integrations/versioning.py 和 py/pyproject.toml,以了解 integration 的注册和测试方式。在确定 replicate.run()、async_run()、stream()、async_stream() 以及 Client 和 AsyncClient 接口的覆盖范围之前,先比较现有的 integration。完成的标准是 Replicate tracing、流式聚合、异步执行、注册、版本管理和测试都得到覆盖。
由索引模型根据 Issue 内容生成。
描述
Summary
The Replicate Python SDK (replicate) is the official client for the Replicate platform, which hosts 100k+ machine learning models for language generation, image synthesis, video, audio, and more. Its primary execution surface is replicate.run(model, input={}) and replicate.async_run() — a platform-agnostic model execution API distinct from any provider-specific format. This repository has zero instrumentation for any Replicate SDK surface — no integration directory, no wrapper, no patcher, no auto_instrument() support.
The Replicate API is fundamentally different from OpenAI-style APIs: there is no chat.completions.create() shape, model identifiers are version strings (e.g. "meta/llama-3-70b-instruct:..." or "owner/model"), and streaming is token-by-token via an iterator. wrap_openai() cannot be used with the Replicate client. Users who follow Replicate's official documentation and pip install replicate get zero Braintrust tracing.
What needs to be instrumented
The replicate package exposes these execution surfaces via module-level functions and the Client class, none of which are instrumented:
Model execution (highest priority)
| SDK Method | Description | Streaming | Return type |
|---|---|---|---|
replicate.run(model, input) |
Sync model execution — runs a model version and returns the complete output | stream=True yields ServerSentEvent objects |
str, list, or model-specific output |
replicate.async_run(model, input) |
Async model execution | stream=True yields ServerSentEvent |
Same as sync |
replicate.stream(model, input) |
Sync streaming execution — returns an iterator of output tokens/chunks | Always streaming | Iterator[ServerSentEvent] |
replicate.async_stream(model, input) |
Async streaming execution | Always streaming | AsyncIterator[ServerSentEvent] |
Span shape for language models: The model parameter (a version string) maps to span metadata model. Inputs are the input dict (contains prompt, system_prompt, max_tokens, etc. depending on model). Output is the concatenated string of streamed tokens. Token usage is not returned by the standard API (models expose usage differently), so metrics may require best-effort extraction from model-specific output.
Predictions API (lower priority)
| SDK Method | Description | Return type |
|---|---|---|
replicate.predictions.create() |
Create a model prediction (lower-level than run()) |
Prediction |
replicate.predictions.get() |
Poll a prediction by ID | Prediction |
Deployments (lower priority)
| SDK Method | Description |
|---|---|
replicate.deployments.predictions.create() |
Run a model via a named deployment |
All module-level functions delegate to a default Client instance. Client and AsyncClient have corresponding instance methods.
Implementation notes
Model ID format: replicate.run() accepts model as either "owner/model" (latest version) or "owner/model:version_hash". The integration should extract and log both the model name and version.
No single response type: Unlike OpenAI where all chat completions return ChatCompletion, Replicate output varies by model (strings, lists of strings, dicts, file URLs). The integration should log the raw output and handle streaming aggregation generically.
Streaming: stream=True in run() and the dedicated stream() function yield ServerSentEvent objects with data fields. Accumulated output should be logged as the span output.
Async first-class: The SDK has AsyncClient with async_run() and async_stream() — both must be instrumented.
input dict as span input: The input dict is model-specific but typically contains prompt, system_prompt, max_tokens, temperature, etc. for language models.
No coverage in any instrumentation layer
- No integration directory (
py/src/braintrust/integrations/replicate/) - No wrapper function (e.g.
wrap_replicate()) - No patcher in any existing integration
- No nox test session (
test_replicate) - No version entry in
py/src/braintrust/integrations/versioning.py - No mention in
py/src/braintrust/integrations/__init__.py - No entry in
[tool.braintrust.matrix]inpy/pyproject.toml
A grep for replicate across py/src/braintrust/ returns zero matches in integration code.
Braintrust docs status
not_found — Replicate is not listed on the Braintrust integrations directory or the tracing guide.
Upstream references
- Replicate Python SDK on PyPI: https://pypi.org/project/replicate/
- Replicate Python SDK on GitHub: https://github.com/replicate/replicate-python
- Replicate API reference: https://replicate.com/docs/reference/http
- Replicate Python client docs: https://replicate.com/docs/get-started/python
- Replicate streaming guide: https://replicate.com/docs/topics/streaming
Local repo files inspected
py/src/braintrust/integrations/— noreplicate/directory exists onmainpy/src/braintrust/wrappers/— no Replicate wrapperpy/noxfile.py— notest_replicatesessionpy/src/braintrust/integrations/__init__.py— Replicate not listed in integration registrypy/src/braintrust/integrations/versioning.py— no Replicate version matrixpy/pyproject.toml— no Replicate entries in[tool.braintrust.matrix]- Full repo grep for "replicate" across
py/src/braintrust/— zero matches
- 主要语言
- Python
- 星标
- 21
- 派生
- 23
- 平均合并
- 18 小时 23 分钟
- 30 天内合并 PR
- 104
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
braintrustdata/braintrust-sdk-python 的其他 Issue
-
feature python
难度 2/5 1-3 小时 新手友好度 76/100
braintrustdata/braintrust-sdk-python#868 ·
维护者通常 1 天内回复
-
new-integration python
难度 4/5 3-5 天 新手友好度 55/100
braintrustdata/braintrust-sdk-python#854 ·
维护者通常 1 天内回复
-
new-integration python
难度 5/5 一周以上 新手友好度 35/100
braintrustdata/braintrust-sdk-python#853 ·
维护者通常 1 天内回复
-
new-integration python
难度 4/5 3-5 天 新手友好度 52/100
braintrustdata/braintrust-sdk-python#852 ·
维护者通常 1 天内回复
-
Migrate legacy HTTPConnection callers to the policy-aware Transport incrementally可能已有人在做 @AbhiPrasad 于 8 天前认领。 未关闭python
braintrustdata/braintrust-sdk-python#839 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 braintrustdata/braintrust-sdk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
aicell-lab/bioengine#232 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
modelscope/evalscope#1836 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
jbaruch/speaker-toolkit#480 ·
维护者通常 1 天内回复