Spaces:
Sleeping
Sleeping
changes lsp wrapper imports
Browse files- src/lsp_wrappers.py +15 -42
src/lsp_wrappers.py
CHANGED
|
@@ -1,33 +1,19 @@
|
|
| 1 |
"""
|
| 2 |
Wrappers around lsp/src/prompts/*.
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
These names don't collide with the app's own src/prompts.py, which is
|
| 12 |
-
always imported as src.prompts.
|
| 13 |
"""
|
| 14 |
-
from prompts.seller_system.preference import get_seller_system_prompt as _pref_seller_prompt
|
| 15 |
-
from prompts.seller_system.likelihood import get_seller_system_prompt as _like_seller_prompt
|
| 16 |
-
from prompts.survey_prompts import (
|
| 17 |
-
preference_initial,
|
| 18 |
-
preference_final,
|
| 19 |
-
likelihood_initial,
|
| 20 |
-
likelihood_final,
|
| 21 |
-
)
|
| 22 |
|
| 23 |
|
| 24 |
# ββ Demographics (must match training code exactly) βββββββββββββββββββββββββββ
|
| 25 |
|
| 26 |
def format_demographics(demo: dict) -> str:
|
| 27 |
-
"""
|
| 28 |
-
Format participant demographics as a comma-separated 'key: value' string.
|
| 29 |
-
Matches lsp training code's format_demographics exactly.
|
| 30 |
-
"""
|
| 31 |
return ", ".join(f"{k}: {v}" for k, v in demo.items())
|
| 32 |
|
| 33 |
|
|
@@ -50,11 +36,6 @@ def _feat_str(product: dict) -> str:
|
|
| 50 |
# ββ Product overview formatters βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 51 |
|
| 52 |
def product_overview(product: dict, include_features: bool) -> str:
|
| 53 |
-
"""
|
| 54 |
-
Format a single product for likelihood_initial / likelihood_final.
|
| 55 |
-
|
| 56 |
-
Features included only when include_features=True (likelihood + groceries only).
|
| 57 |
-
"""
|
| 58 |
lines = [
|
| 59 |
f"Product: {product.get('title', '')}",
|
| 60 |
f"Price: {product.get('price', '')}",
|
|
@@ -68,10 +49,7 @@ def product_overview(product: dict, include_features: bool) -> str:
|
|
| 68 |
|
| 69 |
|
| 70 |
def pair_overview(pair: dict) -> str:
|
| 71 |
-
"""
|
| 72 |
-
Format a product pair for preference_initial / preference_final.
|
| 73 |
-
Matches lsp/src/data.py _pair_overview exactly β no features, ever.
|
| 74 |
-
"""
|
| 75 |
a = pair["product_a"]
|
| 76 |
b = pair["product_b"]
|
| 77 |
return (
|
|
@@ -89,11 +67,10 @@ def pair_overview(pair: dict) -> str:
|
|
| 89 |
def build_seller_system_prompt_preference(
|
| 90 |
pair: dict, cfg: dict, demographics_str: str
|
| 91 |
) -> str:
|
| 92 |
-
|
| 93 |
pv = cfg["prompt_variant"]
|
| 94 |
a, b = pair["product_a"], pair["product_b"]
|
| 95 |
-
|
| 96 |
-
return _pref_seller_prompt(
|
| 97 |
personalization=pv["personalization"],
|
| 98 |
detailed_instruction=pv["detailed_instruction"],
|
| 99 |
title=a.get("title", ""),
|
|
@@ -112,10 +89,9 @@ def build_seller_system_prompt_preference(
|
|
| 112 |
def build_seller_system_prompt_likelihood(
|
| 113 |
product: dict, cfg: dict, demographics_str: str
|
| 114 |
) -> str:
|
| 115 |
-
|
| 116 |
pv = cfg["prompt_variant"]
|
| 117 |
-
|
| 118 |
-
return _like_seller_prompt(
|
| 119 |
personalization=pv["personalization"],
|
| 120 |
detailed_instruction=pv["detailed_instruction"],
|
| 121 |
title=product.get("title", ""),
|
|
@@ -130,23 +106,20 @@ def build_seller_system_prompt_likelihood(
|
|
| 130 |
# ββ Opening / closing survey messages ββββββββββββββββββββββββββββββββββββββββ
|
| 131 |
|
| 132 |
def opening_message_preference(pair: dict) -> str:
|
| 133 |
-
|
| 134 |
return preference_initial(pair_overview(pair))
|
| 135 |
|
| 136 |
|
| 137 |
def opening_message_likelihood(product: dict, category: str) -> str:
|
| 138 |
-
|
| 139 |
-
AI's first synthetic turn: likelihood_initial(product_overview).
|
| 140 |
-
Features included only for likelihood + groceries.
|
| 141 |
-
"""
|
| 142 |
return likelihood_initial(product_overview(product, include_features=(category == "groceries")))
|
| 143 |
|
| 144 |
|
| 145 |
def closing_message_preference(pair: dict) -> str:
|
| 146 |
-
|
| 147 |
return preference_final(pair_overview(pair))
|
| 148 |
|
| 149 |
|
| 150 |
def closing_message_likelihood(product: dict, category: str) -> str:
|
| 151 |
-
|
| 152 |
return likelihood_final(product_overview(product, include_features=(category == "groceries")))
|
|
|
|
| 1 |
"""
|
| 2 |
Wrappers around lsp/src/prompts/*.
|
| 3 |
|
| 4 |
+
Imports from the lsp submodule are intentionally lazy (inside each function)
|
| 5 |
+
so this module can be imported at startup before _init_submodule() has fetched
|
| 6 |
+
the submodule and added lsp/src to sys.path.
|
| 7 |
|
| 8 |
+
By the time any of these functions are actually called (when a participant
|
| 9 |
+
clicks "Start Chat"), _init_submodule() has already run and lsp/src is on
|
| 10 |
+
sys.path, so the imports succeed.
|
|
|
|
|
|
|
|
|
|
| 11 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
# ββ Demographics (must match training code exactly) βββββββββββββββββββββββββββ
|
| 15 |
|
| 16 |
def format_demographics(demo: dict) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
return ", ".join(f"{k}: {v}" for k, v in demo.items())
|
| 18 |
|
| 19 |
|
|
|
|
| 36 |
# ββ Product overview formatters βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 37 |
|
| 38 |
def product_overview(product: dict, include_features: bool) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
lines = [
|
| 40 |
f"Product: {product.get('title', '')}",
|
| 41 |
f"Price: {product.get('price', '')}",
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def pair_overview(pair: dict) -> str:
|
| 52 |
+
"""Matches lsp/src/data.py _pair_overview exactly β no features, ever."""
|
|
|
|
|
|
|
|
|
|
| 53 |
a = pair["product_a"]
|
| 54 |
b = pair["product_b"]
|
| 55 |
return (
|
|
|
|
| 67 |
def build_seller_system_prompt_preference(
|
| 68 |
pair: dict, cfg: dict, demographics_str: str
|
| 69 |
) -> str:
|
| 70 |
+
from prompts.seller_system.preference import get_seller_system_prompt
|
| 71 |
pv = cfg["prompt_variant"]
|
| 72 |
a, b = pair["product_a"], pair["product_b"]
|
| 73 |
+
return get_seller_system_prompt(
|
|
|
|
| 74 |
personalization=pv["personalization"],
|
| 75 |
detailed_instruction=pv["detailed_instruction"],
|
| 76 |
title=a.get("title", ""),
|
|
|
|
| 89 |
def build_seller_system_prompt_likelihood(
|
| 90 |
product: dict, cfg: dict, demographics_str: str
|
| 91 |
) -> str:
|
| 92 |
+
from prompts.seller_system.likelihood import get_seller_system_prompt
|
| 93 |
pv = cfg["prompt_variant"]
|
| 94 |
+
return get_seller_system_prompt(
|
|
|
|
| 95 |
personalization=pv["personalization"],
|
| 96 |
detailed_instruction=pv["detailed_instruction"],
|
| 97 |
title=product.get("title", ""),
|
|
|
|
| 106 |
# ββ Opening / closing survey messages ββββββββββββββββββββββββββββββββββββββββ
|
| 107 |
|
| 108 |
def opening_message_preference(pair: dict) -> str:
|
| 109 |
+
from prompts.survey_prompts import preference_initial
|
| 110 |
return preference_initial(pair_overview(pair))
|
| 111 |
|
| 112 |
|
| 113 |
def opening_message_likelihood(product: dict, category: str) -> str:
|
| 114 |
+
from prompts.survey_prompts import likelihood_initial
|
|
|
|
|
|
|
|
|
|
| 115 |
return likelihood_initial(product_overview(product, include_features=(category == "groceries")))
|
| 116 |
|
| 117 |
|
| 118 |
def closing_message_preference(pair: dict) -> str:
|
| 119 |
+
from prompts.survey_prompts import preference_final
|
| 120 |
return preference_final(pair_overview(pair))
|
| 121 |
|
| 122 |
|
| 123 |
def closing_message_likelihood(product: dict, category: str) -> str:
|
| 124 |
+
from prompts.survey_prompts import likelihood_final
|
| 125 |
return likelihood_final(product_overview(product, include_features=(category == "groceries")))
|