-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include a basic exercise that uses the OpenAI API with the test model
- Loading branch information
Showing
1 changed file
with
169 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from chatlab import Chat" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from typing import Optional\n", | ||
"from pydantic import BaseModel, Field\n", | ||
"\n", | ||
"# Define a function to use in testing\n", | ||
"def simple_func(x: int, y: str, z: bool = False):\n", | ||
" \"\"\"A simple test function\"\"\"\n", | ||
" return f\"{x}, {y}, {z}\"\n", | ||
"\n", | ||
"\n", | ||
"class SimpleModel(BaseModel):\n", | ||
" x: int\n", | ||
" y: str\n", | ||
" z: bool = Field(default=False, description=\"A simple boolean field\")\n", | ||
"\n", | ||
"\n", | ||
"class SimpleClass:\n", | ||
" def simple_method(self, x: int, y: str, z: bool = False):\n", | ||
" \"\"\"A simple test method\"\"\"\n", | ||
" return f\"{x}, {y}, {z}\"\n", | ||
"\n", | ||
"\n", | ||
"def simple_func_with_model_arg(\n", | ||
" x: int,\n", | ||
" y: str,\n", | ||
" z: bool = False,\n", | ||
" model: Optional[SimpleModel] = None,\n", | ||
") -> str:\n", | ||
" \"\"\"A simple test function with a model argument\"\"\"\n", | ||
" return f\"{x}, {y}, {z}, {model}\"\n", | ||
"\n", | ||
"\n", | ||
"class NestedModel(BaseModel):\n", | ||
" foo: int\n", | ||
" bar: str\n", | ||
" baz: bool = True\n", | ||
" simple_model: SimpleModel\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def simple_func_with_model_args(\n", | ||
" x: int,\n", | ||
" y: str,\n", | ||
" z: bool = False,\n", | ||
" model: Optional[SimpleModel] = None,\n", | ||
" nested_model: Optional[NestedModel] = None,\n", | ||
") -> str:\n", | ||
" \"\"\"A simple test function with model arguments\"\"\"\n", | ||
" return f\"{x}, {y}, {z}, {model}, {nested_model}\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div><style>.chatlab-chat-details summary > * { display: inline; color: #27374D; }</style><details style=\"background: #DDE6ED; border-radius: 5px; padding: .5rem 1rem\" className=\"chatlab-chat-details\"><summary style=\"color: #27374D; cursor: pointer\"><span style=\"color: #9DB2BF; padding-left: 5px; padding-right: 5px\">𝑓</span><span style=\"color: #27374D; padding-left: 5px; padding-right: 5px\">Ran</span><span style=\"font-family: monospace; unicode-bidi: embed; white-space: pre\">simple_func_with_model_args</span><span style=\"font-family: monospace; unicode-bidi: embed; white-space: pre\"></span></summary><div style=\"margin-left: 10px; margin-top: 10px\"><div><div style=\"color: #27374D; font-weight: 500; margin-bottom: 5px\">Input:</div><div style=\"background: #F7F9FA; color: #27374D; font-family: monospace; margin-bottom: 10px; overflow-x: auto; padding: 10px; unicode-bidi: embed; white-space: pre\">{\n", | ||
" "x": 10,\n", | ||
" "y": "example",\n", | ||
" "z": true,\n", | ||
" "model": {\n", | ||
" "x": 5,\n", | ||
" "y": "model",\n", | ||
" "z": false\n", | ||
" },\n", | ||
" "nested_model": {\n", | ||
" "foo": 1,\n", | ||
" "bar": "nested",\n", | ||
" "baz": true,\n", | ||
" "simple_model": {\n", | ||
" "x": 2,\n", | ||
" "y": "nested_model",\n", | ||
" "z": true\n", | ||
" }\n", | ||
" }\n", | ||
"}</div></div><div><div style=\"color: #27374D; font-weight: 500; margin-bottom: 5px\">Output:</div><div style=\"background: #F7F9FA; color: #27374D; font-family: monospace; margin-bottom: 10px; overflow-x: auto; padding: 10px; unicode-bidi: embed; white-space: pre\">10, example, True, {'x': 5, 'y': 'model', 'z': False}, {'foo': 1, 'bar': 'nested', 'baz': True, 'simple_model': {'x': 2, 'y': 'nested_model', 'z': True}}</div></div></div></details></div>" | ||
], | ||
"text/plain": [ | ||
"<chatlab.display.ChatFunctionCall at 0x10ff36250>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/markdown": [ | ||
"The simple_func_with_model_args function was called with the following data:\n", | ||
"\n", | ||
"- x: 10\n", | ||
"- y: \"example\"\n", | ||
"- z: true\n", | ||
"- model: {x: 5, y: \"model\", z: false}\n", | ||
"- nested_model: {foo: 1, bar: \"nested\", baz: true, simple_model: {x: 2, y: \"nested_model\", z: true}}" | ||
], | ||
"text/plain": [ | ||
"The simple_func_with_model_args function was called with the following data:\n", | ||
"\n", | ||
"- x: 10\n", | ||
"- y: \"example\"\n", | ||
"- z: true\n", | ||
"- model: {x: 5, y: \"model\", z: false}\n", | ||
"- nested_model: {foo: 1, bar: \"nested\", baz: true, simple_model: {x: 2, y: \"nested_model\", z: true}}" | ||
] | ||
}, | ||
"metadata": { | ||
"text/markdown": { | ||
"chatlab": { | ||
"default": true | ||
} | ||
} | ||
}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"chat = Chat()\n", | ||
"chat.register(simple_func_with_model_args)\n", | ||
"\n", | ||
"await chat(\"Call my simple func with some example data\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "chatlab-3kMKfU-i-py3.11", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |