Prompt operations
Modules concerning the prompt operations of an LM invoker.
PromptOperations(invoker)
Handles prompt operations for an LM invoker.
Examples:
- Configure prompt templates:
lm_invoker.prompt.build(system_template="You are helpful.", user_template="{query}")
- Invoke with the configured prompt builder:
result = await lm_invoker.prompt.invoke(query="Hello")
- Clear configured prompt builder:
lm_invoker.prompt.clear()
Initializes the prompt operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoker
|
BaseLMInvoker
|
The LM invoker to use for prompt operations. |
required |
build(prompt_builder=None, *, system_template='', user_template='', prompt_builder_kwargs=None)
Builds and stores a prompt builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_builder
|
PromptBuilder | None
|
A predefined prompt builder. Defaults to None. |
None
|
system_template
|
str
|
The system prompt template. Defaults to an empty string. |
''
|
user_template
|
str
|
The user prompt template. Defaults to an empty string. |
''
|
prompt_builder_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments for PromptBuilder. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseLMInvoker |
BaseLMInvoker
|
The LM invoker for fluent chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
clear()
Clears the configured prompt builder.
Returns:
| Name | Type | Description |
|---|---|---|
BaseLMInvoker |
BaseLMInvoker
|
The LM invoker for fluent chaining. |
invoke(history=None, extra_contents=None, hyperparameters=None, event_emitter=None, **prompt_kwargs)
async
Invokes the language model using a configured prompt builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
history
|
list[Message] | None
|
Conversation history to include in the prompt. Defaults to None. |
None
|
extra_contents
|
list[MessageContent] | None
|
Extra user contents for prompt formatting. Defaults to None. |
None
|
hyperparameters
|
dict[str, Any] | None
|
Hyperparameters passed to the language model invocation. Defaults to None. |
None
|
event_emitter
|
EventEmitter | None
|
Event emitter for streaming outputs. Defaults to None. |
None
|
**prompt_kwargs
|
Any
|
Prompt variables passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
LMOutput |
LMOutput
|
The language model output from a single invocation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no prompt builder is configured. |