models
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| BasePrompt llmling.prompts.models Base class for all prompts. |
||
| DynamicPrompt llmling.prompts.models Dynamic prompt loaded from callable. |
||
| FilePrompt llmling.prompts.models Prompt loaded from a file. |
||
| PromptMessage llmling.prompts.models A message in a prompt template. |
||
| PromptParameter llmling.prompts.models Prompt argument with validation information. |
||
| StaticPrompt llmling.prompts.models Static prompt defined by message list. |
🛈 DocStrings¶
Prompt models for LLMling.
BasePrompt
¶
Bases: BaseModel
Base class for all prompts.
Source code in src/llmling/prompts/models.py
arguments
class-attribute
instance-attribute
¶
arguments: list[PromptParameter] = Field(default_factory=list)
List of arguments that this prompt accepts.
description
instance-attribute
¶
Human-readable description of what this prompt does.
metadata
class-attribute
instance-attribute
¶
Additional metadata for storing custom prompt information.
name
class-attribute
instance-attribute
¶
Technical identifier (automatically set from config key during registration).
format
async
¶
format(arguments: dict[str, Any] | None = None) -> list[PromptMessage]
Format this prompt with given arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
dict[str, Any] | None
|
Optional argument values |
None
|
Returns:
| Type | Description |
|---|---|
list[PromptMessage]
|
List of formatted messages |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required arguments are missing |
Source code in src/llmling/prompts/models.py
get_messages
¶
get_messages() -> list[PromptMessage]
Get the messages for this prompt.
Source code in src/llmling/prompts/models.py
to_mcp_prompt
¶
Convert to MCP Prompt.
Source code in src/llmling/prompts/models.py
validate_arguments
¶
Validate that required arguments are provided.
Source code in src/llmling/prompts/models.py
DynamicPrompt
¶
Bases: BasePrompt
Dynamic prompt loaded from callable.
Source code in src/llmling/prompts/models.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
completions
class-attribute
instance-attribute
¶
Optional mapping of argument names to completion functions.
import_path
instance-attribute
¶
Dotted import path to the callable that generates the prompt.
messages
property
¶
messages: list[PromptMessage]
Get the template messages for this prompt.
Note: These are template messages - actual content will be populated during format() when the callable is executed.
template
class-attribute
instance-attribute
¶
Optional template string for formatting the callable's output.
type
class-attribute
instance-attribute
¶
Discriminator field identifying this as a function-based prompt.
format
async
¶
format(arguments: dict[str, Any] | None = None) -> list[PromptMessage]
Format this prompt with given arguments.
Source code in src/llmling/prompts/models.py
from_callable
classmethod
¶
from_callable(
fn: Callable[..., Any] | str,
*,
name_override: str | None = None,
description_override: str | None = None,
template_override: str | None = None,
completions: Mapping[str, CompletionFunction] | None = None
) -> DynamicPrompt
Create a prompt from a callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any] | str
|
Function or import path to create prompt from |
required |
name_override
|
str | None
|
Optional override for prompt name |
None
|
description_override
|
str | None
|
Optional override for prompt description |
None
|
template_override
|
str | None
|
Optional override for message template |
None
|
completions
|
Mapping[str, CompletionFunction] | None
|
Optional dict mapping argument names to completion functions |
None
|
Returns:
| Type | Description |
|---|---|
DynamicPrompt
|
DynamicPrompt instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If callable cannot be imported or is invalid |
Source code in src/llmling/prompts/models.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
get_completion_functions
¶
get_completion_functions() -> dict[str, CompletionFunction]
Resolve completion function import paths and return a completion fn dict.
Source code in src/llmling/prompts/models.py
FilePrompt
¶
Bases: BasePrompt
Prompt loaded from a file.
This type of prompt loads its content from a file, allowing for longer or more complex prompts to be managed in separate files. The file content is loaded and parsed according to the specified format.
Source code in src/llmling/prompts/models.py
fmt
class-attribute
instance-attribute
¶
Format of the file content (text, markdown, or jinja2 template).
path
instance-attribute
¶
Path to the file containing the prompt content.
type
class-attribute
instance-attribute
¶
Discriminator field identifying this as a file-based prompt.
watch
class-attribute
instance-attribute
¶
Whether to watch the file for changes and reload automatically.
format
async
¶
format(arguments: dict[str, Any] | None = None) -> list[PromptMessage]
Format the file content with arguments.
Source code in src/llmling/prompts/models.py
PromptMessage
¶
Bases: BaseModel
A message in a prompt template.
Source code in src/llmling/prompts/models.py
get_text_content
¶
Get text content of message.
Source code in src/llmling/prompts/models.py
PromptParameter
¶
Bases: BaseModel
Prompt argument with validation information.
Source code in src/llmling/prompts/models.py
completion_function
class-attribute
instance-attribute
¶
Optional function to provide argument completions.
default
class-attribute
instance-attribute
¶
Default value if argument is optional.
description
class-attribute
instance-attribute
¶
Human-readable description of the argument.
required
class-attribute
instance-attribute
¶
Whether this argument must be provided when formatting the prompt.
type_hint
class-attribute
instance-attribute
¶
Type annotation for the argument, defaults to str.
to_mcp_argument
¶
Convert to MCP PromptArgument.
StaticPrompt
¶
Bases: BasePrompt
Static prompt defined by message list.
Source code in src/llmling/prompts/models.py
messages
instance-attribute
¶
messages: list[PromptMessage]
List of messages that make up this prompt.
type
class-attribute
instance-attribute
¶
Discriminator field identifying this as a static text prompt.
format
async
¶
format(arguments: dict[str, Any] | None = None) -> list[PromptMessage]
Format static prompt messages with arguments.