Studio: prompt variables into prompt editor (#6434)
* add custom and system variable feature in system prompt * missing function use * feat: prompt variables editor ux Co-authored-by: CodeMan62 <175127021+CodeMan62@users.noreply.github.com> * fix: guard prompt variable defaults * refine prompt variables editor layout * fix: harden prompt variable substitution * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refine prompt variables editor copy and built-in token labels --------- Co-authored-by: CodeMan62 <sharmahimanshu15082007@gmail.com> Co-authored-by: CodeMan62 <175127021+CodeMan62@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Leo Borcherding <borchborchmail@gmail.com>
This commit is contained in:
parent
a636693019
commit
c873ef052d
8 changed files with 322 additions and 16 deletions
42
tests/studio/test_chat_prompt_variables.py
Normal file
42
tests/studio/test_chat_prompt_variables.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""Regression checks for system prompt variable substitution."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parents[2]
|
||||
ADAPTER_SRC = (WORKSPACE / "studio/frontend/src/features/chat/api/chat-adapter.ts").read_text()
|
||||
|
||||
|
||||
def _function_source(name: str) -> str:
|
||||
start = ADAPTER_SRC.index(f"function {name}")
|
||||
body_start = ADAPTER_SRC.index("{", start)
|
||||
depth = 0
|
||||
for index in range(body_start, len(ADAPTER_SRC)):
|
||||
if ADAPTER_SRC[index] == "{":
|
||||
depth += 1
|
||||
elif ADAPTER_SRC[index] == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return ADAPTER_SRC[start : index + 1]
|
||||
raise AssertionError(f"Could not parse function body for {name}")
|
||||
|
||||
|
||||
def test_prompt_variable_builtins_use_local_time_helpers():
|
||||
resolver = _function_source("resolveSystemPromptVariables")
|
||||
assert "formatLocalDate(now)" in resolver
|
||||
assert "formatLocalTime(now)" in resolver
|
||||
assert "formatTimezoneOffset(now)" in resolver
|
||||
assert "toISOString()" not in resolver
|
||||
|
||||
|
||||
def test_prompt_variable_builtins_use_own_property_lookup():
|
||||
resolver = _function_source("resolveSystemPromptVariables")
|
||||
assert "if (hasOwn(systemVariables, key))" in resolver
|
||||
assert "key in systemVariables" not in resolver
|
||||
|
||||
|
||||
def test_prompt_variable_nested_lookup_ignores_prototype_properties():
|
||||
nested_lookup = _function_source("getNestedValue")
|
||||
assert "if (!hasOwn(current, part))" in nested_lookup
|
||||
Loading…
Add table
Add a link
Reference in a new issue