A conversation: its messages, in order.
Attributes#
| Attribute | Type | Description |
|---|---|---|
content | tuple[Message, ...] |
Functions#
__init__#
__init__(content) -> None| Parameter | Type | Description |
|---|---|---|
content | tuple[Message, ...] |
pipe#
pipe[B](f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)concat#
concat(input) -> PromptThis prompt's messages, then input's.
| Parameter | Type | Description |
|---|---|---|
input | RawInput |
Returns Prompt
def concat(self, input: RawInput) -> Prompt:
"""This prompt's messages, then ``input``'s."""
other = make(input)
if not self.content:
return other
if not other.content:
return self
return Prompt((*self.content, *other.content))set_system#
set_system(content) -> PromptA system message content first, replacing every other one.
| Parameter | Type | Description |
|---|---|---|
content | str |
Returns Prompt
def set_system(self, content: str) -> Prompt:
"""A system message ``content`` first, replacing every other one."""
return Prompt(
(
SystemMessage(content=content),
*(m for m in self.content if not isinstance(m, SystemMessage)),
)
)prepend_system#
prepend_system(content) -> PromptA leading system message: content before the first system
message's text (Effect keeps that message too).
| Parameter | Type | Description |
|---|---|---|
content | str |
Returns Prompt
def prepend_system(self, content: str) -> Prompt:
"""A leading system message: ``content`` before the first system
message's text (Effect keeps that message too)."""
first = next((m for m in self.content if isinstance(m, SystemMessage)), None)
system = SystemMessage(content=content if first is None else content + first.content)
return Prompt((system, *self.content))append_system#
append_system(content) -> PromptA leading system message: the first system message's text, then
content (Effect keeps that message too).
| Parameter | Type | Description |
|---|---|---|
content | str |
Returns Prompt
def append_system(self, content: str) -> Prompt:
"""A leading system message: the first system message's text, then
``content`` (Effect keeps that message too)."""
first = next((m for m in self.content if isinstance(m, SystemMessage)), None)
system = SystemMessage(content=content if first is None else first.content + content)
return Prompt((system, *self.content))