mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 05:24:18 +02:00
Fix prompt return type documentation (#2741)
This commit is contained in:
parent
1ed1032ca5
commit
70fac26f9f
2 changed files with 13 additions and 12 deletions
|
|
@ -38,11 +38,14 @@ def ask_about_topic(topic: str) -> str:
|
|||
"""Generates a user message asking for an explanation of a topic."""
|
||||
return f"Can you please explain the concept of '{topic}'?"
|
||||
|
||||
# Prompt returning a specific message type
|
||||
# Prompt returning multiple messages
|
||||
@mcp.prompt
|
||||
def generate_code_request(language: str, task_description: str) -> Message:
|
||||
"""Generates a user message requesting code generation."""
|
||||
return Message(f"Write a {language} function that performs the following task: {task_description}")
|
||||
def generate_code_request(language: str, task_description: str) -> list[Message]:
|
||||
"""Generates a conversation for code generation."""
|
||||
return [
|
||||
Message(f"Write a {language} function that performs the following task: {task_description}"),
|
||||
Message("I'll help you write that function.", role="assistant"),
|
||||
]
|
||||
```
|
||||
|
||||
**Key Concepts:**
|
||||
|
|
|
|||
|
|
@ -242,10 +242,9 @@ class Prompt(FastMCPComponent):
|
|||
"""Create a Prompt from a function.
|
||||
|
||||
The function can return:
|
||||
- A string (converted to a message)
|
||||
- A Message object
|
||||
- A dict (converted to a message)
|
||||
- A sequence of any of the above
|
||||
- str: wrapped as single user Message
|
||||
- list[Message | str]: converted to list[Message]
|
||||
- PromptResult: used directly
|
||||
"""
|
||||
return FunctionPrompt.from_function(
|
||||
fn=fn,
|
||||
|
|
@ -385,10 +384,9 @@ class FunctionPrompt(Prompt):
|
|||
"""Create a Prompt from a function.
|
||||
|
||||
The function can return:
|
||||
- A string (converted to a message)
|
||||
- A Message object
|
||||
- A dict (converted to a message)
|
||||
- A sequence of any of the above
|
||||
- str: wrapped as single user Message
|
||||
- list[Message | str]: converted to list[Message]
|
||||
- PromptResult: used directly
|
||||
"""
|
||||
|
||||
func_name = name or getattr(fn, "__name__", None) or fn.__class__.__name__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue