Skip to content
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

core: update load chat prompt template multi mesages #27584

Closed
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
14 changes: 10 additions & 4 deletions libs/core/langchain_core/prompts/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,21 @@ def _load_prompt_from_file(
def _load_chat_prompt(config: dict) -> ChatPromptTemplate:
"""Load chat prompt from config"""

messages = config.pop("messages")
template = messages[0]["prompt"].pop("template") if messages else None
config.pop("input_variables")
template = config.pop("template")

if not template:
msg = "Can't load chat prompt without template"
raise ValueError(msg)

return ChatPromptTemplate.from_template(template=template, **config)
messages = []
if isinstance(template, str):
messages.append(("human", template))

elif isinstance(template, list):
for item in template:
messages.append((item["role"], item["content"]))

return ChatPromptTemplate(messages=messages, **config)


type_to_loader_dict: dict[str, Callable[[dict], BasePromptTemplate]] = {
Expand Down
Loading