updated tokens again
Browse files
app/recommendation_pipeline.py
CHANGED
|
@@ -116,6 +116,12 @@ class CatalogIndex:
|
|
| 116 |
for s, r in out
|
| 117 |
]
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
def build_query_text(persona: str, chat_history: list[dict[str, str]]) -> str:
|
| 121 |
parts = [persona.strip()]
|
|
@@ -165,7 +171,7 @@ Output ONLY a JSON array of {top_n} objects: {{"business_id":"<id>","rank":1,"ra
|
|
| 165 |
system_instruction=_RANK_SYSTEM,
|
| 166 |
user_text=user_prompt,
|
| 167 |
temperature=0.2,
|
| 168 |
-
max_output_tokens=
|
| 169 |
)
|
| 170 |
return _normalize_ranked_output(raw, candidates, top_n)
|
| 171 |
|
|
@@ -175,7 +181,7 @@ def _normalize_ranked_output(
|
|
| 175 |
candidates: list[dict[str, Any]],
|
| 176 |
top_n: int,
|
| 177 |
) -> list[dict[str, Any]]:
|
| 178 |
-
raw =
|
| 179 |
data: list[dict[str, Any]] | None = None
|
| 180 |
try:
|
| 181 |
data = json.loads(raw)
|
|
|
|
| 116 |
for s, r in out
|
| 117 |
]
|
| 118 |
|
| 119 |
+
def strip_code_fences(s: str) -> str:
|
| 120 |
+
s = s.strip()
|
| 121 |
+
s = re.sub(r"^```(?:json)?\s*", "", s)
|
| 122 |
+
s = re.sub(r"\s*```$", "", s)
|
| 123 |
+
return s.strip()
|
| 124 |
+
|
| 125 |
|
| 126 |
def build_query_text(persona: str, chat_history: list[dict[str, str]]) -> str:
|
| 127 |
parts = [persona.strip()]
|
|
|
|
| 171 |
system_instruction=_RANK_SYSTEM,
|
| 172 |
user_text=user_prompt,
|
| 173 |
temperature=0.2,
|
| 174 |
+
max_output_tokens=1536,
|
| 175 |
)
|
| 176 |
return _normalize_ranked_output(raw, candidates, top_n)
|
| 177 |
|
|
|
|
| 181 |
candidates: list[dict[str, Any]],
|
| 182 |
top_n: int,
|
| 183 |
) -> list[dict[str, Any]]:
|
| 184 |
+
raw = strip_code_fences(raw)
|
| 185 |
data: list[dict[str, Any]] | None = None
|
| 186 |
try:
|
| 187 |
data = json.loads(raw)
|