Skip to content

Commit

Permalink
pass serialize to right spot
Browse files Browse the repository at this point in the history
  • Loading branch information
aaazzam committed Sep 22, 2023
1 parent 9d677a3 commit 38a3801
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
24 changes: 12 additions & 12 deletions docs/prompting/prompt_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down
3 changes: 2 additions & 1 deletion src/marvin/components/ai_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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, serialize_on_call=False, **kwargs) # type: ignore # noqa
return ai_classifier_prompt(cls, ctx=ctx, **kwargs) # type: ignore # noqa

@classmethod
def as_prompt(
Expand Down
2 changes: 1 addition & 1 deletion src/marvin/components/ai_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +82,6 @@ def get_prompt(
response_model_name=self.response_model_name,
response_model_description=self.response_model_description,
response_model_field_name=self.response_model_field_name,
serialize_on_call=False,
)

def as_prompt(
Expand Down
2 changes: 1 addition & 1 deletion src/marvin/components/ai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -114,7 +115,6 @@ def get_prompt(
response_model_name=response_model_name,
response_model_description=response_model_description,
response_model_field_name=response_model_field_name,
serialize_on_call=False,
)

@classmethod
Expand Down

0 comments on commit 38a3801

Please sign in to comment.