发布

  • [OPIK-6467] [SDK] feat: add prompt version support (#6805)

    frostbyte_neo 发布于 2026-05-21 15:12:25 +00:00

    • [OPIK-6467] [SDK] feat: fetch prompt versions by sequential v

    Adds a version selector to Opik.get_prompt / get_chat_prompt
    (Python) and OpikClient.getPrompt / getChatPrompt (TypeScript)
    accepting wire format "v" (e.g. "v3"). The selector is forwarded to
    the backend's POST /v1/private/prompts/versions/retrieve endpoint as
    the new version_number field added in OPIK-6454.

    The existing commit parameter is kept for backwards compatibility but
    marked deprecated in docstrings/JSDoc; passing both commit and
    version raises locally with a clear error. The returned Prompt /
    ChatPrompt object now exposes a version attribute populated from the
    backend's version_number.

    Cache: the version selector reuses the existing commit slot in the
    cache key (commits are 8 hex chars, versions match v\d+ — they cannot
    collide). Only commit pins indefinitely; a sequential version like
    "v3" can be reassigned by the backend if the underlying version is
    deleted and recreated, so it follows the normal TTL refresh.

    Includes unit tests covering selector threading, mutual-exclusion
    validation, cache disambiguation, and prompt.version population, plus
    E2E / integration tests that create three versions and round-trip each
    sequential identifier (and verify the unselected fetch returns latest).

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • extend promptversion in TS as well

    • update comparison logic

    • getVersion update

    • ts doc

    • test: use temporary_project_name and prompt_name fixtures in e2e prompts

    Refactor every test in tests/e2e/test_prompt.py to follow the e2e isolation
    contract in sdks/python/AGENTS.md: project names now come from the
    temporary_project_name fixture (project deleted on teardown) and prompt
    names from the prompt_name fixture. Tests that need multiple prompts
    derive distinct names by appending a suffix to the fixture-provided name.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • fix ts test

    • fix: preserve positional arg order in Opik.get_prompt/get_chat_prompt

    Move the new version parameter to the end of the positional list in
    both Opik.get_prompt and Opik.get_chat_prompt so old positional
    calls like client.get_prompt(name, commit, project_name, no_cache)
    continue to bind correctly. Inserting it between commit and
    project_name silently shifted args, sending project_name to
    version and producing wrong-prompt or None results.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • refactor(ts): rename getVersion param from versionOrCommit to version

    New callers see a clear, single-purpose parameter name that matches the
    preferred input form. Existing callers are unaffected — TypeScript only
    exposes positional arguments at the call site, so the rename does not
    change any installed-base code. The dispatch logic (/^v\d+$/ selects
    the versionNumber endpoint; anything else falls back to the deprecated
    commit endpoint) is unchanged.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • feat(py): expose version_number in opik_prompts trace metadata

    Extend Prompt.__internal_api__to_info_dict__ and the chat-prompt
    counterpart to include the sequential version identifier under
    version.version_number whenever it is set (mask versions still omit
    it). This makes the auto-injected metadata["opik_prompts"] entries
    on traces/spans carry the user-facing version (e.g. "v3") alongside
    the legacy commit hash, matching the same field on the prompt objects.

    Extend the e2e verify_opik_prompt_entry helper to assert the new
    field. The existing test_prompt__auto_inject_into_trace__happyflow
    test calls this helper for both a text and a chat prompt, so the e2e
    coverage is picked up automatically.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com


    Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com

    下载附件