Skip to content

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

Merged
merged 33 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
457f985
init commit placeholder messages
nimarb Jun 24, 2025
ffb8ea6
Merge branch 'main' into nimar/lfe-5387-message-placeholder-python
nimarb Jun 25, 2025
0288197
make the types beautiful again
nimarb Jun 25, 2025
e130dbf
fix type
nimarb Jun 25, 2025
d349c38
update types
nimarb Jun 25, 2025
d7fb969
placeholer compile
nimarb Jun 25, 2025
3487207
fix model
nimarb Jun 25, 2025
401bf64
fix types
nimarb Jun 25, 2025
2759684
update api
nimarb Jun 25, 2025
31f3dc9
fix tests
nimarb Jun 25, 2025
6ddee62
tests
nimarb Jun 25, 2025
0c7ec1d
prvoide equality
nimarb Jun 25, 2025
98faa14
Merge branch 'main' into nimar/lfe-5387-message-placeholder-python
nimarb Jun 26, 2025
ce93eda
Merge branch 'main' into nimar/lfe-5387-message-placeholder-python
nimarb Jun 26, 2025
39c0ae7
code review
nimarb Jun 26, 2025
fc7a363
feedback
nimarb Jun 27, 2025
9199be5
fix for LC
nimarb Jun 27, 2025
e295821
migrate to getter setter
nimarb Jun 27, 2025
958914b
fix docstring
nimarb Jun 30, 2025
210021d
remove superfluous set
nimarb Jun 30, 2025
5d03dba
update uopdate
nimarb Jun 30, 2025
e5c8272
update update again
nimarb Jun 30, 2025
c0e261c
fix test
nimarb Jun 30, 2025
cbf2265
fix test
nimarb Jun 30, 2025
c35d1b3
use compile for all instead of update
nimarb Jun 30, 2025
41c6252
messagesplaceholder object returned
nimarb Jul 1, 2025
4845864
lint it
nimarb Jul 1, 2025
2b52fdc
Merge branch 'main' into nimar/lfe-5387-message-placeholder-python
nimarb Jul 1, 2025
1bc57c9
fix lint
nimarb Jul 1, 2025
acd9c6f
remove unsused
nimarb Jul 1, 2025
8d53cd9
fix test
nimarb Jul 1, 2025
1c093d2
fix test
nimarb Jul 1, 2025
5f662e8
Merge branch 'main' into nimar/lfe-5387-message-placeholder-python
nimarb Jul 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions langfuse/_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from langfuse.media import LangfuseMedia
from langfuse.model import (
ChatMessageDict,
ChatMessageWithPlaceholdersDict,
ChatPromptClient,
CreateDatasetItemRequest,
CreateDatasetRequest,
Expand Down Expand Up @@ -2133,7 +2134,7 @@ def create_prompt(
self,
*,
name: str,
prompt: List[ChatMessageDict],
prompt: List[Union[ChatMessageDict, ChatMessageWithPlaceholdersDict]],
labels: List[str] = [],
tags: Optional[List[str]] = None,
type: Optional[Literal["chat"]],
Expand All @@ -2158,7 +2159,9 @@ def create_prompt(
self,
*,
name: str,
prompt: Union[str, List[ChatMessageDict]],
prompt: Union[
str, List[Union[ChatMessageDict, ChatMessageWithPlaceholdersDict]]
],
labels: List[str] = [],
tags: Optional[List[str]] = None,
type: Optional[Literal["chat", "text"]] = "text",
Expand Down
8 changes: 8 additions & 0 deletions langfuse/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
CategoricalScore,
CategoricalScoreV1,
ChatMessage,
ChatMessageWithPlaceholders,
ChatMessageWithPlaceholders_Chatmessage,
ChatMessageWithPlaceholders_Placeholder,
ChatPrompt,
Comment,
CommentObjectType,
Expand Down Expand Up @@ -126,6 +129,7 @@
PaginatedModels,
PaginatedSessions,
PatchMediaBody,
PlaceholderMessage,
Project,
ProjectDeletionResponse,
Projects,
Expand Down Expand Up @@ -230,6 +234,9 @@
"CategoricalScore",
"CategoricalScoreV1",
"ChatMessage",
"ChatMessageWithPlaceholders",
"ChatMessageWithPlaceholders_Chatmessage",
"ChatMessageWithPlaceholders_Placeholder",
"ChatPrompt",
"Comment",
"CommentObjectType",
Expand Down Expand Up @@ -335,6 +342,7 @@
"PaginatedModels",
"PaginatedSessions",
"PatchMediaBody",
"PlaceholderMessage",
"Project",
"ProjectDeletionResponse",
"Projects",
Expand Down
9 changes: 6 additions & 3 deletions langfuse/api/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4290,7 +4290,10 @@ Create a new version for the prompt with the given `name`
<dd>

```python
from langfuse import ChatMessage, CreatePromptRequest_Chat
from langfuse import (
ChatMessageWithPlaceholders_Chatmessage,
CreatePromptRequest_Chat,
)
from langfuse.client import FernLangfuse

client = FernLangfuse(
Expand All @@ -4305,11 +4308,11 @@ client.prompts.create(
request=CreatePromptRequest_Chat(
name="name",
prompt=[
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
Expand Down
8 changes: 8 additions & 0 deletions langfuse/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,16 @@
from .prompts import (
BasePrompt,
ChatMessage,
ChatMessageWithPlaceholders,
ChatMessageWithPlaceholders_Chatmessage,
ChatMessageWithPlaceholders_Placeholder,
ChatPrompt,
CreateChatPromptRequest,
CreatePromptRequest,
CreatePromptRequest_Chat,
CreatePromptRequest_Text,
CreateTextPromptRequest,
PlaceholderMessage,
Prompt,
PromptMeta,
PromptMetaListResponse,
Expand Down Expand Up @@ -242,6 +246,9 @@
"CategoricalScore",
"CategoricalScoreV1",
"ChatMessage",
"ChatMessageWithPlaceholders",
"ChatMessageWithPlaceholders_Chatmessage",
"ChatMessageWithPlaceholders_Placeholder",
"ChatPrompt",
"Comment",
"CommentObjectType",
Expand Down Expand Up @@ -347,6 +354,7 @@
"PaginatedModels",
"PaginatedSessions",
"PatchMediaBody",
"PlaceholderMessage",
"Project",
"ProjectDeletionResponse",
"Projects",
Expand Down
8 changes: 8 additions & 0 deletions langfuse/api/resources/prompts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
from .types import (
BasePrompt,
ChatMessage,
ChatMessageWithPlaceholders,
ChatMessageWithPlaceholders_Chatmessage,
ChatMessageWithPlaceholders_Placeholder,
ChatPrompt,
CreateChatPromptRequest,
CreatePromptRequest,
CreatePromptRequest_Chat,
CreatePromptRequest_Text,
CreateTextPromptRequest,
PlaceholderMessage,
Prompt,
PromptMeta,
PromptMetaListResponse,
Expand All @@ -20,12 +24,16 @@
__all__ = [
"BasePrompt",
"ChatMessage",
"ChatMessageWithPlaceholders",
"ChatMessageWithPlaceholders_Chatmessage",
"ChatMessageWithPlaceholders_Placeholder",
"ChatPrompt",
"CreateChatPromptRequest",
"CreatePromptRequest",
"CreatePromptRequest_Chat",
"CreatePromptRequest_Text",
"CreateTextPromptRequest",
"PlaceholderMessage",
"Prompt",
"PromptMeta",
"PromptMetaListResponse",
Expand Down
18 changes: 12 additions & 6 deletions langfuse/api/resources/prompts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def create(

Examples
--------
from langfuse import ChatMessage, CreatePromptRequest_Chat
from langfuse import (
ChatMessageWithPlaceholders_Chatmessage,
CreatePromptRequest_Chat,
)
from langfuse.client import FernLangfuse

client = FernLangfuse(
Expand All @@ -243,11 +246,11 @@ def create(
request=CreatePromptRequest_Chat(
name="name",
prompt=[
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
Expand Down Expand Up @@ -512,7 +515,10 @@ async def create(
--------
import asyncio

from langfuse import ChatMessage, CreatePromptRequest_Chat
from langfuse import (
ChatMessageWithPlaceholders_Chatmessage,
CreatePromptRequest_Chat,
)
from langfuse.client import AsyncFernLangfuse

client = AsyncFernLangfuse(
Expand All @@ -530,11 +536,11 @@ async def main() -> None:
request=CreatePromptRequest_Chat(
name="name",
prompt=[
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
ChatMessage(
ChatMessageWithPlaceholders_Chatmessage(
role="role",
content="content",
),
Expand Down
10 changes: 10 additions & 0 deletions langfuse/api/resources/prompts/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from .base_prompt import BasePrompt
from .chat_message import ChatMessage
from .chat_message_with_placeholders import (
ChatMessageWithPlaceholders,
ChatMessageWithPlaceholders_Chatmessage,
ChatMessageWithPlaceholders_Placeholder,
)
from .chat_prompt import ChatPrompt
from .create_chat_prompt_request import CreateChatPromptRequest
from .create_prompt_request import (
Expand All @@ -10,6 +15,7 @@
CreatePromptRequest_Text,
)
from .create_text_prompt_request import CreateTextPromptRequest
from .placeholder_message import PlaceholderMessage
from .prompt import Prompt, Prompt_Chat, Prompt_Text
from .prompt_meta import PromptMeta
from .prompt_meta_list_response import PromptMetaListResponse
Expand All @@ -18,12 +24,16 @@
__all__ = [
"BasePrompt",
"ChatMessage",
"ChatMessageWithPlaceholders",
"ChatMessageWithPlaceholders_Chatmessage",
"ChatMessageWithPlaceholders_Placeholder",
"ChatPrompt",
"CreateChatPromptRequest",
"CreatePromptRequest",
"CreatePromptRequest_Chat",
"CreatePromptRequest_Text",
"CreateTextPromptRequest",
"PlaceholderMessage",
"Prompt",
"PromptMeta",
"PromptMetaListResponse",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1


class ChatMessageWithPlaceholders_Chatmessage(pydantic_v1.BaseModel):
role: str
content: str
type: typing.Literal["chatmessage"] = "chatmessage"

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().json(**kwargs_with_defaults)

def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
kwargs_with_defaults_exclude_unset: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
kwargs_with_defaults_exclude_none: typing.Any = {
"by_alias": True,
"exclude_none": True,
**kwargs,
}

return deep_union_pydantic_dicts(
super().dict(**kwargs_with_defaults_exclude_unset),
super().dict(**kwargs_with_defaults_exclude_none),
)

class Config:
frozen = True
smart_union = True
extra = pydantic_v1.Extra.allow
json_encoders = {dt.datetime: serialize_datetime}


class ChatMessageWithPlaceholders_Placeholder(pydantic_v1.BaseModel):
name: str
type: typing.Literal["placeholder"] = "placeholder"

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().json(**kwargs_with_defaults)

def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
kwargs_with_defaults_exclude_unset: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
kwargs_with_defaults_exclude_none: typing.Any = {
"by_alias": True,
"exclude_none": True,
**kwargs,
}

return deep_union_pydantic_dicts(
super().dict(**kwargs_with_defaults_exclude_unset),
super().dict(**kwargs_with_defaults_exclude_none),
)

class Config:
frozen = True
smart_union = True
extra = pydantic_v1.Extra.allow
json_encoders = {dt.datetime: serialize_datetime}


ChatMessageWithPlaceholders = typing.Union[
ChatMessageWithPlaceholders_Chatmessage, ChatMessageWithPlaceholders_Placeholder
]
4 changes: 2 additions & 2 deletions langfuse/api/resources/prompts/types/chat_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .base_prompt import BasePrompt
from .chat_message import ChatMessage
from .chat_message_with_placeholders import ChatMessageWithPlaceholders


class ChatPrompt(BasePrompt):
prompt: typing.List[ChatMessage]
prompt: typing.List[ChatMessageWithPlaceholders]

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .chat_message import ChatMessage
from .chat_message_with_placeholders import ChatMessageWithPlaceholders


class CreateChatPromptRequest(pydantic_v1.BaseModel):
name: str
prompt: typing.List[ChatMessage]
prompt: typing.List[ChatMessageWithPlaceholders]
config: typing.Optional[typing.Any] = None
labels: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None)
"""
Expand Down
4 changes: 2 additions & 2 deletions langfuse/api/resources/prompts/types/create_prompt_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .chat_message import ChatMessage
from .chat_message_with_placeholders import ChatMessageWithPlaceholders


class CreatePromptRequest_Chat(pydantic_v1.BaseModel):
name: str
prompt: typing.List[ChatMessage]
prompt: typing.List[ChatMessageWithPlaceholders]
config: typing.Optional[typing.Any] = None
labels: typing.Optional[typing.List[str]] = None
tags: typing.Optional[typing.List[str]] = None
Expand Down
Loading
Loading