Skip to content

Commit

Permalink
Merge pull request #738 from Mirascope/fix-prompt-template-cleaning
Browse files Browse the repository at this point in the history
fix: prompt template usage of inspect.cleandoc changing certain chara…
  • Loading branch information
willbakst authored Dec 9, 2024
2 parents f4474e5 + fa514d7 commit f60ac2a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mirascope/core/base/_utils/_format_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This module contains the `format_template` function."""

import inspect
from textwrap import dedent
from typing import Any

from ._get_template_values import get_template_values
Expand All @@ -18,7 +18,7 @@ def format_template(template: str, attrs: dict[str, Any]) -> str:
The formatted template.
"""
dedented_template = inspect.cleandoc(template).strip()
dedented_template = dedent(template).strip()
template_vars = get_template_variables(dedented_template, True)

values = get_template_values(template_vars, attrs)
Expand Down
4 changes: 2 additions & 2 deletions mirascope/core/base/_utils/_get_prompt_template.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Utility for pulling the `prompt_template` from a call or `BasePrompt`."""

import inspect
import os
from collections.abc import Callable
from textwrap import dedent

from pydantic import BaseModel

Expand All @@ -25,4 +25,4 @@ def get_prompt_template(fn: Callable | BaseModel) -> str:
"You must explicitly enable docstring prompt templates by setting "
"`MIRASCOPE_DOCSTRING_PROMPT_TEMPLATE=ENABLED` in your environment."
)
return inspect.cleandoc(doc)
return dedent(doc).strip()
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mirascope"
version = "1.12.0"
version = "1.12.1"
description = "LLM abstractions that aren't obstructions"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down Expand Up @@ -83,9 +83,7 @@ realtime = [
"sounddevice>=0.5.1,<1",
"websockets>=13.1,<14",
]
mcp = [
"mcp>=1.0.0",
]
mcp = ["mcp>=1.0.0"]

[tool.uv]
dev-dependencies = [
Expand Down
7 changes: 7 additions & 0 deletions tests/core/base/_utils/test_format_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ def test_format_template_with_list_format_spec() -> None:
formatted_template
== "Recommend books from one of the following genres:\nfantasy\nscifi"
)


def test_format_template_with_internal_tab() -> None:
"""Tests the `format_template` function with internal tab."""
template = "output \text"
formatted_template = format_template(template, {})
assert formatted_template == "output \text"
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f60ac2a

Please sign in to comment.