mirascope api¶
mirascope package.
BaseCallParams
¶
Bases: BaseModel
, Generic[BaseToolT]
The parameters with which to make a call.
Source code in mirascope/base/types.py
kwargs(tool_type=None, exclude=None)
¶
Returns all parameters for the call as a keyword arguments dictionary.
Source code in mirascope/base/types.py
BasePrompt
¶
Bases: BaseModel
The base class for working with prompts.
This class is implemented as the base for all prompting needs across various model providers.
Example:
from mirascope import BasePrompt
class BookRecommendationPrompt(BasePrompt):
"""A prompt for recommending a book."""
prompt_template = """
SYSTEM: You are the world's greatest librarian.
USER: Please recommend a {genre} book.
"""
genre: str
prompt = BookRecommendationPrompt(genre="fantasy")
print(prompt.messages())
#> [{"role": "user", "content": "Please recommend a fantasy book."}]
print(prompt)
#> Please recommend a fantasy book.
Source code in mirascope/base/prompts.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
__str__()
¶
dump()
¶
Dumps the contents of the prompt into a dictionary.
messages()
¶
Returns the template as a formatted list of messages.
Source code in mirascope/base/prompts.py
tags(args)
¶
A decorator for adding tags to a BasePrompt
.
Adding this decorator to a BasePrompt
updates the _tags
class attribute to the
given value. This is useful for adding metadata to a BasePrompt
that can be used
for logging or filtering.
Example:
from mirascope import BasePrompt, tags
@tags(["book_recommendation", "entertainment"])
class BookRecommendationPrompt(BasePrompt):
prompt_template = """
SYSTEM:
You are the world's greatest librarian.
USER:
I've recently read this book: {book_title}.
What should I read next?
"""
book_title: [str]
print(BookRecommendationPrompt.dump()["tags"])
#> ['book_recommendation', 'entertainment']
Returns:
Type | Description |
---|---|
Callable[[Type[BasePromptT]], Type[BasePromptT]]
|
The decorated class with |