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

Prompt is not dedented when used in prompt_template #780

Closed
off6atomic opened this issue Jan 24, 2025 · 1 comment
Closed

Prompt is not dedented when used in prompt_template #780

off6atomic opened this issue Jan 24, 2025 · 1 comment
Labels
bug Something isn't working mirascope

Comments

@off6atomic
Copy link
Contributor

Description

Run this code:

from dotenv import load_dotenv
from mirascope.core import openai, prompt_template

load_dotenv()


@prompt_template(
    """
    SYSTEM:
    You are a librarian
    with knowledge of all books
    and very charming.

    USER:
    Recommend a {genre} book
    with your charm
    """
)
def recommend_book_prompt(genre: str): ...


recommend_book = openai.call("gpt-4o-mini")(recommend_book_prompt)

prompt = recommend_book_prompt("fantasy")
print("Prompt:", prompt)

response = recommend_book("fantasy")
print("Messages:", response.messages)
print("Content:", response.content)

Get the following output:

Prompt: [BaseMessageParam(role='system', content='You are a librarian\n    with knowledge of all books\n    and very charming.'), BaseMessageParam(role='user', content='Recommend a fantasy book\n    with your charm')]
Messages: [{'role': 'system', 'content': 'You are a librarian\n    with knowledge of all books\n    and very charming.'}, {'role': 'user', 'content': 'Recommend a fantasy book\n    with your charm'}]
Content: Ah, dear reader, allow me to whisk you away to a realm of magic and wonder! I wholeheartedly recommend **"The Night Circus" by Erin Morgenstern**. 

This enchanting tale unfolds within the mysterious confines of a traveling circus that arrives without warning and is open only at night. Yet, this is no ordinary circus; it is the battleground for two young illusionists, Celia and Marco, bound in a fierce competition by their mentors, but their hearts are drawn to one another amidst the spectacle.

The prose is lyrical, the imagery vivid, and each twist of the plot is like a delightful surprise waiting to be discovered. You'll find yourself captivated by the enchanting ambiance and the richly drawn characters that will linger in your thoughts long after you close the book.

So gather your favorite blanket, brew a cup of something warm, and prepare to be transported to a world where the impossible becomes possible. Happy reading! 🌌✨

Notice that the are many leading whitespaces in both the prompt and response.messages

Python, Mirascope & OS Versions, related packages (not required)

mirascope==1.15.1
@off6atomic off6atomic added the bug Something isn't working label Jan 24, 2025
@willbakst
Copy link
Contributor

Duplicate of #779

@willbakst willbakst marked this as a duplicate of #779 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mirascope
Projects
None yet
Development

No branches or pull requests

2 participants