PotatoHead
Agent
¶
Source code in python/opsml/potato_head/_potato_head.pyi
id
property
¶
The ID of the agent. This is a random uuid7 that is generated when the agent is created.
__init__(provider)
¶
Create an Agent object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
Provider | str
|
The provider to use for the agent. This can be a Provider enum or a string representing the provider. |
required |
Source code in python/opsml/potato_head/_potato_head.pyi
execute_task(task, context_messages)
¶
Execute a task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Task
|
The task to execute. |
required |
context_messages
|
Dict[str, List[Message]]
|
The context messages to use for the task. This is a dictionary where the keys are the task IDs and the values are lists of messages that will be used as context for the task. |
required |
Returns:
Name | Type | Description |
---|---|---|
AgentResponse |
AgentResponse
|
The response from the agent after executing the task. |
Source code in python/opsml/potato_head/_potato_head.pyi
AgentResponse
¶
Source code in python/opsml/potato_head/_potato_head.pyi
AudioUrl
¶
Source code in python/opsml/potato_head/_potato_head.pyi
format
property
¶
The format of the audio URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the audio URL.
url
property
¶
The URL of the audio.
__init__(url, kind='audio-url')
¶
Create an AudioUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the audio. |
required |
kind
|
Literal['audio-url']
|
The kind of the content. |
'audio-url'
|
Source code in python/opsml/potato_head/_potato_head.pyi
BinaryContent
¶
Source code in python/opsml/potato_head/_potato_head.pyi
data
property
¶
The binary data.
format
property
¶
The format of the binary content.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the binary content.
__init__(data, media_type, kind='binary')
¶
Create a BinaryContent object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
bytes
|
The binary data. |
required |
media_type
|
str
|
The media type of the binary data. |
required |
kind
|
str
|
The kind of the content |
'binary'
|
Source code in python/opsml/potato_head/_potato_head.pyi
DocumentUrl
¶
Source code in python/opsml/potato_head/_potato_head.pyi
format
property
¶
The format of the document URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the document URL.
url
property
¶
The URL of the document.
__init__(url, kind='document-url')
¶
Create a DocumentUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the document. |
required |
kind
|
Literal['document-url']
|
The kind of the content. |
'document-url'
|
Source code in python/opsml/potato_head/_potato_head.pyi
ImageUrl
¶
Source code in python/opsml/potato_head/_potato_head.pyi
format
property
¶
The format of the image URL.
kind
property
¶
The kind of the content.
media_type
property
¶
The media type of the image URL.
url
property
¶
The URL of the image.
__init__(url, kind='image-url')
¶
Create an ImageUrl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the image. |
required |
kind
|
Literal['image-url']
|
The kind of the content. |
'image-url'
|
Source code in python/opsml/potato_head/_potato_head.pyi
Message
¶
Source code in python/opsml/potato_head/_potato_head.pyi
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 392 393 394 395 396 |
|
content
property
¶
The content of the message
sanitized_output
property
¶
The sanitized content of the message
__init__(content)
¶
Create a Message object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
str | ImageUrl | AudioUrl | BinaryContent | DocumentUrl
|
The content of the message. |
required |
Source code in python/opsml/potato_head/_potato_head.pyi
bind(context)
¶
Bind a context in the prompt. This is an immutable operation meaning that it will return a new Message object with the context bound.
Example with Prompt that contains two messages
```python
prompt = Prompt(
model="openai:gpt-4o",
user_message=[
"My prompt $1 is $2",
"My prompt $3 is $4",
],
system_message="system_prompt",
)
bounded_prompt = prompt.user_message[0].bind("world").unwrap() # we bind "world" to the first message
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
str
|
The context to bind. |
required |
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The message with the context bound. |
Source code in python/opsml/potato_head/_potato_head.pyi
model_dump()
¶
Unwrap the message content and serialize it to a dictionary.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The message dictionary with keys "content" and "role". |
sanitize(sanitizer)
¶
Sanitize the message content.
Example with Prompt that contains two messages
```python
prompt = Prompt(
model="openai:gpt-4o",
user_message=[
"My prompt $1 is $2",
"My prompt $3 is $4",
],
system_message="system_prompt",
)
# sanitize the first message
# Note: sanitization will fail if no sanitizer is provided (either through prompt.sanitizer or standalone)
# we bind "world" to the first message
bounded_prompt = prompt.user_message[0].bind("world").sanitize(prompt.sanitizer).unwrap()
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sanitizer
|
PromptSanitizer
|
The sanitizer to use for sanitizing the message |
required |
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The sanitized message. |
Source code in python/opsml/potato_head/_potato_head.pyi
ModelSettings
¶
Source code in python/opsml/potato_head/_potato_head.pyi
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
extra_body
property
¶
The extra body to use.
frequency_penalty
property
¶
The frequency penalty to use.
logit_bias
property
¶
The logit bias to use.
max_tokens
property
¶
The maximum number of tokens to generate.
model
property
¶
The model to use.
parallel_tool_calls
property
¶
Whether to allow parallel tool calls.
presence_penalty
property
¶
The presence penalty to use.
provider
property
¶
The provider to use.
seed
property
¶
The seed to use for the model allowing for reproducible results.
stop_sequences
property
¶
The stop sequences to use.
temperature
property
¶
The amount of randomness to use.
timeout
property
¶
The timeout to use.
top_p
property
¶
The top p to use.
__init__(model, provider, max_tokens=None, temperature=None, top_p=None, frequency_penalty=None, presence_penalty=None, timeout=None, parallel_tool_calls=None, seed=None, logit_bias=None, stop_sequences=None, extra_body=None)
¶
ModelSettings for configuring the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The model to use. |
required |
provider
|
str
|
The provider to use. |
required |
max_tokens
|
Optional[int]
|
The maximum number of tokens to generate. |
None
|
temperature
|
Optional[float]
|
The amount of randomness to use. |
None
|
top_p
|
Optional[float]
|
The top p to use. |
None
|
frequency_penalty
|
Optional[float]
|
The frequency penalty to use. Penalizes new tokens based on their frequency in the text. |
None
|
presence_penalty
|
Optional[float]
|
The presence penalty to use. Penalizes new tokens based on whether they already appear in the text. |
None
|
timeout
|
Optional[float]
|
The timeout to use. |
None
|
parallel_tool_calls
|
Optional[bool]
|
Whether to allow parallel tool calls. |
None
|
seed
|
Optional[int]
|
The seed to use for the model allowing for reproducible results. |
None
|
logit_bias
|
Optional[dict[str, int]]
|
The logit bias to use. Modifies the likelihood of specified tokens appearing in the generated text. |
None
|
stop_sequences
|
Optional[List[str]]
|
The stop sequences to use that will cause the model to stop generating text. |
None
|
extra_body
|
Optional[dict[str, Any]]
|
The extra body to use. Must be a dictionary |
None
|
Source code in python/opsml/potato_head/_potato_head.pyi
PIIConfig
¶
Source code in python/opsml/potato_head/_potato_head.pyi
__init__(check_email=True, check_phone=True, check_credit_card=True, check_ssn=True, check_ip=True, check_password=True, check_address=True, check_name=True, check_dob=True, custom_pii_patterns=[])
¶
PIIConfig for configuring the sanitization of a chat prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
check_email
|
bool
|
Whether to check for email addresses in the chat prompt. |
True
|
check_phone
|
bool
|
Whether to check for phone numbers in the chat prompt. |
True
|
check_credit_card
|
bool
|
Whether to check for credit card numbers in the chat prompt. |
True
|
check_ssn
|
bool
|
Whether to check for social security numbers in the chat prompt. |
True
|
check_ip
|
bool
|
Whether to check for IP addresses in the chat prompt. |
True
|
check_password
|
bool
|
Whether to check for passwords in the chat prompt. |
True
|
check_address
|
bool
|
Whether to check for addresses in the chat prompt. |
True
|
check_name
|
bool
|
Whether to check for names in the chat prompt. |
True
|
check_dob
|
bool
|
Whether to check for dates of birth in the chat prompt. |
True
|
custom_pii_patterns
|
List[str]
|
Custom patterns to use for the PII checks. These will be read as regular expressions. |
[]
|
Source code in python/opsml/potato_head/_potato_head.pyi
Prompt
¶
Source code in python/opsml/potato_head/_potato_head.pyi
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
|
model
property
¶
The model to use for the prompt.
model_identifier
property
¶
Concatenation of provider and model, used for identifying the model in the prompt. This is commonly used with pydantic_ai to identify the model to use for the agent.
model_settings
property
¶
The model settings to use for the prompt.
provider
property
¶
The provider to use for the prompt.
sanitizer
property
¶
The prompt sanitizer to use for the prompt.
system_message
property
¶
The system message to use in the prompt.
user_message
property
¶
The user message to use in the prompt.
__init__(user_message, model=None, provider=None, system_message=None, sanitization_config=None, model_settings=None)
¶
Prompt for interacting with an LLM API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_message
|
str | Sequence[str | ImageUrl | AudioUrl | BinaryContent | DocumentUrl] | Message | List[Message]
|
The prompt to use. |
required |
model
|
str | None
|
The model to use for the prompt. Required if model_settings is not provided. |
None
|
provider
|
str | None
|
The provider to use for the prompt. Required if model_settings is not provided. |
None
|
system_message
|
Optional[str | List[str]]
|
The system prompt to use in the prompt. |
None
|
sanitization_config
|
None
|
The santization configuration to use for the prompt. Defaults to None which means no sanitization will be done |
None
|
model_settings
|
None
|
The model settings to use for the prompt. Defaults to None which means no model settings will be used |
None
|
Source code in python/opsml/potato_head/_potato_head.pyi
from_path(path)
staticmethod
¶
Load a prompt from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path to the prompt file. |
required |
Returns:
Name | Type | Description |
---|---|---|
Prompt |
Prompt
|
The loaded prompt. |
model_dump_json()
¶
model_validate_json(json_string)
staticmethod
¶
Validate the model JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_string
|
str
|
The JSON string to validate. |
required |
Returns: Prompt: The prompt object.
save_prompt(path=None)
¶
Save the prompt to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Path]
|
The path to save the prompt to. If None, the prompt will be saved to the current working directory. |
None
|
Source code in python/opsml/potato_head/_potato_head.pyi
PromptSanitizer
¶
Source code in python/opsml/potato_head/_potato_head.pyi
__init__(config)
¶
Create a PromptSanitizer object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
SanitizationConfig
|
The sanitization configuration to use. |
required |
sanitize(text)
¶
Sanitize the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text to sanitize. |
required |
Returns:
Name | Type | Description |
---|---|---|
SanitizedResult |
SanitizedResult
|
The sanitized result. |
RiskLevel
¶
Bases: IntEnum
Risk level of a potential prompt injection attempt
Source code in python/opsml/potato_head/_potato_head.pyi
SanitizationConfig
¶
Source code in python/opsml/potato_head/_potato_head.pyi
check_control_chars
property
¶
Whether to check for control characters in the chat prompt.
check_delimiters
property
¶
Whether to check for delimiters in the chat prompt.
check_keywords
property
¶
Whether to check for keywords in the chat prompt.
custom_patterns
property
¶
Custom patterns to use for the sanitization.
error_on_high_risk
property
writable
¶
Whether to raise an error on high risk.
risk_threshold
property
¶
The risk threshold to use for the sanitization.
sanitize
property
¶
Whether to sanitize the chat prompt or just assess risk.
__init__(risk_threshold=RiskLevel.High, sanitize=True, check_delimiters=True, check_keywords=True, check_control_chars=True, check_pii=True, custom_patterns=[], error_on_high_risk=True, pii_config=None)
¶
SanitizationConfig for configuring the sanitization of a chat prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
risk_threshold
|
RiskLevel
|
The risk threshold to use for the sanitization. |
High
|
sanitize
|
bool
|
Whether to sanitize the chat prompt or just assess risk. Both will return a sanitization result. Sanitize will return the input text with identified risks masked. |
True
|
check_delimiters
|
bool
|
Whether to check for delimiters in the chat prompt. |
True
|
check_keywords
|
bool
|
Whether to check for keywords in the chat prompt. |
True
|
check_control_chars
|
bool
|
Whether to check for control characters in the chat prompt. |
True
|
check_pii
|
bool
|
Whether to check for PII in the chat prompt |
True
|
custom_patterns
|
List[str]
|
Custom patterns to use for the sanitization. These will be read as regular expressions. |
[]
|
error_on_high_risk
|
bool
|
Whether to raise an error on high risk. |
True
|
pii_config
|
Optional[PIIConfig]
|
The PII configuration to use for the sanitization. |
None
|
Source code in python/opsml/potato_head/_potato_head.pyi
permissive()
staticmethod
¶
A permissive sanitization (sanitize=True) configuration with keyword and control_chars enabled and a Critical risk threshold set
standard()
staticmethod
¶
A standard sanitization (sanitize=True) configuration with all checks enabled and a risk_threshold of High.
strict()
staticmethod
¶
A strict sanitization (sanitize=True) configuration with all checks enabled and a risk_threshold of Low.
SanitizedResult
¶
Class to represent the result of a sanitization attempt
Source code in python/opsml/potato_head/_potato_head.pyi
Task
¶
Source code in python/opsml/potato_head/_potato_head.pyi
dependencies
property
¶
The dependencies of the task.
id
property
¶
The ID of the task.
prompt
property
¶
The prompt to use for the task.
status
property
¶
The status of the task.
__init__(agent_id, prompt, dependencies=[], id=None)
¶
Create a Task object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
str
|
The ID of the agent that will execute the task. |
required |
prompt
|
Prompt
|
The prompt to use for the task. |
required |
dependencies
|
List[str]
|
The dependencies of the task. |
[]
|
id
|
Optional[str]
|
The ID of the task. If None, a random uuid7 will be generated. |
None
|
Source code in python/opsml/potato_head/_potato_head.pyi
TaskList
¶
Source code in python/opsml/potato_head/_potato_head.pyi
Workflow
¶
Source code in python/opsml/potato_head/_potato_head.pyi
agents
property
¶
The agents in the workflow.
id
property
¶
The ID of the workflow. This is a random uuid7 that is generated when the workflow is created.
name
property
¶
The name of the workflow.
tasks
property
¶
The tasks in the workflow.
__init__(name)
¶
Create a Workflow object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the workflow. |
required |
add_agent(agent)
¶
Add an agent to the workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Agent
|
The agent to add to the workflow. |
required |
add_task(task)
¶
Add a task to the workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Task
|
The task to add to the workflow. |
required |
execution_plan()
¶
Get the execution plan for the workflow.
Returns:
Type | Description |
---|---|
Dict[str, List[str]]
|
Dict[str, List[str]]: A dictionary where the keys are task IDs and the values are lists of task IDs that the task depends on. |
Source code in python/opsml/potato_head/_potato_head.pyi
is_complete()
¶
Check if the workflow is complete.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the workflow is complete, False otherwise. |
pending_count()
¶
Get the number of pending tasks in the workflow.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of pending tasks in the workflow. |