-
Notifications
You must be signed in to change notification settings - Fork 227
feat(prompts): chat message placeholders #1222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile
| ) -> None: | ||
| """Backward-compatible setter for raw prompt structure.""" | ||
| for p in prompt: | ||
| if hasattr(p, "type") and hasattr(p, "name") and p.type == "placeholder": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using hasattr(p, ...) in the prompt setter may fail for plain dict inputs which lack attribute access. Consider checking if p is a dict (e.g. using 'if isinstance(p, dict) and "type" in p') to support both dicts and objects.
Important
Adds support for chat message placeholders in langfuse-python SDK, enabling dynamic templating in prompts with comprehensive test coverage.
ChatMessageWithPlaceholderstype inchat_message_with_placeholders.pyto handle both regular and placeholder messages.create_prompt_request.pyandchat_prompt.pyto useChatMessageWithPlaceholdersfor prompt creation.PlaceholderMessagemodel inplaceholder_message.pyfor template variables.ChatPromptClientinmodel.pyto compile prompts with placeholders, handling unresolved placeholders by logging warnings.get_langchain_prompt()to convert unresolved placeholders toMessagesPlaceholderobjects.test_prompt.pyandtest_prompt_compilation.pyto cover placeholder scenarios, including edge cases and integration with Langchain.This description was created by
for 1c093d2. You can customize this summary. It will automatically update as commits are pushed.
Greptile Summary
Disclaimer: Experimental PR review
Implements chat message placeholder functionality in the langfuse-python SDK, enabling dynamic templating in chat prompts. This feature is critical for scenarios like injecting conversation history or examples into prompts.
ChatMessageWithPlaceholdersunion type inlangfuse/api/resources/prompts/types/chat_message_with_placeholders.pysupporting both regular chat messages and placeholder messagesChatMessageWithPlaceholdersinstead ofChatMessageinlangfuse/api/resources/prompts/types/create_prompt_request.pyPlaceholderMessagePydantic model inlangfuse/api/resources/prompts/types/placeholder_message.pyfor template variablestests/test_prompt.pyfor placeholder scenarios and edge cases