feat(prompts): Fetch prompts by label - #4163
Conversation
|
Reviews (1): Last reviewed commit: "feat(ai): fetch prompts by label" | Re-trigger Greptile |
| const versionQuery = version === undefined ? '' : `&version=${encodeURIComponent(String(version))}` | ||
| const promptLabel = this.getPromptLabel(name, version) | ||
| const url = `${this.host}/api/environments/@current/llm_prompts/name/${encodedPromptName}/?token=${encodedProjectApiKey}${versionQuery}` | ||
| const labelQuery = label === undefined ? '' : `&label=${encodeURIComponent(label)}` |
There was a problem hiding this comment.
Empty Label Becomes Ambiguous Request
When a configured label resolves to an empty string, this path sends label= and caches the response under the empty-string key. If the API treats an empty label as missing or rejects it, callers either receive the latest prompt instead of a labeled prompt or unexpectedly fall back; reject empty labels before building the request.
There was a problem hiding this comment.
No, empty label will be rejected with a 400, and thus never cached
There was a problem hiding this comment.
Fair enough — a 400 will throw before any caching happens, so the failure is explicit rather than silent. My concern doesn't apply here.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.
|
Size Change: +2.68 kB (+0.02%) Total Size: 17.5 MB
ℹ️ View Unchanged
|
Radu-Raicea
left a comment
There was a problem hiding this comment.
Also needs the deploy changeset/label added.
I noticed on both this one and the Python library PR that you don't verify that the response prompt's label matches the requested one. It can be what we want, up to you.
|
Problem
PostHog prompt management is gaining labels: movable pointers from a name like
productionto exactly one version of a prompt, so a version can be released or rolled back without a code deploy (PostHog/posthog#70862, PostHog/posthog#71509). The@posthog/aiPrompts class can fetch by name or version number, but not by label — and fetching by label is the way labels are meant to be consumed.Changes
Adds a
labeloption toPrompts.get():labelis passed as a query param on the existing fetch endpoint; mutually exclusive withversion(throws if both are given, matching the API's 400)PromptRemoteResultand the cache carry alabelfield, so callers can see which label a prompt resolved throughDraft until the backend PR (PostHog/posthog#71509) is deployed: the API ignores unknown query params, so releasing this first would send
label=productionand silently get the latest version back. Mirrors PostHog/posthog-python#744.How did you test this code?
New jest cases: the label query param is sent and label metadata comes back on the result, version+label together throws before any fetch, and labeled fetches are cached separately from latest fetches (without the cache-key change, a labeled fetch after a latest fetch silently returns the wrong version). Full
prompts.test.tssuite passes (49 tests), eslint clean; the two pre-existing tsc errors incaptureAiGeneration.tsagainst a stale core build are unrelated to this change.