[bot] Add AI21 Labs Python SDK integration for chat completions and embeddings instrumentation (54,424 weekly downloads)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
首先比较 py/src/braintrust/integrations/ 下的 OpenAI 或 Mistral 集成模式,然后检查 py/noxfile.py 以及 issue 中所列的集成注册和版本管理文件。实现对同步和异步 chat completions、streaming 及 embeddings 的覆盖,包括文档中说明的元数据,并添加该集成的测试、注册、版本条目和依赖矩阵条目。
由索引模型根据 Issue 内容生成。
描述
Summary
The AI21 Python SDK (ai21) is the official Python client for AI21 Labs' inference platform, which provides the Jamba model family — hybrid SSM-Transformer models optimized for long-context tasks and high throughput. Its AI21Client and AsyncAI21Client expose client.chat.completions.create() and client.embed.create() APIs. This repository has zero instrumentation for any AI21 SDK surface — no integration directory, no wrapper, no patcher, no auto_instrument() support.
AI21's Python SDK uses its own client class (ai21.AI21Client), which is not a subclass of openai.OpenAI, so wrap_openai() cannot be used with it. The pattern is the same as Groq, Mistral, and OpenRouter — OpenAI-compatible endpoint but a distinct Python client requiring a dedicated integration. Users who follow AI21's official documentation and pip install ai21 get zero Braintrust tracing.
What needs to be instrumented
The ai21 package exposes these execution surfaces via AI21Client and AsyncAI21Client, none of which are instrumented:
Chat completions (highest priority)
| SDK Method | Description | Streaming | Return type |
|---|---|---|---|
client.chat.completions.create() |
Chat completions with tool calling, structured output, and document grounding | stream=True returns Stream[ChatCompletionChunk] |
ChatCompletion |
Response shape is OpenAI-compatible: ChatCompletion has choices, usage (prompt_tokens, completion_tokens, total_tokens), model, id — standard span metrics extraction follows the OpenAI pattern.
Streaming: stream=True returns a Stream[ChatCompletionChunk] iterator. The integration must handle the streaming span lifecycle.
Embeddings
| SDK Method | Description | Return type |
|---|---|---|
client.embed.create() |
Text embeddings generation for semantic search and RAG | EmbedResponse |
Both sync (AI21Client) and async (AsyncAI21Client) clients exist with identical method signatures.
Implementation notes
Stainless-generated SDK (v3.x): The ai21 v3.x package (current major version) is generated by Stainless (same toolchain as OpenAI, Groq, Mistral). The client structure mirrors the OpenAI SDK, so the patcher/wrapper pattern from the OpenAI or Mistral integration can serve as a close structural reference.
chat.completions.create() parameters relevant for span metadata: model, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, n, stop, tools, tool_choice, response_format, documents (AI21-specific grounding feature).
Document grounding: The documents parameter is AI21-specific and allows grounding responses in provided documents. This should be captured in span input metadata when present.
Model family: Jamba 1.6 Large and Jamba 1.6 Mini are the primary models. Response model field should be captured in span metadata.
No coverage in any instrumentation layer
- No integration directory (
py/src/braintrust/integrations/ai21/) - No wrapper function (e.g.
wrap_ai21()) - No patcher in any existing integration
- No nox test session (
test_ai21) - 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 ai21 across py/src/braintrust/ returns zero matches.
Braintrust docs status
not_found — AI21 is not listed on the Braintrust integrations directory or the tracing guide.
Upstream references
- AI21 Python SDK on PyPI: https://pypi.org/project/ai21/
- AI21 Python SDK on GitHub: https://github.com/AI21Labs/ai21-python
- AI21 API reference: https://docs.ai21.com/reference/
- AI21 Chat Completions docs: https://docs.ai21.com/reference/jamba-15-api-ref
- AI21 Embeddings docs: https://docs.ai21.com/reference/embeddings-ref
- AI21 SDK quickstart: https://docs.ai21.com/docs/quickstart
Local repo files inspected
py/src/braintrust/integrations/— noai21/directory exists onmainpy/src/braintrust/wrappers/— no AI21 wrapperpy/noxfile.py— notest_ai21sessionpy/src/braintrust/integrations/__init__.py— AI21 not listed in integration registrypy/src/braintrust/integrations/versioning.py— no AI21 version matrixpy/pyproject.toml— no AI21 entries in[tool.braintrust.matrix]- Full repo grep for "ai21" across
py/src/braintrust/— zero matches
- 主要语言
- Python
- 星标
- 21
- 派生
- 23
- 平均合并
- 20 小时 2 分钟
- 30 天内合并 PR
- 95
环境准备
- 提供 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 天内回复
-
feature integration: mistral python
难度 2/5 1-3 小时 新手友好度 75/100
braintrustdata/braintrust-sdk-python#867 ·
维护者通常 1 天内回复
-
[bot] Google GenAI: streaming responses drop `url_context_metadata` that non-streaming responses preserve可能已有人在做 @Kayvan-Zahiri 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
braintrustdata/braintrust-sdk-python#774 ·
维护者通常 1 天内回复
-
feature python
难度 3/5 1-2 天 新手友好度 72/100
braintrustdata/braintrust-sdk-python#866 ·
维护者通常 1 天内回复
-
feature python
难度 4/5 3-5 天 新手友好度 55/100
braintrustdata/braintrust-sdk-python#863 ·
维护者通常 1 天内回复
查看 braintrustdata/braintrust-sdk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/inspect_ai#5781 ·
维护者通常 2 天内回复
-
Bump .cicd to wamp-cicd 4c2f9ac: `just land` refuses open A18 decisions, `just where` lists them未关闭
难度 1/5 1 小时以内 新手友好度 82/100
crossbario/cfxdb#139 ·
-
Bump .cicd to wamp-cicd 4c2f9ac: `just land` refuses open A18 decisions, `just where` lists them未关闭
难度 1/5 1 小时以内 新手友好度 84/100
crossbario/txaio#241 ·
-
UX
难度 2/5 1-3 小时 新手友好度 82/100
mediajunkie/piper-morgan-product#1963 ·
-
难度 2/5 1-3 小时 新手友好度 64/100