diff --git a/docs/prompting/prompt_function.md b/docs/prompting/prompt_function.md index a8d0617bc..43771747d 100644 --- a/docs/prompting/prompt_function.md +++ b/docs/prompting/prompt_function.md @@ -21,12 +21,12 @@ This is the easiest way to use Azure / OpenAI's function calling API. def list_fruits(n: int, color: str = 'red') -> list[str]: '''Generates a list of {{n}} {{color}} fruits''' - list_fruits(3, color = 'blue').serialize() + list_fruits(3, color = 'blue') ``` This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -84,12 +84,12 @@ This is the easiest way to use Azure / OpenAI's function calling API. def list_fruits(n: int, color: str = 'red') -> list[Fruit]: '''Generates a list of {{n}} {{color}} fruits''' - list_fruits(3, color = 'blue').serialize() + list_fruits(3, color = 'blue') ``` This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -168,12 +168,12 @@ This is the easiest way to use Azure / OpenAI's function calling API. def list_fruits(n: int, color: str = 'red') -> list[Fruit]: '''Generates a list of {{n}} {{color}} fruits''' - list_fruits(3, color = 'blue').serialize() + list_fruits(3, color = 'blue') ``` This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -246,12 +246,12 @@ This is the easiest way to use Azure / OpenAI's function calling API. def list_fruits(n: int, color: str = 'red') -> list[Fruit]: '''Generates a list of {{n}} {{color}} {{'{{ response_model.__name__.lower() }}'}}''' - list_fruits(3, color = 'blue').serialize() + list_fruits(3, color = 'blue') ``` This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -324,7 +324,7 @@ This is the easiest way to use Azure / OpenAI's function calling API. This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -385,7 +385,7 @@ This is the easiest way to use Azure / OpenAI's function calling API. This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```list_fruits(3, color = 'blue').serialize()```" + ??? success "Click to see results: ```list_fruits(3, color = 'blue')```" ```python { "messages": [ @@ -456,7 +456,7 @@ This is the easiest way to use Azure / OpenAI's function calling API. This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "Click to see results: ```classify_fruits('tomato').serialize()```" + ??? success "Click to see results: ```classify_fruits('tomato')```" ```python { "messages": [ @@ -525,7 +525,7 @@ This is the easiest way to use Azure / OpenAI's function calling API. This function can now be run and serialized to an Azure / OpenAI Function Calling payload. - ??? success "```extract_fruits('There are red apples and yellow bananas.').serialize()```" + ??? success "```extract_fruits('There are red apples and yellow bananas.')```" ```python { "messages": [ diff --git a/src/marvin/components/ai_classifier.py b/src/marvin/components/ai_classifier.py index 79d10112c..98e0a69d2 100644 --- a/src/marvin/components/ai_classifier.py +++ b/src/marvin/components/ai_classifier.py @@ -30,6 +30,7 @@ def ai_classifier_prompt( response_model_name="Index", response_model_description="The index of the most likely class.", response_model_field_name="index", + serialize_on_call=False, **kwargs, ) @@ -151,7 +152,7 @@ def get_prompt( ctx = ctx or cls.__metadata__.ctx or {} instructions = instructions or cls.__metadata__.instructions ctx["instructions"] = instructions or ctx.get("instructions", None) - return ai_classifier_prompt(cls, ctx=ctx, **kwargs) # type: ignore + return ai_classifier_prompt(cls, ctx=ctx, **kwargs) # type: ignore # noqa @classmethod def as_prompt( diff --git a/src/marvin/components/ai_function.py b/src/marvin/components/ai_function.py index 65e602c2c..81ec4cc7c 100644 --- a/src/marvin/components/ai_function.py +++ b/src/marvin/components/ai_function.py @@ -28,6 +28,7 @@ def ai_fn_prompt( @prompt_fn( ctx={"ctx": ctx or {}, "func": func, "inspect": inspect}, response_model=return_annotation, + serialize_on_call=False, **kwargs, ) def prompt_wrapper(*args: P.args, **kwargs: P.kwargs) -> None: # type: ignore # noqa diff --git a/src/marvin/components/ai_model.py b/src/marvin/components/ai_model.py index d95386ee4..5ad28599e 100644 --- a/src/marvin/components/ai_model.py +++ b/src/marvin/components/ai_model.py @@ -33,6 +33,7 @@ def ai_model_prompt( response_model=cls, response_model_name="FormatResponse", response_model_description=description, + serialize_on_call=False, ) def prompt_wrapper(text: str) -> None: # type: ignore # noqa """ diff --git a/src/marvin/prompts/base.py b/src/marvin/prompts/base.py index 7165a2848..183661c8c 100644 --- a/src/marvin/prompts/base.py +++ b/src/marvin/prompts/base.py @@ -263,6 +263,7 @@ def as_decorator( response_model_name: Optional[str] = None, response_model_description: Optional[str] = None, response_model_field_name: Optional[str] = None, + serialize_on_call: bool = True, ) -> Union[ Callable[[Callable[P, None]], Callable[P, None]], Callable[[Callable[P, None]], Callable[P, Self]], @@ -289,6 +290,8 @@ def wrapper(func: Callable[P, Any], *args: P.args, **kwargs: P.kwargs) -> Self: response_model_field_name=response_model_field_name, ) response.__doc__ = func.__doc__ + if serialize_on_call: + return response.serialize() return response if func is not None: