Created
February 18, 2024 20:18
-
-
Save zzstoatzz/2058b568cd9b3450c0e1e54e5e47d85d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: from pydantic import BaseModel | |
In [2]: import marvin | |
In [3]: class Book(BaseModel): | |
...: title: str | |
...: author: str | |
...: | |
In [4]: @marvin.fn | |
...: def recommend_a_book(genre: str) -> Book: | |
...: """You are the worlds greatest librarian | |
...: | |
...: the user will ask you for a recommendation in a given genre | |
...: """ | |
...: | |
In [5]: recommend_a_book("fantasy") | |
Out[5]: Book(title='The Name of the Wind', author='Patrick Rothfuss') | |
```python | |
# debug logs | |
[02/18/24 14:16:56] DEBUG marvin.ai.text: Request: { logging.py:89 | |
"tools": [ | |
{ | |
"type": "function", | |
"function": { | |
"name": "FormatResponse", | |
"description": "Format the response with valid JSON.", | |
"parameters": { | |
"$defs": { | |
"Book": { | |
"properties": { | |
"title": { | |
"title": "Title", | |
"type": "string" | |
}, | |
"author": { | |
"title": "Author", | |
"type": "string" | |
} | |
}, | |
"required": [ | |
"title", | |
"author" | |
], | |
"title": "Book", | |
"type": "object" | |
} | |
}, | |
"description": "Format the response with valid JSON.", | |
"properties": { | |
"value": { | |
"allOf": [ | |
{ | |
"$ref": "#/$defs/Book" | |
} | |
], | |
"description": "The formatted response" | |
} | |
}, | |
"required": [ | |
"value" | |
], | |
"type": "object" | |
} | |
} | |
} | |
], | |
"tool_choice": { | |
"type": "function", | |
"function": { | |
"name": "FormatResponse" | |
} | |
}, | |
"logit_bias": null, | |
"max_tokens": null, | |
"response_format": null, | |
"messages": [ | |
{ | |
"content": "Your job is to generate likely outputs for a Python function with the\nfollowing definition:\n\ndef | |
recommend_a_book(genre: str) -> __main__.Book:\n \"\"\"\n You are the worlds greatest librarian\n\n the user will ask you for | |
a recommendation in a given genre\n \"\"\"\n\nThe user will provide function inputs (if any) and you must respond with\nthe most | |
likely result.", | |
"role": "system" | |
}, | |
{ | |
"content": "## Function inputs\n\nThe function was called with the following inputs:\n- genre: fantasy\n\n\nWhat is the | |
function's output?", | |
"role": "user" | |
}, | |
{ | |
"content": "The output is", | |
"role": "assistant" | |
} | |
], | |
"model": "gpt-4-1106-preview", | |
"frequency_penalty": 0.0, | |
"n": 1, | |
"presence_penalty": 0.0, | |
"seed": null, | |
"stop": null, | |
"stream": false, | |
"temperature": 0.0, | |
"top_p": 1.0, | |
"user": null | |
} | |
[02/18/24 14:16:58] DEBUG marvin.ai.text: Response: { logging.py:89 | |
"id": "chatcmpl-8thsncPaummbMvXkvclbLB2YOO9Pr", | |
"choices": [ | |
{ | |
"finish_reason": "stop", | |
"index": 0, | |
"logprobs": null, | |
"message": { | |
"content": null, | |
"role": "assistant", | |
"function_call": null, | |
"tool_calls": [ | |
{ | |
"id": "call_oevtUNNuce41mv4GJHWlTce2", | |
"function": { | |
"arguments": "{\"value\":{\"title\":\"The Name of the Wind\",\"author\":\"Patrick Rothfuss\"}}", | |
"name": "FormatResponse" | |
}, | |
"type": "function" | |
} | |
] | |
} | |
} | |
], | |
"created": 1708287417, | |
"model": "gpt-4-1106-preview", | |
"object": "chat.completion", | |
"system_fingerprint": "fp_225a6f324c", | |
"usage": { | |
"completion_tokens": 18, | |
"prompt_tokens": 198, | |
"total_tokens": 216 | |
} | |
} | |
DEBUG marvin.Tools: FormatResponse: called with arguments: {'value': {'title': 'The Name of the Wind', 'author': 'Patrick Rothfuss'}} logging.py:89 | |
DEBUG marvin.Tools: FormatResponse: returned: title='The Name of the Wind' author='Patrick Rothfuss' | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment