Skip to content

Commit 4845864

Browse files
committed
lint it
1 parent 41c6252 commit 4845864

3 files changed

Lines changed: 14 additions & 25 deletions

File tree

langfuse/model.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,6 @@ def __init__(self, prompt: Prompt_Chat, is_fallback: bool = False):
321321
content=p.content,
322322
),
323323
)
324-
# Handle plain dictionaries (fallback case)
325-
elif isinstance(p, dict):
326-
if p.get("type") == "placeholder" and "name" in p:
327-
self.prompt.append(
328-
ChatMessageWithPlaceholdersDict_Placeholder(
329-
type="placeholder",
330-
name=p["name"],
331-
),
332-
)
333-
elif "role" in p and "content" in p:
334-
self.prompt.append(
335-
ChatMessageWithPlaceholdersDict_Message(
336-
type="message",
337-
role=p["role"],
338-
content=p["content"],
339-
),
340-
)
341324

342325
def compile(
343326
self, **kwargs

tests/test_prompt.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,30 @@ def test_get_prompt_with_placeholders():
276276
"Help me with coding",
277277
], # None = placeholder
278278
),
279-
# 5. Placeholder with non-list value (should log warning and create invalid dict)
279+
# 5. Placeholder with non-list value (should log warning and append as string)
280280
(
281281
{"role": "helpful", "task": "coding"},
282282
{"examples": "not a list"},
283283
3,
284284
[
285285
"You are a helpful assistant",
286-
"{'not a list'}", # Invalid dict becomes string when checked
286+
"not a list", # String value appended directly
287287
"Help me with coding",
288288
],
289289
),
290290
# 6. Placeholder with invalid message structure (should log warning and include both)
291291
(
292292
{"role": "helpful", "task": "coding"},
293-
{"examples": ["invalid message", {"role": "user", "content": "valid message"}]},
293+
{
294+
"examples": [
295+
"invalid message",
296+
{"role": "user", "content": "valid message"},
297+
]
298+
},
294299
4,
295300
[
296301
"You are a helpful assistant",
297-
"{\"['invalid message', {'role': 'user', 'content': 'valid message'}]\"}", # Invalid structure becomes string
302+
"['invalid message', {'role': 'user', 'content': 'valid message'}]", # Invalid structure becomes string
298303
"valid message", # Valid message processed normally
299304
"Help me with coding",
300305
],
@@ -330,9 +335,9 @@ def test_compile_with_placeholders(
330335
if expected_content is None:
331336
# This should be an unresolved placeholder
332337
assert "type" in result[i] and result[i]["type"] == "placeholder"
333-
elif expected_content.startswith("{") and expected_content.endswith("}"):
334-
# This is an invalid dictionary that becomes a string representation
335-
assert str(result[i]) == expected_content
338+
elif isinstance(result[i], str):
339+
# This is a string value from invalid placeholder
340+
assert result[i] == expected_content
336341
else:
337342
# This should be a regular message
338343
assert "content" in result[i]

tests/test_prompt_compilation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ def test_get_langchain_prompt_with_unresolved_placeholders(self):
827827

828828
# Call get_langchain_prompt without resolving placeholder
829829
langchain_messages = prompt_client.get_langchain_prompt(
830-
role="helpful", task="coding",
830+
role="helpful",
831+
task="coding",
831832
)
832833

833834
# Should have 3 items: system message, MessagesPlaceholder, user message

0 commit comments

Comments
 (0)