-
[OPIK-6467] [SDK] feat: add prompt version support (#6805)
发布于
2026-05-21 15:12:25 +00:00 - [OPIK-6467] [SDK] feat: fetch prompt versions by sequential v
Adds a
versionselector toOpik.get_prompt/get_chat_prompt
(Python) andOpikClient.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 newversion_numberfield added in OPIK-6454.The existing
commitparameter is kept for backwards compatibility but
marked deprecated in docstrings/JSDoc; passing bothcommitand
versionraises locally with a clear error. The returned Prompt /
ChatPrompt object now exposes aversionattribute populated from the
backend'sversion_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). Onlycommitpins indefinitely; a sequentialversionlike
"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, andprompt.versionpopulation, 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_namefixture (project deleted on teardown) and prompt
names from theprompt_namefixture. 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
versionparameter to the end of the positional list in
bothOpik.get_promptandOpik.get_chat_promptso old positional
calls likeclient.get_prompt(name, commit, project_name, no_cache)
continue to bind correctly. Inserting it betweencommitand
project_namesilently shifted args, sendingproject_nameto
versionand 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_numberwhenever it is set (mask versions still omit
it). This makes the auto-injectedmetadata["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_entryhelper to assert the new
field. The existingtest_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
下载附件